diff --git a/src/mcp-server-http.ts b/src/mcp-server-http.ts index 3674d3e..63729e1 100644 --- a/src/mcp-server-http.ts +++ b/src/mcp-server-http.ts @@ -252,15 +252,8 @@ export async function main() { // Health check endpoint app.get("/health", (c) => c.json({ status: "ok" })); - // MCP Inspector at root path - auto-connects to /mcp - // Use environment variable for public URL, fallback to localhost for dev - const mcpPublicUrl = process.env.MCP_PUBLIC_URL || `http://localhost:${PORT}`; - mountInspector(app, { - autoConnectUrl: `${mcpPublicUrl}/mcp`, - devMode: process.env.NODE_ENV !== "production", - }); - // MCP endpoint - handles both GET and POST + // Must be defined BEFORE inspector (which mounts at /) for proper route matching app.all("/mcp", async (c) => { // Get parsed body from Hono (automatic JSON parsing) let parsedBody: unknown; @@ -289,6 +282,14 @@ export async function main() { return response; }); + // MCP Inspector at root path - auto-connects to /mcp + // Mounted AFTER /mcp so specific routes take precedence + const mcpPublicUrl = process.env.MCP_PUBLIC_URL || `http://localhost:${PORT}`; + mountInspector(app, { + autoConnectUrl: `${mcpPublicUrl}/mcp`, + devMode: process.env.NODE_ENV !== "production", + }); + // Start the server console.log(`Ask262 MCP HTTP Server running on http://0.0.0.0:${PORT}`); console.log(`MCP endpoint: POST http://0.0.0.0:${PORT}/mcp`);