@mastra/mcp 1.0.0-beta.2 → 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,28 @@
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
+
3
26
  ## 1.0.0-beta.2
4
27
 
5
28
  ### 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"}
@@ -157,6 +157,8 @@ export declare class InternalMastraMCPClient extends MastraBase {
157
157
  private serverConfig;
158
158
  private transport?;
159
159
  private currentOperationContext;
160
+ private exitHookUnsubscribe?;
161
+ private sigTermHandler?;
160
162
  /** Provides access to resource operations (list, read, subscribe, etc.) */
161
163
  readonly resources: ResourceClientActions;
162
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,iBAA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E,qCAAqC,CACnC,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC,QAAQ,CAAC,KAAK,IAAI,GACrF,IAAI;IAOP,yCAAyC,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAOpE,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;YAQjD,kBAAkB;YA0ClB,mBAAmB;IA2C3B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;CA+DjE"}
package/dist/index.cjs CHANGED
@@ -401,6 +401,8 @@ var InternalMastraMCPClient = class extends base.MastraBase {
401
401
  serverConfig;
402
402
  transport;
403
403
  currentOperationContext = null;
404
+ exitHookUnsubscribe;
405
+ sigTermHandler;
404
406
  /** Provides access to resource operations (list, read, subscribe, etc.) */
405
407
  resources;
406
408
  /** Provides access to prompt operations (list, get, notifications) */
@@ -568,14 +570,19 @@ var InternalMastraMCPClient = class extends base.MastraBase {
568
570
  reject(e);
569
571
  }
570
572
  });
571
- exitHook.asyncExitHook(
572
- async () => {
573
- this.log("debug", `Disconnecting MCP server during exit`);
574
- await this.disconnect();
575
- },
576
- { wait: 5e3 }
577
- );
578
- 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
+ }
579
586
  this.log("debug", `Successfully connected to MCP server`);
580
587
  return this.isConnected;
581
588
  }
@@ -611,6 +618,14 @@ var InternalMastraMCPClient = class extends base.MastraBase {
611
618
  } finally {
612
619
  this.transport = void 0;
613
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
+ }
614
629
  }
615
630
  }
616
631
  async listResources() {
@@ -798,6 +813,9 @@ var InternalMastraMCPClient = class extends base.MastraBase {
798
813
  }
799
814
  );
800
815
  this.log("debug", `Tool executed successfully: ${tool.name}`);
816
+ if (res.structuredContent !== void 0) {
817
+ return res.structuredContent;
818
+ }
801
819
  return res;
802
820
  } catch (e) {
803
821
  this.log("error", `Error calling tool: ${tool.name}`, {
@@ -3006,7 +3024,7 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3006
3024
  httpPath,
3007
3025
  req,
3008
3026
  res,
3009
- options = { sessionIdGenerator: () => crypto$1.randomUUID() }
3027
+ options
3010
3028
  }) {
3011
3029
  this.logger.debug(`startHTTP: Received ${req.method} request to ${url.pathname}`);
3012
3030
  if (url.pathname !== httpPath) {
@@ -3015,11 +3033,18 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3015
3033
  res.end();
3016
3034
  return;
3017
3035
  }
3018
- if (options?.serverless) {
3019
- 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)");
3020
3039
  await this.handleServerlessRequest(req, res);
3021
3040
  return;
3022
3041
  }
3042
+ const mergedOptions = {
3043
+ sessionIdGenerator: () => crypto$1.randomUUID(),
3044
+ // default: enabled
3045
+ ...options
3046
+ // user-provided overrides default
3047
+ };
3023
3048
  const sessionId = req.headers["mcp-session-id"];
3024
3049
  let transport;
3025
3050
  this.logger.debug(
@@ -3066,8 +3091,8 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3066
3091
  if (isInitializeRequest(body)) {
3067
3092
  this.logger.debug("startHTTP: Received Streamable HTTP initialize request, creating new transport.");
3068
3093
  transport = new streamableHttp_js.StreamableHTTPServerTransport({
3069
- ...options,
3070
- sessionIdGenerator: () => crypto$1.randomUUID(),
3094
+ ...mergedOptions,
3095
+ sessionIdGenerator: mergedOptions.sessionIdGenerator,
3071
3096
  onsessioninitialized: (id) => {
3072
3097
  this.streamableHTTPTransports.set(id, transport);
3073
3098
  }