@mastra/mcp 0.14.2-alpha.0 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,29 +1,29 @@
1
- import $RefParser from '@apidevtools/json-schema-ref-parser';
2
1
  import { MastraBase } from '@mastra/core/base';
3
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
+ import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
4
+ import equal from 'fast-deep-equal';
5
+ import { v5 } from 'uuid';
6
+ import $RefParser from '@apidevtools/json-schema-ref-parser';
4
7
  import { createTool } from '@mastra/core/tools';
5
8
  import { makeCoreTool, isZodType } from '@mastra/core/utils';
6
9
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
7
10
  import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
8
11
  import { StdioClientTransport, getDefaultEnvironment } from '@modelcontextprotocol/sdk/client/stdio.js';
9
12
  import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
10
- import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
11
13
  import { ListToolsRequestSchema, CallToolRequestSchema, SetLevelRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListResourceTemplatesRequestSchema, SubscribeRequestSchema, UnsubscribeRequestSchema, ListPromptsRequestSchema, PromptSchema, GetPromptRequestSchema, ListResourcesResultSchema, ReadResourceResultSchema, ListResourceTemplatesResultSchema, ListPromptsResultSchema, GetPromptResultSchema, PromptListChangedNotificationSchema, ResourceUpdatedNotificationSchema, ResourceListChangedNotificationSchema, ElicitRequestSchema, CallToolResultSchema, JSONRPCMessageSchema, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
12
14
  import { asyncExitHook, gracefulExit } from 'exit-hook';
13
15
  import { z } from 'zod';
14
16
  import { convertJsonSchemaToZod } from 'zod-from-json-schema';
15
17
  import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
16
- import equal from 'fast-deep-equal';
17
- import { v5 } from 'uuid';
18
18
  import { randomUUID } from 'crypto';
19
19
  import { MCPServerBase } from '@mastra/core/mcp';
20
- import { RuntimeContext } from '@mastra/core/runtime-context';
20
+ import { RequestContext } from '@mastra/core/request-context';
21
21
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
22
22
  import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
23
23
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
24
24
  import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
25
25
 
26
- // src/client/client.ts
26
+ // src/client/configuration.ts
27
27
 
28
28
  // src/client/elicitationActions.ts
29
29
  var ElicitationClientActions = class {
@@ -447,7 +447,7 @@ var InternalMastraMCPClient = class extends MastraBase {
447
447
  timestamp: /* @__PURE__ */ new Date(),
448
448
  serverName: this.name,
449
449
  details,
450
- runtimeContext: this.currentOperationContext
450
+ requestContext: this.currentOperationContext
451
451
  });
452
452
  }
453
453
  }
