mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
refactor: move MCP endpoint above inspector for proper route priority
- Define /mcp endpoint before mounting inspector at / - Ensures specific routes are matched before catch-all - Prevents inspector from intercepting MCP requests
This commit is contained in:
@@ -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`);
|
||||
|
||||
Reference in New Issue
Block a user