@mastra/mcp 1.9.1 → 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 +13 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +32 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -62
- package/dist/index.js.map +1 -1
- package/dist/server/resourceActions.d.ts +3 -6
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +1 -2
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
3
16
|
## 1.9.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
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
|
|
2734
|
-
*
|
|
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.
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
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
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
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
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
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
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
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
|
};
|