mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-19 00:31:06 +00:00
refactor(mcp): change HEAD endpoint to middleware for improved route handling
This commit is contained in:
@@ -252,9 +252,9 @@ export async function main() {
|
|||||||
// Health check endpoint
|
// Health check endpoint
|
||||||
app.get("/health", (c) => c.json({ status: "ok" }));
|
app.get("/health", (c) => c.json({ status: "ok" }));
|
||||||
|
|
||||||
// MCP HEAD endpoint - health check / availability probe
|
// MCP HEAD handler - runs before the main handler
|
||||||
// Must be defined BEFORE app.all for proper route matching (specific routes first)
|
app.use("/mcp", async (c, next) => {
|
||||||
app.on("HEAD", "/mcp", (_c) => {
|
if (c.req.method === "HEAD") {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -262,11 +262,13 @@ export async function main() {
|
|||||||
"mcp-protocol-version": "2025-03-26",
|
"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
|
// 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)
|
// Get parsed body from Hono (automatic JSON parsing)
|
||||||
let parsedBody: unknown;
|
let parsedBody: unknown;
|
||||||
if (c.req.method === "POST") {
|
if (c.req.method === "POST") {
|
||||||
|
|||||||
Reference in New Issue
Block a user