mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 21:31:46 +00:00
refactor(mcp): change HEAD endpoint to middleware for improved route handling
This commit is contained in:
+14
-12
@@ -252,21 +252,23 @@ export async function main() {
|
||||
// Health check endpoint
|
||||
app.get("/health", (c) => c.json({ status: "ok" }));
|
||||
|
||||
// MCP HEAD endpoint - health check / availability probe
|
||||
// Must be defined BEFORE app.all for proper route matching (specific routes first)
|
||||
app.on("HEAD", "/mcp", (_c) => {
|
||||
return new Response(null, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"mcp-protocol-version": "2025-03-26",
|
||||
},
|
||||
});
|
||||
// MCP HEAD handler - runs before the main handler
|
||||
app.use("/mcp", async (c, next) => {
|
||||
if (c.req.method === "HEAD") {
|
||||
return new Response(null, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"mcp-protocol-version": "2025-03-26",
|
||||
},
|
||||
});
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
// MCP endpoint - handles GET and POST
|
||||
// MCP endpoint - handles GET and POST (HEAD is handled by middleware above)
|
||||
// Must be defined BEFORE inspector (which mounts at /) for proper route matching
|
||||
app.all("/mcp", async (c) => {
|
||||
app.on(["GET", "POST"], "/mcp", async (c) => {
|
||||
// Get parsed body from Hono (automatic JSON parsing)
|
||||
let parsedBody: unknown;
|
||||
if (c.req.method === "POST") {
|
||||
|
||||
Reference in New Issue
Block a user