{"version":3,"sources":["../src/server/handlers/mcp.ts"],"names":["__export","createRoute","listMcpServersQuerySchema","listMcpServersResponseSchema","HTTPException","mcpServerDetailPathParams","getMcpServerDetailQuerySchema","serverDetailSchema","mcpServerIdPathParams","listMcpServerToolsResponseSchema","mcpServerToolPathParams","mcpToolInfoSchema","executeToolBodySchema","executeToolResponseSchema","mcpServerResourcePathParams","listResourcesResponseSchema","readResourceBodySchema","readResourceResponseSchema"],"mappings":";;;;;;;;AAAA,IAAA,WAAA,GAAA;AAAAA,0BAAA,CAAA,WAAA,EAAA;AAAA,EAAA,6BAAA,EAAA,MAAA,6BAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,gCAAA,EAAA,MAAA,gCAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,+BAAA,EAAA,MAAA,+BAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,wBAAA,EAAA,MAAA,wBAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,8BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AA0BO,IAAM,yBAAyBC,6BAAA,CAAY;AAAA,EAChD,MAAA,EAAQ,KAAA;AAAA,EACR,IAAA,EAAM,iBAAA;AAAA,EACN,YAAA,EAAc,MAAA;AAAA,EACd,gBAAA,EAAkBC,2CAAA;AAAA,EAClB,cAAA,EAAgBC,8CAAA;AAAA,EAChB,OAAA,EAAS,kBAAA;AAAA,EACT,WAAA,EAAa,kEAAA;AAAA,EACb,IAAA,EAAM,CAAC,KAAK,CAAA;AAAA,EACZ,YAAA,EAAc,IAAA;AAAA,EACd,SAAS,OAAO;AAAA,IACd,MAAA;AAAA,IACA,WAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF,KAA4F;AAC1F,IAAA,IAAI,CAAC,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core/mcp';\nimport { HTTPException } from '../http-exception';\nimport {\n mcpServerDetailPathParams,\n mcpServerToolPathParams,\n executeToolBodySchema,\n listMcpServersQuerySchema,\n getMcpServerDetailQuerySchema,\n listMcpServersResponseSchema,\n serverDetailSchema,\n mcpServerIdPathParams,\n listMcpServerToolsResponseSchema,\n mcpToolInfoSchema,\n executeToolResponseSchema,\n mcpServerResourcePathParams,\n readResourceBodySchema,\n readResourceResponseSchema,\n listResourcesResponseSchema,\n} from '../schemas/mcp';\nimport type { ServerContext } from '../server-adapter';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\n// ============================================================================\n// Route Definitions (createRoute pattern for server adapters)\n// ============================================================================\n\nexport const LIST_MCP_SERVERS_ROUTE = createRoute({\n method: 'GET',\n path: '/mcp/v0/servers',\n responseType: 'json',\n queryParamSchema: listMcpServersQuerySchema,\n responseSchema: listMcpServersResponseSchema,\n summary: 'List MCP servers',\n description: 'Returns a list of registered MCP servers with pagination support',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({\n mastra,\n routePrefix,\n page,\n perPage,\n limit,\n offset,\n }: ServerContext & { page?: number; perPage?: number; limit?: number; offset?: number }) => {\n if (!mastra || typeof mastra.listMCPServers !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or listMCPServers method not available' });\n }\n\n const servers = mastra.listMCPServers();\n\n if (!servers) {\n return { servers: [], total_count: 0, next: null };\n }\n\n const serverList = Object.values(servers) as MastraMCPServerImplementation[];\n const totalCount = serverList.length;\n\n // Support both page/perPage and limit/offset for backwards compatibility\n // Detect which format user is using - prefer page/perPage if both provided\n const useLegacyFormat =\n (limit !== undefined || offset !== undefined) && page === undefined && perPage === undefined;\n\n // If perPage provided, use it; otherwise fall back to limit\n const finalPerPage = perPage ?? limit;\n // If page provided, use it; otherwise convert from offset\n let finalPage = page;\n if (finalPage === undefined && offset !== undefined && finalPerPage !== undefined && finalPerPage > 0) {\n finalPage = Math.floor(offset / finalPerPage);\n }\n\n // Calculate offset from page/perPage\n const actualOffset = finalPage !== undefined && finalPerPage !== undefined ? finalPage * finalPerPage : 0;\n\n // Apply pagination\n let paginatedServers = serverList;\n let nextUrl: string | null = null;\n\n if (finalPerPage !== undefined) {\n paginatedServers = serverList.slice(actualOffset, actualOffset + finalPerPage);\n\n // Calculate next URL if there are more results\n if (actualOffset + finalPerPage < totalCount) {\n const nextPage = (finalPage ?? 0) + 1;\n // Return next URL in same format as request (legacy limit/offset or page/perPage)\n const prefix = routePrefix ?? '';\n if (useLegacyFormat) {\n const nextOffset = actualOffset + finalPerPage;\n nextUrl = `${prefix}/mcp/v0/servers?limit=${finalPerPage}&offset=${nextOffset}`;\n } else {\n nextUrl = `${prefix}/mcp/v0/servers?perPage=${finalPerPage}&page=${nextPage}`;\n }\n }\n }\n\n // Get server info for each server\n const serverInfoList: ServerInfo[] = paginatedServers.map(server => server.getServerInfo());\n\n return {\n servers: serverInfoList,\n total_count: totalCount,\n next: nextUrl,\n };\n },\n});\n\nexport const GET_MCP_SERVER_DETAIL_ROUTE = createRoute({\n method: 'GET',\n path: '/mcp/v0/servers/:id',\n responseType: 'json',\n pathParamSchema: mcpServerDetailPathParams,\n queryParamSchema: getMcpServerDetailQuerySchema,\n responseSchema: serverDetailSchema,\n summary: 'Get MCP server details',\n description: 'Returns detailed information about a specific MCP server',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, id, version }: ServerContext & { id: string; version?: string }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(id);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${id}' not found` });\n }\n\n const serverDetail = server.getServerDetail();\n\n // If a specific version was requested, check if it matches\n if (version && serverDetail.version_detail.version !== version) {\n throw new HTTPException(404, {\n message: `MCP server with ID '${id}' found, but not version '${version}'. Available version: ${serverDetail.version_detail.version}`,\n });\n }\n\n return serverDetail;\n },\n});\n\nexport const LIST_MCP_SERVER_TOOLS_ROUTE = createRoute({\n method: 'GET',\n path: '/mcp/:serverId/tools',\n responseType: 'json',\n pathParamSchema: mcpServerIdPathParams,\n responseSchema: listMcpServerToolsResponseSchema,\n summary: 'List MCP server tools',\n description: 'Returns a list of tools available on the specified MCP server',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId, requestContext }: ServerContext & { serverId: string }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${serverId}' not found` });\n }\n\n if (typeof server.getToolListInfo !== 'function') {\n throw new HTTPException(501, { message: `Server '${serverId}' cannot list tools in this way.` });\n }\n\n return await server.getToolListInfo(requestContext);\n },\n});\n\nexport const GET_MCP_SERVER_TOOL_DETAIL_ROUTE = createRoute({\n method: 'GET',\n path: '/mcp/:serverId/tools/:toolId',\n responseType: 'json',\n pathParamSchema: mcpServerToolPathParams,\n responseSchema: mcpToolInfoSchema,\n summary: 'Get MCP server tool details',\n description: 'Returns detailed information about a specific tool on the MCP server',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId, toolId }: ServerContext & { serverId: string; toolId: string }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${serverId}' not found` });\n }\n\n if (typeof server.getToolInfo !== 'function') {\n throw new HTTPException(501, { message: `Server '${serverId}' cannot provide tool details in this way.` });\n }\n\n const toolInfo = await server.getToolInfo(toolId);\n if (!toolInfo) {\n throw new HTTPException(404, { message: `Tool with ID '${toolId}' not found on MCP server '${serverId}'` });\n }\n\n return toolInfo;\n },\n});\n\nexport const EXECUTE_MCP_SERVER_TOOL_ROUTE = createRoute({\n method: 'POST',\n path: '/mcp/:serverId/tools/:toolId/execute',\n responseType: 'json',\n pathParamSchema: mcpServerToolPathParams,\n bodySchema: executeToolBodySchema,\n responseSchema: executeToolResponseSchema,\n summary: 'Execute MCP server tool',\n description: 'Executes a tool on the specified MCP server with the provided arguments',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({\n mastra,\n serverId,\n toolId,\n data,\n requestContext,\n }: ServerContext & { serverId: string; toolId: string; data?: unknown }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${serverId}' not found` });\n }\n\n if (typeof server.executeTool !== 'function') {\n throw new HTTPException(501, { message: `Server '${serverId}' cannot execute tools in this way.` });\n }\n\n const result = await server.executeTool(toolId, data, { requestContext });\n return { result };\n },\n});\n\n// ============================================================================\n// MCP Resource Routes\n// ============================================================================\n\nexport const LIST_MCP_SERVER_RESOURCES_ROUTE = createRoute({\n method: 'GET',\n path: '/mcp/:serverId/resources',\n responseType: 'json',\n pathParamSchema: mcpServerResourcePathParams,\n responseSchema: listResourcesResponseSchema,\n summary: 'List MCP server resources',\n description: 'Returns a list of resources available on the MCP server, including ui:// app resources',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId }: ServerContext & { serverId: string }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${serverId}' not found` });\n }\n\n if (typeof server.listResources !== 'function') {\n return { resources: [] };\n }\n\n return server.listResources();\n },\n});\n\nexport const READ_MCP_SERVER_RESOURCE_ROUTE = createRoute({\n method: 'POST',\n path: '/mcp/:serverId/resources/read',\n responseType: 'json',\n pathParamSchema: mcpServerResourcePathParams,\n bodySchema: readResourceBodySchema,\n responseSchema: readResourceResponseSchema,\n summary: 'Read MCP server resource content',\n description: 'Reads the content of a resource by URI, used for rendering MCP App ui:// resources',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId, uri }: ServerContext & { serverId: string; uri: string }) => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server with ID '${serverId}' not found` });\n }\n\n if (typeof server.readResource !== 'function') {\n throw new HTTPException(501, { message: `Server '${serverId}' does not support reading resources` });\n }\n\n try {\n return await server.readResource(uri);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (message.includes('not found') || message.includes('not configured')) {\n throw new HTTPException(404, { message: `Resource '${uri}' not found on server '${serverId}'` });\n }\n throw error;\n }\n },\n});\n\n// ============================================================================\n// MCP Transport Routes (Streamable HTTP and SSE)\n// ============================================================================\n\n/**\n * MCP transport options that can be passed to startHTTP() or startSSE().\n * Includes serverless mode for running in stateless environments like Cloudflare Workers or Vercel Edge.\n */\nexport interface MCPTransportOptions {\n /**\n * When true, runs in stateless mode without session management.\n * Ideal for serverless environments where you can't maintain persistent connections.\n */\n serverless?: boolean;\n /**\n * Custom session ID generator function.\n */\n sessionIdGenerator?: () => string;\n}\n\n/**\n * MCP HTTP Transport response type.\n * Adapters use this to set up the HTTP transport via MCPServer.startHTTP()\n */\nexport interface MCPHttpTransportResult {\n server: MastraMCPServerImplementation;\n httpPath: string;\n /**\n * Optional MCP transport options for this specific route.\n * These override any class-level mcpOptions configured on the adapter.\n */\n mcpOptions?: MCPTransportOptions;\n}\n\n/**\n * MCP SSE Transport response type.\n * Adapters use this to set up the SSE transport via MCPServer.startSSE() or startHonoSSE()\n *\n * Note: SSE transport is inherently stateful and doesn't support serverless mode.\n */\nexport interface MCPSseTransportResult {\n server: MastraMCPServerImplementation;\n ssePath: string;\n messagePath: string;\n}\n\nexport const MCP_HTTP_TRANSPORT_ROUTE = createRoute({\n method: 'ALL',\n path: '/mcp/:serverId/mcp',\n responseType: 'mcp-http',\n pathParamSchema: mcpServerIdPathParams,\n summary: 'MCP HTTP Transport',\n description: 'Streamable HTTP transport endpoint for MCP protocol communication',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId }: ServerContext & { serverId: string }): Promise => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server '${serverId}' not found` });\n }\n\n return {\n server,\n httpPath: `/mcp/${serverId}/mcp`,\n };\n },\n});\n\nexport const MCP_SSE_TRANSPORT_ROUTE = createRoute({\n method: 'ALL',\n path: '/mcp/:serverId/sse',\n responseType: 'mcp-sse',\n pathParamSchema: mcpServerIdPathParams,\n summary: 'MCP SSE Transport',\n description: 'SSE transport endpoint for MCP protocol communication',\n tags: ['MCP'],\n requiresAuth: true,\n handler: async ({ mastra, serverId }: ServerContext & { serverId: string }): Promise => {\n if (!mastra || typeof mastra.getMCPServerById !== 'function') {\n throw new HTTPException(500, { message: 'Mastra instance or getMCPServerById method not available' });\n }\n\n const server = mastra.getMCPServerById(serverId);\n\n if (!server) {\n throw new HTTPException(404, { message: `MCP server '${serverId}' not found` });\n }\n\n return {\n server,\n ssePath: `/mcp/${serverId}/sse`,\n messagePath: `/mcp/${serverId}/messages`,\n };\n },\n});\n\nexport const MCP_SSE_MESSAGES_ROUTE = createRoute({\n method: 'POST',\n path: '/mcp/:serverId/messages',\n responseType: 'mcp-sse',\n pathParamSchema: mcpServerIdPathParams,\n summary: 'MCP SSE Messages',\n description: 'Message endpoint for SSE transport (posts messages to active SSE streams)',\n tags: ['MCP'],\n requiresAuth: true,\n handler: MCP_SSE_TRANSPORT_ROUTE.handler,\n});\n"]}