{"version":3,"file":"routes.mjs","sources":["../../../src/services/mcp/routes.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport { McpConfiguration } from './internal/McpConfiguration';\nimport { sendJsonRpcError } from './utils/sendJsonRpcError';\n\n/**\n * Handler for unsupported HTTP methods on /mcp endpoint.\n * Returns JSON-RPC error instead of plain text so MCP clients can parse it.\n */\nconst handleMethodNotAllowed: Core.MiddlewareHandler = async (ctx) => {\n // Opt out of Koa's response phase — sendJsonRpcError writes directly to ctx.res.\n ctx.respond = false;\n // ctx.set() writes to Koa's in-memory headers which are never flushed when ctx.respond = false.\n // Use res.setHeader() so the header is included when sendJsonRpcError calls res.writeHead().\n ctx.res.setHeader('Allow', 'POST');\n sendJsonRpcError(ctx.res, 'METHOD_NOT_ALLOWED');\n};\n\nexport type McpRouteHandlers = {\n handlePost: Core.MiddlewareHandler;\n};\n\n/**\n * Creates MCP route definitions for registration with Strapi server.\n * @internal\n */\nexport const createMcpRoutes = (\n config: McpConfiguration,\n handlers: McpRouteHandlers\n): Omit[] => {\n const noAuth = { auth: false } as const;\n\n return [\n { method: 'POST', path: config.path, handler: handlers.handlePost, config: noAuth },\n { method: 'GET', path: config.path, handler: handleMethodNotAllowed, config: noAuth },\n { method: 'DELETE', path: config.path, handler: handleMethodNotAllowed, config: noAuth },\n { method: 'PUT', path: config.path, handler: handleMethodNotAllowed, config: noAuth },\n { method: 'PATCH', path: config.path, handler: handleMethodNotAllowed, config: noAuth },\n ];\n};\n"],"names":["handleMethodNotAllowed","ctx","respond","res","setHeader","sendJsonRpcError","createMcpRoutes","config","handlers","noAuth","auth","method","path","handler","handlePost"],"mappings":";;AAIA;;;IAIA,MAAMA,yBAAiD,OAAOC,GAAAA,GAAAA;;AAE5DA,IAAAA,GAAAA,CAAIC,OAAO,GAAG,KAAA;;;AAGdD,IAAAA,GAAAA,CAAIE,GAAG,CAACC,SAAS,CAAC,OAAA,EAAS,MAAA,CAAA;IAC3BC,gBAAAA,CAAiBJ,GAAAA,C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