@mastra/mcp 1.0.0-beta.1 → 1.0.0-beta.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 1.0.0-beta.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix MCPClient resource leak causing MaxListenersExceededWarning ([#10501](https://github.com/mastra-ai/mastra/pull/10501))
8
+
9
+ Fixes an issue where `InternalMastraMCPClient` registered event listeners to the `process` object for graceful shutdown but failed to remove them upon disconnection. This caused a memory leak after multiple connect/disconnect cycles, triggering the warning:
10
+
11
+ ```
12
+ MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process].
13
+ ```
14
+
15
+ The fix stores references to the exit hook unsubscribe function and SIGTERM handler, then properly cleans them up in `disconnect()`.
16
+
17
+ Additionally, users can now disable session management by passing `sessionIdGenerator: undefined` in `startHTTP()` options. This enables stateless MCP server deployments, which is useful for serverless environments.
18
+
19
+ Fixes #10499, #8526
20
+
21
+ - Fix MCP client to return structuredContent directly when tools define an outputSchema, ensuring output validation works correctly instead of failing with "expected X, received undefined" errors. ([#10442](https://github.com/mastra-ai/mastra/pull/10442))
22
+
23
+ - Updated dependencies [[`21a15de`](https://github.com/mastra-ai/mastra/commit/21a15de369fe82aac26bb642ed7be73505475e8b), [`feb7ee4`](https://github.com/mastra-ai/mastra/commit/feb7ee4d09a75edb46c6669a3beaceec78811747), [`b0e2ea5`](https://github.com/mastra-ai/mastra/commit/b0e2ea5b52c40fae438b9e2f7baee6f0f89c5442), [`c456e01`](https://github.com/mastra-ai/mastra/commit/c456e0149e3c176afcefdbd9bb1d2c5917723725), [`ab035c2`](https://github.com/mastra-ai/mastra/commit/ab035c2ef6d8cc7bb25f06f1a38508bd9e6f126b), [`1a46a56`](https://github.com/mastra-ai/mastra/commit/1a46a566f45a3fcbadc1cf36bf86d351f264bfa3), [`3cf540b`](https://github.com/mastra-ai/mastra/commit/3cf540b9fbfea8f4fc8d3a2319a4e6c0b0cbfd52), [`1c6ce51`](https://github.com/mastra-ai/mastra/commit/1c6ce51f875915ab57fd36873623013699a2a65d), [`898a972`](https://github.com/mastra-ai/mastra/commit/898a9727d286c2510d6b702dfd367e6aaf5c6b0f), [`a97003a`](https://github.com/mastra-ai/mastra/commit/a97003aa1cf2f4022a41912324a1e77263b326b8), [`ccc141e`](https://github.com/mastra-ai/mastra/commit/ccc141ed27da0abc3a3fc28e9e5128152e8e37f4), [`fe3b897`](https://github.com/mastra-ai/mastra/commit/fe3b897c2ccbcd2b10e81b099438c7337feddf89), [`00123ba`](https://github.com/mastra-ai/mastra/commit/00123ba96dc9e5cd0b110420ebdba56d8f237b25), [`29c4309`](https://github.com/mastra-ai/mastra/commit/29c4309f818b24304c041bcb4a8f19b5f13f6b62), [`16785ce`](https://github.com/mastra-ai/mastra/commit/16785ced928f6f22638f4488cf8a125d99211799), [`de8239b`](https://github.com/mastra-ai/mastra/commit/de8239bdcb1d8c0cfa06da21f1569912a66bbc8a), [`b5e6cd7`](https://github.com/mastra-ai/mastra/commit/b5e6cd77fc8c8e64e0494c1d06cee3d84e795d1e), [`3759cb0`](https://github.com/mastra-ai/mastra/commit/3759cb064935b5f74c65ac2f52a1145f7352899d), [`651e772`](https://github.com/mastra-ai/mastra/commit/651e772eb1475fb13e126d3fcc01751297a88214), [`b61b93f`](https://github.com/mastra-ai/mastra/commit/b61b93f9e058b11dd2eec169853175d31dbdd567), [`bae33d9`](https://github.com/mastra-ai/mastra/commit/bae33d91a63fbb64d1e80519e1fc1acaed1e9013), [`c0b731f`](https://github.com/mastra-ai/mastra/commit/c0b731fb27d712dc8582e846df5c0332a6a0c5ba), [`43ca8f2`](https://github.com/mastra-ai/mastra/commit/43ca8f2c7334851cc7b4d3d2f037d8784bfbdd5f), [`2ca67cc`](https://github.com/mastra-ai/mastra/commit/2ca67cc3bb1f6a617353fdcab197d9efebe60d6f), [`9e67002`](https://github.com/mastra-ai/mastra/commit/9e67002b52c9be19936c420a489dbee9c5fd6a78), [`35edc49`](https://github.com/mastra-ai/mastra/commit/35edc49ac0556db609189641d6341e76771b81fc)]:
24
+ - @mastra/core@1.0.0-beta.5
25
+
26
+ ## 1.0.0-beta.2
27
+
28
+ ### Patch Changes
29
+
30
+ - Add timeout configuration to mcp server config ([#9950](https://github.com/mastra-ai/mastra/pull/9950))
31
+
32
+ - Remove unused dependencies ([#10019](https://github.com/mastra-ai/mastra/pull/10019))
33
+
34
+ - Updated dependencies [[`2319326`](https://github.com/mastra-ai/mastra/commit/2319326f8c64e503a09bbcf14be2dd65405445e0), [`d629361`](https://github.com/mastra-ai/mastra/commit/d629361a60f6565b5bfb11976fdaf7308af858e2), [`08c31c1`](https://github.com/mastra-ai/mastra/commit/08c31c188ebccd598acaf55e888b6397d01f7eae), [`fd3d338`](https://github.com/mastra-ai/mastra/commit/fd3d338a2c362174ed5b383f1f011ad9fb0302aa), [`c30400a`](https://github.com/mastra-ai/mastra/commit/c30400a49b994b1b97256fe785eb6c906fc2b232), [`69e0a87`](https://github.com/mastra-ai/mastra/commit/69e0a878896a2da9494945d86e056a5f8f05b851), [`01f8878`](https://github.com/mastra-ai/mastra/commit/01f88783de25e4de048c1c8aace43e26373c6ea5), [`4c77209`](https://github.com/mastra-ai/mastra/commit/4c77209e6c11678808b365d545845918c40045c8), [`d827d08`](https://github.com/mastra-ai/mastra/commit/d827d0808ffe1f3553a84e975806cc989b9735dd), [`23c10a1`](https://github.com/mastra-ai/mastra/commit/23c10a1efdd9a693c405511ab2dc8a1236603162), [`676ccc7`](https://github.com/mastra-ai/mastra/commit/676ccc7fe92468d2d45d39c31a87825c89fd1ea0), [`c10398d`](https://github.com/mastra-ai/mastra/commit/c10398d5b88f1d4af556f4267ff06f1d11e89179), [`00c2387`](https://github.com/mastra-ai/mastra/commit/00c2387f5f04a365316f851e58666ac43f8c4edf), [`ad6250d`](https://github.com/mastra-ai/mastra/commit/ad6250dbdaad927e29f74a27b83f6c468b50a705), [`3a73998`](https://github.com/mastra-ai/mastra/commit/3a73998fa4ebeb7f3dc9301afe78095fc63e7999), [`e16d553`](https://github.com/mastra-ai/mastra/commit/e16d55338403c7553531cc568125c63d53653dff), [`4d59f58`](https://github.com/mastra-ai/mastra/commit/4d59f58de2d90d6e2810a19d4518e38ddddb9038), [`e1bb9c9`](https://github.com/mastra-ai/mastra/commit/e1bb9c94b4eb68b019ae275981be3feb769b5365), [`351a11f`](https://github.com/mastra-ai/mastra/commit/351a11fcaf2ed1008977fa9b9a489fc422e51cd4)]:
35
+ - @mastra/core@1.0.0-beta.3
36
+
3
37
  ## 1.0.0-beta.1
4
38
 
5
39
  ### Patch Changes
@@ -5,5 +5,5 @@ export declare const weatherTool: import("@mastra/core/tools").Tool<z.ZodObject<
5
5
  location: string;
6
6
  }, {
7
7
  location: string;
8
- }>, undefined, any, any, import("@mastra/core/tools").ToolExecutionContext<any, any>>;
8
+ }>, undefined, any, any, import("@mastra/core/tools").ToolExecutionContext<any, any>, "get-weather">;
9
9
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,eAAO,MAAM,WAAW;;;;;;qFAUtB,CAAC"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,eAAO,MAAM,WAAW;;;;;;oGAUtB,CAAC"}
@@ -68,6 +68,7 @@ type StdioServerDefinition = BaseServerOptions & {
68
68
  authProvider?: never;
69
69
  reconnectionOptions?: never;
70
70
  sessionId?: never;
71
+ connectTimeout?: never;
71
72
  };
72
73
  /**
73
74
  * Configuration for MCP servers using HTTP-based transport (Streamable HTTP or SSE fallback).
@@ -91,6 +92,11 @@ type HttpServerDefinition = BaseServerOptions & {
91
92
  reconnectionOptions?: StreamableHTTPClientTransportOptions['reconnectionOptions'];
92
93
  /** Optional session ID for Streamable HTTP */
93
94
  sessionId?: StreamableHTTPClientTransportOptions['sessionId'];
95
+ /** Optional timeout in milliseconds for the connection phase (default: 3000ms).
96
+ * This timeout allows the system to switch MCP streaming protocols during the setup phase.
97
+ * The default is set to 3s because the long default timeout would be extremely slow for SSE backwards compat (60s).
98
+ */
99
+ connectTimeout?: number;
94
100
  };
95
101
  /**
96
102
  * Configuration for connecting to an MCP server.
@@ -151,6 +157,8 @@ export declare class InternalMastraMCPClient extends MastraBase {
151
157
  private serverConfig;
152
158
  private transport?;
153
159
  private currentOperationContext;
160
+ private exitHookUnsubscribe?;
161
+ private sigTermHandler?;
154
162
  /** Provides access to resource operations (list, read, subscribe, etc.) */
155
163
  readonly resources: ResourceClientActions;
156
164
  /** Provides access to prompt operations (list, get, notifications) */
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAI/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGzF,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,oDAAoD,CAAC;AAG/G,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACb,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAKL,iCAAiC,EAMlC,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,wBA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_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
376
377
  function convertLogLevelToLoggerMethod(level) {
377
378
  switch (level) {
378
379
  case "debug":
@@ -400,6 +401,8 @@ var InternalMastraMCPClient = class extends base.MastraBase {
400
401
  serverConfig;
401
402
  transport;
402
403
  currentOperationContext = null;
404
+ exitHookUnsubscribe;
405
+ sigTermHandler;
403
406
  /** Provides access to resource operations (list, read, subscribe, etc.) */
404
407
  resources;
405
408
  /** Provides access to prompt operations (list, get, notifications) */
@@ -490,7 +493,7 @@ var InternalMastraMCPClient = class extends base.MastraBase {
490
493
  }
491
494
  }
492
495
  async connectHttp(url) {
493
- const { requestInit, eventSourceInit, authProvider } = this.serverConfig;
496
+ const { requestInit, eventSourceInit, authProvider, connectTimeout } = this.serverConfig;
494
497
  this.log("debug", `Attempting to connect to URL: ${url}`);
495
498
  let shouldTrySSE = url.pathname.endsWith(`/sse`);
496
499
  if (!shouldTrySSE) {
@@ -502,10 +505,7 @@ var InternalMastraMCPClient = class extends base.MastraBase {
502
505
  authProvider
503
506
  });
504
507
  await this.client.connect(streamableTransport, {
505
- timeout: (
506
- // this is hardcoded to 3s because the long default timeout would be extremely slow for sse backwards compat (60s)
507
- 3e3
508
- )
508
+ timeout: connectTimeout ?? DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC
509
509
  });
510
510
  this.transport = streamableTransport;
511
511
  this.log("debug", "Successfully connected using Streamable HTTP transport.");
@@ -570,14 +570,19 @@ var InternalMastraMCPClient = class extends base.MastraBase {
570
570
  reject(e);
571
571
  }
572
572
  });
573
- exitHook.asyncExitHook(
574
- async () => {
575
- this.log("debug", `Disconnecting MCP server during exit`);
576
- await this.disconnect();
577
- },
578
- { wait: 5e3 }
579
- );
580
- process.on("SIGTERM", () => exitHook.gracefulExit());
573
+ if (!this.exitHookUnsubscribe) {
574
+ this.exitHookUnsubscribe = exitHook.asyncExitHook(
575
+ async () => {
576
+ this.log("debug", `Disconnecting MCP server during exit`);
577
+ await this.disconnect();
578
+ },
579
+ { wait: 5e3 }
580
+ );
581
+ }
582
+ if (!this.sigTermHandler) {
583
+ this.sigTermHandler = () => exitHook.gracefulExit();
584
+ process.on("SIGTERM", this.sigTermHandler);
585
+ }
581
586
  this.log("debug", `Successfully connected to MCP server`);
582
587
  return this.isConnected;
583
588
  }
@@ -613,6 +618,14 @@ var InternalMastraMCPClient = class extends base.MastraBase {
613
618
  } finally {
614
619
  this.transport = void 0;
615
620
  this.isConnected = Promise.resolve(false);
621
+ if (this.exitHookUnsubscribe) {
622
+ this.exitHookUnsubscribe();
623
+ this.exitHookUnsubscribe = void 0;
624
+ }
625
+ if (this.sigTermHandler) {
626
+ process.off("SIGTERM", this.sigTermHandler);
627
+ this.sigTermHandler = void 0;
628
+ }
616
629
  }
617
630
  }
618
631
  async listResources() {
@@ -800,6 +813,9 @@ var InternalMastraMCPClient = class extends base.MastraBase {
800
813
  }
801
814
  );
802
815
  this.log("debug", `Tool executed successfully: ${tool.name}`);
816
+ if (res.structuredContent !== void 0) {
817
+ return res.structuredContent;
818
+ }
803
819
  return res;
804
820
  } catch (e) {
805
821
  this.log("error", `Error calling tool: ${tool.name}`, {
@@ -1587,7 +1603,7 @@ To fix this you have three different options:
1587
1603
  }
1588
1604
  };
1589
1605
 
1590
- // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/utils/stream.js
1606
+ // ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/stream.js
1591
1607
  var StreamingApi = class {
1592
1608
  writer;
1593
1609
  encoder;
@@ -1654,7 +1670,7 @@ var StreamingApi = class {
1654
1670
  }
1655
1671
  };
1656
1672
 
1657
- // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/helper/streaming/utils.js
1673
+ // ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/utils.js
1658
1674
  var isOldBunVersion = () => {
1659
1675
  const version = typeof Bun !== "undefined" ? Bun.version : void 0;
1660
1676
  if (version === void 0) {
@@ -1665,7 +1681,7 @@ var isOldBunVersion = () => {
1665
1681
  return result;
1666
1682
  };
1667
1683
 
1668
- // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/utils/html.js
1684
+ // ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/utils/html.js
1669
1685
  var HtmlEscapedCallbackPhase = {
1670
1686
  Stringify: 1};
1671
1687
  var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
@@ -1696,7 +1712,7 @@ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) =>
1696
1712
  }
1697
1713
  };
1698
1714
 
1699
- // ../../node_modules/.pnpm/hono@4.10.3/node_modules/hono/dist/helper/streaming/sse.js
1715
+ // ../../node_modules/.pnpm/hono@4.10.6/node_modules/hono/dist/helper/streaming/sse.js
1700
1716
  var SSEStreamingApi = class extends StreamingApi {
1701
1717
  constructor(writable, readable) {
1702
1718
  super(writable, readable);
@@ -3008,7 +3024,7 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3008
3024
  httpPath,
3009
3025
  req,
3010
3026
  res,
3011
- options = { sessionIdGenerator: () => crypto$1.randomUUID() }
3027
+ options
3012
3028
  }) {
3013
3029
  this.logger.debug(`startHTTP: Received ${req.method} request to ${url.pathname}`);
3014
3030
  if (url.pathname !== httpPath) {
@@ -3017,11 +3033,18 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3017
3033
  res.end();
3018
3034
  return;
3019
3035
  }
3020
- if (options?.serverless) {
3021
- this.logger.debug("startHTTP: Running in serverless (stateless) mode");
3036
+ const isStatelessMode = options?.serverless || options && "sessionIdGenerator" in options && options.sessionIdGenerator === void 0;
3037
+ if (isStatelessMode) {
3038
+ this.logger.debug("startHTTP: Running in stateless mode (serverless or sessionIdGenerator: undefined)");
3022
3039
  await this.handleServerlessRequest(req, res);
3023
3040
  return;
3024
3041
  }
3042
+ const mergedOptions = {
3043
+ sessionIdGenerator: () => crypto$1.randomUUID(),
3044
+ // default: enabled
3045
+ ...options
3046
+ // user-provided overrides default
3047
+ };
3025
3048
  const sessionId = req.headers["mcp-session-id"];
3026
3049
  let transport;
3027
3050
  this.logger.debug(
@@ -3068,8 +3091,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3068
3091
  if (isInitializeRequest(body)) {
3069
3092
  this.logger.debug("startHTTP: Received Streamable HTTP initialize request, creating new transport.");
3070
3093
  transport = new streamableHttp_js.StreamableHTTPServerTransport({
3071
- ...options,
3072
- sessionIdGenerator: () => crypto$1.randomUUID(),
3094
+ ...mergedOptions,
3095
+ sessionIdGenerator: mergedOptions.sessionIdGenerator,
3073
3096
  onsessioninitialized: (id) => {
3074
3097
  this.streamableHTTPTransports.set(id, transport);
3075
3098
  }