@mastra/mcp 1.9.1-alpha.0 → 1.9.2-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 1.9.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed `MCPServer` leaking one caller's resources to other callers. The result of the first `resources/list` request was cached on the shared, long-lived server instance and replayed to everyone, so a dynamic resource provider that scopes resources per user or tenant (resolved from `extra.authInfo`) served the first caller's resource index — names and URIs — to subsequent callers. The same stale cache also backed `resources/read` URI resolution and the public `listResources()` method. The `resources/templates/list` handler had the same defect for dynamic resource template providers. ([#17610](https://github.com/mastra-ai/mastra/pull/17610))
8
+
9
+ Resource and resource template providers are now invoked on every request with the current caller's context, so each caller only sees their own resources. See https://github.com/mastra-ai/mastra/issues/17609
10
+
11
+ - Fixed flaky MCP server tests by replacing real weather API calls with deterministic mock tool ([#17572](https://github.com/mastra-ai/mastra/pull/17572))
12
+
13
+ - Updated dependencies [[`d468acb`](https://github.com/mastra-ai/mastra/commit/d468acb07aec1bb19a2cb0ada8042b05b46746b2), [`e9be4e7`](https://github.com/mastra-ai/mastra/commit/e9be4e747ec3d8b65548bff92f9377db06105376), [`d53cfc2`](https://github.com/mastra-ai/mastra/commit/d53cfc2c7f8d78343a4aa84ec4e129ba25f3325e), [`65799d4`](https://github.com/mastra-ai/mastra/commit/65799d4d549e5ebb9c848fbe3f51ac090f64becf), [`c268c89`](https://github.com/mastra-ai/mastra/commit/c268c89f4c63a93ee474d3cffdf3ea60bf00d4f2), [`d468acb`](https://github.com/mastra-ai/mastra/commit/d468acb07aec1bb19a2cb0ada8042b05b46746b2), [`0c72f03`](https://github.com/mastra-ai/mastra/commit/0c72f032abb13254df5a7856d64be2f207b8006d), [`3b45ea9`](https://github.com/mastra-ai/mastra/commit/3b45ea95015557a6cb9d70dc5252af54ab1b78ac), [`f084be1`](https://github.com/mastra-ai/mastra/commit/f084be1fcbe33ad7480913e44d6130c421c0976f)]:
14
+ - @mastra/core@1.42.0-alpha.0
15
+
16
+ ## 1.9.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Removed Hono from @mastra/core and auth package runtime dependencies. Auth providers now receive framework-agnostic request types that support standard Request objects and Hono-compatible request shapes. MCP and deployer avoid relying on core-bundled Hono context types at package boundaries. ([#17410](https://github.com/mastra-ai/mastra/pull/17410))
21
+
22
+ - Updated dependencies [[`c973db4`](https://github.com/mastra-ai/mastra/commit/c973db428df1b564ff0c35d4b2a90e8f4f1e13fd), [`552285e`](https://github.com/mastra-ai/mastra/commit/552285e5af43cfc680a0972032cab8de8776c6a0), [`77e686c`](https://github.com/mastra-ai/mastra/commit/77e686c264e493e99ae5024e4dfe3ea5d5a09718), [`ece8dba`](https://github.com/mastra-ai/mastra/commit/ece8dba7ec1a5089eee8c33167cd762bfa91e509), [`e751af2`](https://github.com/mastra-ai/mastra/commit/e751af219433fbf4c7035b2d771b4c9ec8813b05), [`e2a8380`](https://github.com/mastra-ai/mastra/commit/e2a838017a7657850404c1e94c70d79ffdc6f14a), [`be3f1cd`](https://github.com/mastra-ai/mastra/commit/be3f1cd81f0e2a649e8eac15a024d542d814aef8), [`a34d9db`](https://github.com/mastra-ai/mastra/commit/a34d9dbc39fedb722f271318e9355ecee70489ab)]:
23
+ - @mastra/core@1.39.0
24
+
3
25
  ## 1.9.1-alpha.0
4
26
 
5
27
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-mcp
3
3
  description: Documentation for @mastra/mcp. Use when working with @mastra/mcp APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mcp"
6
- version: "1.9.1-alpha.0"
6
+ version: "1.9.2-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.1-alpha.0",
2
+ "version": "1.9.2-alpha.0",
3
3
  "package": "@mastra/mcp",
4
4
  "exports": {
5
5
  "UnauthorizedError": {
package/dist/index.cjs CHANGED
@@ -2671,8 +2671,6 @@ var ServerResourceActions = class {
2671
2671
  getSubscriptions;
2672
2672
  getLogger;
2673
2673
  getSdkServer;
2674
- clearDefinedResources;
2675
- clearDefinedResourceTemplates;
2676
2674
  /**
2677
2675
  * @internal
2678
2676
  */
@@ -2680,8 +2678,6 @@ var ServerResourceActions = class {
2680
2678
  this.getSubscriptions = dependencies.getSubscriptions;
2681
2679
  this.getLogger = dependencies.getLogger;
2682
2680
  this.getSdkServer = dependencies.getSdkServer;
2683
- this.clearDefinedResources = dependencies.clearDefinedResources;
2684
- this.clearDefinedResourceTemplates = dependencies.clearDefinedResourceTemplates;
2685
2681
  }
2686
2682
  /**
2687
2683
  * Notifies subscribed clients that a specific resource has been updated.
@@ -2730,8 +2726,9 @@ var ServerResourceActions = class {
2730
2726
  /**
2731
2727
  * Notifies clients that the overall list of available resources has changed.
2732
2728
  *
2733
- * This clears the internal resource cache and sends a `notifications/resources/list_changed`
2734
- * message to all clients, prompting them to re-fetch the resource list.
2729
+ * This sends a `notifications/resources/list_changed` message to all clients, prompting
2730
+ * them to re-fetch the resource list. Resource lists and templates are always evaluated
2731
+ * per request, so there is no server-side cache to clear.
2735
2732
  *
2736
2733
  * @throws {MastraError} If sending the notification fails
2737
2734
  *
@@ -2742,11 +2739,7 @@ var ServerResourceActions = class {
2742
2739
  * ```
2743
2740
  */
2744
2741
  async notifyListChanged() {
2745
- this.getLogger().info(
2746
- "Resource list change externally notified. Clearing definedResources and sending notification."
2747
- );
2748
- this.clearDefinedResources();
2749
- this.clearDefinedResourceTemplates();
2742
+ this.getLogger().info("Resource list change externally notified. Sending notification.");
2750
2743
  try {
2751
2744
  await this.getSdkServer().sendResourceListChanged();
2752
2745
  } catch (error$1) {
@@ -2777,9 +2770,11 @@ var MCPServer = class extends mcp.MCPServerBase {
2777
2770
  streamableHTTPTransports = /* @__PURE__ */ new Map();
2778
2771
  // Track server instances for each HTTP session
2779
2772
  httpServerInstances = /* @__PURE__ */ new Map();
2780
- definedResources;
2781
- definedResourceTemplates;
2782
2773
  resourceOptions;
2774
+ // Whether any UI (`ui://`) app resources are configured. Captured at construction so
2775
+ // per-request server instances can advertise the MCP Apps extension without relying on
2776
+ // a shared, per-caller resource cache.
2777
+ hasUiResources = false;
2783
2778
  definedPrompts;
2784
2779
  promptOptions;
2785
2780
  jsonSchemaValidator;
@@ -2920,6 +2915,7 @@ var MCPServer = class extends mcp.MCPServerBase {
2920
2915
  constructor(opts) {
2921
2916
  super(opts);
2922
2917
  this.resourceOptions = this.mergeAppResources(opts.resources, opts.appResources);
2918
+ this.hasUiResources = !!opts.appResources && Object.keys(opts.appResources).length > 0;
2923
2919
  this.promptOptions = opts.prompts;
2924
2920
  this.jsonSchemaValidator = opts.jsonSchemaValidator;
2925
2921
  this.mapAuthInfoToUser = opts.mapAuthInfoToUser;
@@ -2965,13 +2961,7 @@ var MCPServer = class extends mcp.MCPServerBase {
2965
2961
  this.resources = new ServerResourceActions({
2966
2962
  getSubscriptions: () => this.subscriptions,
2967
2963
  getLogger: () => this.logger,
2968
- getSdkServer: () => this.server,
2969
- clearDefinedResources: () => {
2970
- this.definedResources = void 0;
2971
- },
2972
- clearDefinedResourceTemplates: () => {
2973
- this.definedResourceTemplates = void 0;
2974
- }
2964
+ getSdkServer: () => this.server
2975
2965
  });
2976
2966
  this.prompts = new ServerPromptActions({
2977
2967
  getLogger: () => this.logger,
@@ -3130,14 +3120,11 @@ var MCPServer = class extends mcp.MCPServerBase {
3130
3120
  const hasUiTools = Object.values(this.convertedTools).some(
3131
3121
  (tool) => tool.mcp?._meta?.ui?.resourceUri
3132
3122
  );
3133
- if (hasUiTools || this.resourceOptions) {
3134
- const hasUiResources = this.definedResources?.some((r) => r.uri.startsWith("ui://"));
3135
- if (hasUiTools || hasUiResources) {
3136
- capabilities.extensions = {
3137
- ...capabilities.extensions,
3138
- "io.modelcontextprotocol/ui": {}
3139
- };
3140
- }
3123
+ if (hasUiTools || this.hasUiResources) {
3124
+ capabilities.extensions = {
3125
+ ...capabilities.extensions,
3126
+ "io.modelcontextprotocol/ui": {}
3127
+ };
3141
3128
  }
3142
3129
  const serverInstance = new index_js$1.Server(
3143
3130
  {
@@ -3354,18 +3341,13 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3354
3341
  if (!capturedResourceOptions) return;
3355
3342
  if (capturedResourceOptions.listResources) {
3356
3343
  serverInstance.setRequestHandler(types_js.ListResourcesRequestSchema, async (_request, extra) => {
3357
- if (this.definedResources) {
3358
- return { resources: this.definedResources };
3359
- } else {
3360
- try {
3361
- const resources = await capturedResourceOptions.listResources({ extra });
3362
- this.definedResources = resources;
3363
- this.logger.debug("Fetched and cached resources", { count: this.definedResources.length });
3364
- return { resources: this.definedResources };
3365
- } catch (error) {
3366
- this.logger.error("Error fetching resources", { error });
3367
- throw error;
3368
- }
3344
+ try {
3345
+ const resources = await capturedResourceOptions.listResources({ extra });
3346
+ this.logger.debug("Fetched resources", { count: resources.length });
3347
+ return { resources };
3348
+ } catch (error) {
3349
+ this.logger.error("Error fetching resources", { error });
3350
+ throw error;
3369
3351
  }
3370
3352
  });
3371
3353
  }
@@ -3374,12 +3356,9 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3374
3356
  const startTime = Date.now();
3375
3357
  const uri = request.params.uri;
3376
3358
  this.logger.debug("Handling ReadResource request", { uri });
3377
- if (!this.definedResources) {
3378
- const resources = await this.resourceOptions?.listResources?.({ extra });
3379
- if (!resources) throw new Error("Failed to load resources");
3380
- this.definedResources = resources;
3381
- }
3382
- const resource = this.definedResources?.find((r) => r.uri === uri);
3359
+ const resources = await capturedResourceOptions.listResources?.({ extra });
3360
+ if (!resources) throw new Error("Failed to load resources");
3361
+ const resource = resources.find((r) => r.uri === uri);
3383
3362
  if (!resource) {
3384
3363
  this.logger.warn("Unknown resource URI requested", { uri });
3385
3364
  throw new Error(`Resource not found: ${uri}`);
@@ -3419,18 +3398,13 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3419
3398
  }
3420
3399
  if (capturedResourceOptions.resourceTemplates) {
3421
3400
  serverInstance.setRequestHandler(types_js.ListResourceTemplatesRequestSchema, async (_request, extra) => {
3422
- if (this.definedResourceTemplates) {
3423
- return { resourceTemplates: this.definedResourceTemplates };
3424
- } else {
3425
- try {
3426
- const templates = await capturedResourceOptions.resourceTemplates({ extra });
3427
- this.definedResourceTemplates = templates;
3428
- this.logger.debug("Fetched and cached resource templates", { count: this.definedResourceTemplates.length });
3429
- return { resourceTemplates: this.definedResourceTemplates };
3430
- } catch (error) {
3431
- this.logger.error("Error fetching resource templates via resourceTemplates():", { error });
3432
- throw error;
3433
- }
3401
+ try {
3402
+ const templates = await capturedResourceOptions.resourceTemplates({ extra });
3403
+ this.logger.debug("Fetched resource templates", { count: templates.length });
3404
+ return { resourceTemplates: templates };
3405
+ } catch (error) {
3406
+ this.logger.error("Error fetching resource templates via resourceTemplates():", { error });
3407
+ throw error;
3434
3408
  }
3435
3409
  });
3436
3410
  }
@@ -4754,11 +4728,7 @@ Provided arguments: ${JSON.stringify(args, null, 2)}`,
4754
4728
  return { resources: [] };
4755
4729
  }
4756
4730
  const extra = {};
4757
- if (this.definedResources) {
4758
- return { resources: this.definedResources };
4759
- }
4760
4731
  const resources = await this.resourceOptions.listResources({ extra });
4761
- this.definedResources = resources;
4762
4732
  return { resources };
4763
4733
  }
4764
4734
  };