@@ -777,15 +777,15 @@ var InternalMastraMCPClient = class extends MastraBase {
777
777
  description: tool.description || "",
778
778
  inputSchema: await this.convertInputSchema(tool.inputSchema),
779
779
  outputSchema: await this.convertOutputSchema(tool.outputSchema),
780
- execute: async ({ context, runtimeContext }) => {
780
+ execute: async (input, context) => {
781
781
  const previousContext = this.currentOperationContext;
782
- this.currentOperationContext = runtimeContext || null;
782
+ this.currentOperationContext = context?.requestContext || null;
783
783
  try {
784
- this.log("debug", `Executing tool: ${tool.name}`, { toolArgs: context });
784
+ this.log("debug", `Executing tool: ${tool.name}`, { toolArgs: input });
785
785
  const res = await this.client.callTool(
786
786
  {
787
787
  name: tool.name,
788
- arguments: context
788
+ arguments: input
789
789
  },
790
790
  CallToolResultSchema,
791
791
  {
@@ -797,7 +797,7 @@ var InternalMastraMCPClient = class extends MastraBase {
797
797
  } catch (e) {
798
798
  this.log("error", `Error calling tool: ${tool.name}`, {
799
799
  error: e instanceof Error ? e.stack : JSON.stringify(e, null, 2),
800
- toolArgs: context
800
+ toolArgs: input
801
801
  });
802
802
  throw e;
803
803
  } finally {
@@ -818,19 +818,8 @@ var InternalMastraMCPClient = class extends MastraBase {
818
818
  return toolsRes;
819
819
  }
820
820
  };
821
- var MastraMCPClient = class extends InternalMastraMCPClient {
822
- constructor(args) {
823
- super(args);
824
- throw new MastraError(
825
- {
826
- id: "MASTRA_MCP_CLIENT_DEPRECATED",
827
- domain: ErrorDomain.MCP,
828
- category: ErrorCategory.USER,
829
- text: "[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead."
830
- }
831
- );
832
- }
833
- };
821
+
822
+ // src/client/configuration.ts
834
823
  var mcpClientInstances = /* @__PURE__ */ new Map();
835
824
  var MCPClient = class extends MastraBase {
836
825
  serverConfigs = {};
@@ -1431,14 +1420,15 @@ To fix this you have three different options:
1431
1420
  * @example
1432
1421
  * ```typescript
1433
1422
  * const agent = new Agent({
1423
+ * id: 'multi-tool-agent',
1434
1424
  * name: 'Multi-tool Agent',
1435
1425
  * instructions: 'You have access to weather and stock tools.',
1436
1426
  * model: 'openai/gpt-4',
1437
- * tools: await mcp.getTools(), // weather_getWeather, stockPrice_getPrice
1427
+ * tools: await mcp.listTools(), // weather_getWeather, stockPrice_getPrice
1438
1428
  * });
1439
1429
  * ```
1440
1430
  */
1441
- async getTools() {
1431
+ async listTools() {
1442
1432
  this.addToInstanceCache();
1443
1433
  const connectedTools = {};
1444
1434
  try {
@@ -1462,7 +1452,7 @@ To fix this you have three different options:
1462
1452
  /**
1463
1453
  * Returns toolsets organized by server name for dynamic tool injection.
1464
1454
  *
1465
- * Unlike getTools(), this returns tools grouped by server without namespacing.
1455
+ * Unlike listTools(), this returns tools grouped by server without namespacing.
1466
1456
  * This is intended to be passed dynamically to the generate() or stream() method.
1467
1457
  *
1468
1458
  * @returns Object mapping server names to their tool collections
@@ -1471,17 +1461,18 @@ To fix this you have three different options:
1471
1461
  * @example
1472
1462
  * ```typescript
1473
1463
  * const agent = new Agent({
1464
+ * id: 'dynamic-agent',
1474
1465
  * name: 'Dynamic Agent',
1475
1466
  * instructions: 'You can use tools dynamically.',
1476
1467
  * model: 'openai/gpt-4',
1477
1468
  * });
1478
1469
  *
1479
1470
  * const response = await agent.stream(prompt, {
1480
- * toolsets: await mcp.getToolsets(), // { weather: {...}, stockPrice: {...} }
1471
+ * toolsets: await mcp.listToolsets(), // { weather: {...}, stockPrice: {...} }
1481
1472
  * });
1482
1473
  * ```
1483
1474
  */
1484
- async getToolsets() {
1475
+ async listToolsets() {
1485
1476
  this.addToInstanceCache();
1486
1477
  const connectedToolsets = {};
1487
1478
  try {
@@ -1502,12 +1493,6 @@ To fix this you have three different options:
1502
1493
  }
1503
1494
  return connectedToolsets;
1504
1495
  }
1505
- /**
1506
- * @deprecated all resource actions have been moved to the this.resources object. Use this.resources.list() instead.
1507
- */
1508
- async getResources() {
1509
- return this.resources.list();
1510
- }
1511
1496
  /**
1512
1497
  * Gets current session IDs for all connected MCP clients using Streamable HTTP transport.
1513
1498
  *
@@ -1594,24 +1579,8 @@ To fix this you have three different options:
1594
1579
  );
1595
1580
  }
1596
1581
  };
1597
- var MCPConfiguration = class extends MCPClient {
1598
- /**
1599
- * @deprecated Use MCPClient constructor instead
1600
- */
1601
- constructor(args) {
1602
- super(args);
1603
- throw new MastraError(
1604
- {
1605
- id: "MCP_CLIENT_CONFIGURATION_DEPRECATED",
1606
- domain: ErrorDomain.MCP,
1607
- category: ErrorCategory.USER,
1608
- text: "[DEPRECATION] MCPConfiguration has been renamed to MCPClient and MCPConfiguration is deprecated. The API is identical but the MCPConfiguration export will be removed in the future. Update your imports now to prevent future errors."
1609
- }
1610
- );
1611
- }
1612
- };
1613
1582
 
1614
- // ../../node_modules/.pnpm/hono@4.10.1/node_modules/hono/dist/utils/stream.js
1583
+ // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/utils/stream.js
1615
1584
  var StreamingApi = class {
1616
1585
  writer;
1617
1586
  encoder;
@@ -1678,7 +1647,7 @@ var StreamingApi = class {
1678
1647
  }
1679
1648
  };
1680
1649
 
1681
- // ../../node_modules/.pnpm/hono@4.10.1/node_modules/hono/dist/helper/streaming/utils.js
1650
+ // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/helper/streaming/utils.js
1682
1651
  var isOldBunVersion = () => {
1683
1652
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
1684
1653
  if (version === void 0) {
@@ -1689,7 +1658,7 @@ var isOldBunVersion = () => {
1689
1658
  return result;
1690
1659
  };
1691
1660
 
1692
- // ../../node_modules/.pnpm/hono@4.10.1/node_modules/hono/dist/utils/html.js
1661
+ // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/utils/html.js
1693
1662
  var HtmlEscapedCallbackPhase = {
1694
1663
  Stringify: 1};
1695
1664
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
@@ -1720,7 +1689,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
1720
1689
  }
1721
1690
  };
1722
1691
 
1723
- // ../../node_modules/.pnpm/hono@4.10.1/node_modules/hono/dist/helper/streaming/sse.js
1692
+ // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/helper/streaming/sse.js
1724
1693
  var SSEStreamingApi = class extends StreamingApi {
1725
1694
  constructor(writable, readable) {
1726
1695
  super(writable, readable);
@@ -2131,7 +2100,8 @@ var MCPServer = class extends MCPServerBase {
2131
2100
  * import { z } from 'zod';
2132
2101
  *
2133
2102
  * const myAgent = new Agent({
2134
- * name: 'Helper',
2103
+ * id: 'helper',
2104
+ * name: 'Helper Agent',
2135
2105
  * description: 'A helpful assistant',
2136
2106
  * instructions: 'You are helpful.',
2137
2107
  * model: 'openai/gpt-4o-mini',
@@ -2145,7 +2115,7 @@ var MCPServer = class extends MCPServerBase {
2145
2115
  * id: 'getWeather',
2146
2116
  * description: 'Gets weather',
2147
2117
  * inputSchema: z.object({ location: z.string() }),
2148
- * execute: async ({ context }) => `Sunny in ${context.location}`,
2118
+ * execute: async (inputData) => `Sunny in ${inputData.location}`,
2149
2119
  * })
2150
2120
  * },
2151
2121
  * agents: { myAgent },
@@ -2242,7 +2212,7 @@ var MCPServer = class extends MCPServerBase {
2242
2212
  return {
2243
2213
  tools: Object.values(this.convertedTools).map((tool) => {
2244
2214
  const toolSpec = {
2245
- name: tool.name,
2215
+ name: tool.id || "unknown",
2246
2216
  description: tool.description,
2247
2217
  inputSchema: tool.parameters.jsonSchema
2248
2218
  };
@@ -2301,12 +2271,23 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2301
2271
  return this.handleElicitationRequest(request2, serverInstance);
2302
2272
  }
2303
2273
  };
2304
- const result = await tool.execute(validation?.value ?? request.params.arguments ?? {}, {
2274
+ const mcpOptions = {
2305
2275
  messages: [],
2306
2276
  toolCallId: "",
2307
- elicitation: sessionElicitation,
2308
- extra
2309
- });
2277
+ // Pass MCP-specific context through the mcp property
2278
+ mcp: {
2279
+ elicitation: sessionElicitation,
2280
+ extra
2281
+ },
2282
+ // @ts-ignore this is to let people know that the elicitation and extra keys are now nested under mcp.elicitation and mcp.extra in tool arguments
2283
+ get elicitation() {
2284
+ throw new Error(`The "elicitation" key is now nested under "mcp.elicitation" in tool arguments`);
2285
+ },
2286
+ get extra() {
2287
+ throw new Error(`The "extra" key is now nested under "mcp.extra" in tool arguments`);
2288
+ }
2289
+ };
2290
+ const result = await tool.execute(validation?.value ?? request.params.arguments ?? {}, mcpOptions);
2310
2291
  this.logger.debug(`CallTool: Tool '${request.params.name}' executed successfully with result:`, result);
2311
2292
  const duration = Date.now() - startTime;
2312
2293
  this.logger.info(`Tool '${request.params.name}' executed successfully in ${duration}ms.`);
@@ -2582,12 +2563,12 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2582
2563
  inputSchema: z.object({
2583
2564
  message: z.string().describe("The question or input for the agent.")
2584
2565
  }),
2585
- execute: async ({ context, runtimeContext, tracingContext }) => {
2566
+ execute: async (inputData, context) => {
2586
2567
  this.logger.debug(
2587
- `Executing agent tool '${agentToolName}' for agent '${agent.name}' with message: "${context.message}"`
2568
+ `Executing agent tool '${agentToolName}' for agent '${agent.name}' with message: "${inputData.message}"`
2588
2569
  );
2589
2570
  try {
2590
- const response = await agent.generate(context.message, { runtimeContext, tracingContext });
2571
+ const response = await agent.generate(inputData.message, context);
2591
2572
  return response;
2592
2573
  } catch (error) {
2593
2574
  this.logger.error(`Error executing agent tool '${agentToolName}' for agent '${agent.name}':`, error);
@@ -2599,17 +2580,17 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2599
2580
  name: agentToolName,
2600
2581
  logger: this.logger,
2601
2582
  mastra: this.mastra,
2602
- runtimeContext: new RuntimeContext(),
2583
+ requestContext: new RequestContext(),
2603
2584
  tracingContext: {},
2604
2585
  description: agentToolDefinition.description
2605
2586
  };
2606
2587
  const coreTool = makeCoreTool(agentToolDefinition, options);
2607
2588
  agentTools[agentToolName] = {
2608
- name: agentToolName,
2609
- description: coreTool.description,
2610
- parameters: coreTool.parameters,
2611
- execute: coreTool.execute,
2612
- toolType: "agent"
2589
+ ...coreTool,
2590
+ id: agentToolName,
2591
+ mcp: {
2592
+ toolType: "agent"
2593
+ }
2613
2594
  };
2614
2595
  this.logger.info(`Registered agent '${agent.name}' (key: '${agentKey}') as tool: '${agentToolName}'`);
2615
2596
  }
@@ -2645,14 +2626,18 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2645
2626
  id: workflowToolName,
2646
2627
  description: `Run workflow '${workflowKey}'. Workflow description: ${workflowDescription}`,
2647
2628
  inputSchema: workflow.inputSchema,
2648
- execute: async ({ context, runtimeContext, tracingContext }) => {
2629
+ execute: async (inputData, context) => {
2649
2630
  this.logger.debug(
2650
2631
  `Executing workflow tool '${workflowToolName}' for workflow '${workflow.id}' with input:`,
2651
- context
2632
+ inputData
2652
2633
  );
2653
2634
  try {
2654
- const run2 = await workflow.createRunAsync({ runId: runtimeContext?.get("runId") });
2655
- const response = await run2.start({ inputData: context, runtimeContext, tracingContext });
2635
+ const run2 = await workflow.createRun({ runId: context?.requestContext?.get("runId") });
2636
+ const response = await run2.start({
2637
+ inputData,
2638
+ requestContext: context?.requestContext,
2639
+ tracingContext: context?.tracingContext
2640
+ });
2656
2641
  return response;
2657
2642
  } catch (error) {
2658
2643
  this.logger.error(
@@ -2667,18 +2652,17 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2667
2652
  name: workflowToolName,
2668
2653
  logger: this.logger,
2669
2654
  mastra: this.mastra,
2670
- runtimeContext: new RuntimeContext(),
2655
+ requestContext: new RequestContext(),
2671
2656
  tracingContext: {},
2672
2657
  description: workflowToolDefinition.description
2673
2658
  };
2674
2659
  const coreTool = makeCoreTool(workflowToolDefinition, options);
2675
2660
  workflowTools[workflowToolName] = {
2676
- name: workflowToolName,
2677
- description: coreTool.description,
2678
- parameters: coreTool.parameters,
2679
- outputSchema: coreTool.outputSchema,
2680
- execute: coreTool.execute,
2681
- toolType: "workflow"
2661
+ ...coreTool,
2662
+ id: workflowToolName,
2663
+ mcp: {
2664
+ toolType: "workflow"
2665
+ }
2682
2666
  };
2683
2667
  this.logger.info(`Registered workflow '${workflow.id}' (key: '${workflowKey}') as tool: '${workflowToolName}'`);
2684
2668
  }
@@ -2706,7 +2690,7 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2706
2690
  }
2707
2691
  const options = {
2708
2692
  name: toolName,
2709
- runtimeContext: new RuntimeContext(),
2693
+ requestContext: new RequestContext(),
2710
2694
  tracingContext: {},
2711
2695
  mastra: this.mastra,
2712
2696
  logger: this.logger,
@@ -2714,11 +2698,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2714
2698
  };
2715
2699
  const coreTool = makeCoreTool(toolInstance, options);
2716
2700
  definedConvertedTools[toolName] = {
2717
- name: toolName,
2718
- description: coreTool.description,
2719
- parameters: coreTool.parameters,
2720
- outputSchema: coreTool.outputSchema,
2721
- execute: coreTool.execute
2701
+ ...coreTool,
2702
+ id: toolName
2722
2703
  };
2723
2704
  this.logger.info(`Registered explicit tool: '${toolName}'`);
2724
2705
  }
@@ -2962,6 +2943,7 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2962
2943
  * @param options.options.onsessioninitialized - Callback when a new session is initialized
2963
2944
  * @param options.options.enableJsonResponse - If true, return JSON instead of SSE streaming
2964
2945
  * @param options.options.eventStore - Event store for message resumability
2946
+ * @param options.options.serverless - If true, run in stateless mode without session management (ideal for serverless environments)
2965
2947
  *
2966
2948
  * @throws {MastraError} If HTTP connection setup fails
2967
2949
  *
@@ -2987,6 +2969,25 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
2987
2969
  *
2988
2970
  * httpServer.listen(1234);
2989
2971
  * ```
2972
+ *
2973
+ * @example Serverless mode (Cloudflare Workers, Vercel Edge, etc.)
2974
+ * ```typescript
2975
+ * export default {
2976
+ * async fetch(request: Request) {
2977
+ * const url = new URL(request.url);
2978
+ * if (url.pathname === '/mcp') {
2979
+ * await server.startHTTP({
2980
+ * url,
2981
+ * httpPath: '/mcp',
2982
+ * req: request,
2983
+ * res: response,
2984
+ * options: { serverless: true },
2985
+ * });
2986
+ * }
2987
+ * return new Response('Not found', { status: 404 });
2988
+ * },
2989
+ * };
2990
+ * ```
2990
2991
  */
2991
2992
  async startHTTP({
2992
2993
  url,
@@ -3002,6 +3003,11 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3002
3003
  res.end();
3003
3004
  return;
3004
3005
  }
3006
+ if (options?.serverless) {
3007
+ this.logger.debug("startHTTP: Running in serverless (stateless) mode");
3008
+ await this.handleServerlessRequest(req, res);
3009
+ return;
3010
+ }
3005
3011
  const sessionId = req.headers["mcp-session-id"];
3006
3012
  let transport;
3007
3013
  this.logger.debug(
@@ -3137,6 +3143,74 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3137
3143
  }
3138
3144
  }
3139
3145
  }
3146
+ /**
3147
+ * Handles a stateless, serverless HTTP request without session management.
3148
+ *
3149
+ * This method bypasses all session/transport state and handles each request independently.
3150
+ * For serverless environments (Cloudflare Workers, Vercel Edge, etc.) where
3151
+ * persistent connections and session state cannot be maintained across requests.
3152
+ *
3153
+ * Each request gets a fresh transport and server instance that are discarded after the response.
3154
+ *
3155
+ * @param req - Incoming HTTP request
3156
+ * @param res - HTTP response object
3157
+ * @private
3158
+ */
3159
+ async handleServerlessRequest(req, res) {
3160
+ try {
3161
+ this.logger.debug(`handleServerlessRequest: Received ${req.method} request`);
3162
+ const body = req.method === "POST" ? await new Promise((resolve, reject) => {
3163
+ let data = "";
3164
+ req.on("data", (chunk) => data += chunk);
3165
+ req.on("end", () => {
3166
+ try {
3167
+ resolve(JSON.parse(data));
3168
+ } catch (e) {
3169
+ reject(new Error(`Invalid JSON in request body: ${e instanceof Error ? e.message : String(e)}`));
3170
+ }
3171
+ });
3172
+ req.on("error", reject);
3173
+ }) : void 0;
3174
+ this.logger.debug(`handleServerlessRequest: Processing ${req.method} request`, {
3175
+ method: body?.method,
3176
+ id: body?.id
3177
+ });
3178
+ const transientServer = this.createServerInstance();
3179
+ const tempTransport = new StreamableHTTPServerTransport({
3180
+ sessionIdGenerator: void 0,
3181
+ enableJsonResponse: true
3182
+ });
3183
+ await transientServer.connect(tempTransport);
3184
+ await tempTransport.handleRequest(req, res, body);
3185
+ this.logger.debug(`handleServerlessRequest: Completed ${body?.method} request`, { id: body?.id });
3186
+ } catch (error) {
3187
+ const mastraError = new MastraError(
3188
+ {
3189
+ id: "MCP_SERVER_SERVERLESS_REQUEST_FAILED",
3190
+ domain: ErrorDomain.MCP,
3191
+ category: ErrorCategory.USER,
3192
+ text: "Failed to handle serverless MCP request"
3193
+ },
3194
+ error
3195
+ );
3196
+ this.logger.trackException(mastraError);
3197
+ this.logger.error("handleServerlessRequest: Error handling request:", { error: mastraError });
3198
+ if (!res.headersSent) {
3199
+ res.writeHead(500, { "Content-Type": "application/json" });
3200
+ res.end(
3201
+ JSON.stringify({
3202
+ jsonrpc: "2.0",
3203
+ error: {
3204
+ code: -32603,
3205
+ message: "Internal server error",
3206
+ data: error instanceof Error ? error.message : String(error)
3207
+ },
3208
+ id: null
3209
+ })
3210
+ );
3211
+ }
3212
+ }
3213
+ }
3140
3214
  /**
3141
3215
  * Establishes the SSE connection for the MCP server.
3142
3216
  *
@@ -3385,11 +3459,11 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3385
3459
  return {
3386
3460
  tools: Object.entries(this.convertedTools).map(([toolId, tool]) => ({
3387
3461
  id: toolId,
3388
- name: tool.name,
3462
+ name: tool.id || toolId,
3389
3463
  description: tool.description,
3390
3464
  inputSchema: tool.parameters?.jsonSchema || tool.parameters,
3391
3465
  outputSchema: tool.outputSchema?.jsonSchema || tool.outputSchema,
3392
- toolType: tool.toolType
3466
+ toolType: tool.mcp?.toolType
3393
3467
  }))
3394
3468
  };
3395
3469
  }
@@ -3419,11 +3493,11 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3419
3493
  }
3420
3494
  this.logger.debug(`Getting info for tool '${toolId}' on MCPServer '${this.name}'`);
3421
3495
  return {
3422
- name: tool.name,
3496
+ name: tool.id || toolId,
3423
3497
  description: tool.description,
3424
3498
  inputSchema: tool.parameters?.jsonSchema || tool.parameters,
3425
3499
  outputSchema: tool.outputSchema?.jsonSchema || tool.outputSchema,
3426
- toolType: tool.toolType
3500
+ toolType: tool.mcp?.toolType
3427
3501
  };
3428
3502
  }
3429
3503
  /**
@@ -3527,6 +3601,6 @@ Provided arguments: ${JSON.stringify(args, null, 2)}`,
3527
3601
  }
3528
3602
  };
3529
3603
 
3530
- export { MCPClient, MCPConfiguration, MCPServer, MastraMCPClient };
3604
+ export { MCPClient, MCPServer };
3531
3605
  //# sourceMappingURL=index.js.map
3532
3606
  //# sourceMappingURL=index.js.map