From 2fd7dd136d974b3506fa8e1b4fcf546bef8dd359 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Wed, 17 Dec 2025 17:43:41 +0000 Subject: [PATCH] refactor: add CORS support and handle root endpoint in MCP routes --- MCP/Index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/MCP/Index.ts b/MCP/Index.ts index 57af263b52..1caf2ddad2 100755 --- a/MCP/Index.ts +++ b/MCP/Index.ts @@ -347,6 +347,21 @@ function setupMCPRoutes(): void { app.post(mcpEndpoint, ExpressJson(), mcpHandler); app.delete(mcpEndpoint, mcpHandler); + // OPTIONS handler for CORS preflight requests + app.options(mcpEndpoint, (_req: ExpressRequest, res: ExpressResponse) => { + res.status(200).end(); + }); + + // Also handle root "/" when nginx strips the /mcp/ prefix (for "/" prefix only) + if (prefix === "/") { + app.get("/", mcpHandler); + app.post("/", ExpressJson(), mcpHandler); + app.delete("/", mcpHandler); + app.options("/", (_req: ExpressRequest, res: ExpressResponse) => { + res.status(200).end(); + }); + } + // List tools endpoint (REST API) app.get( `${prefix === "/" ? "" : prefix}/tools`,