@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/dist/index.js
CHANGED
|
@@ -2664,8 +2664,6 @@ var ServerResourceActions = class {
|
|
|
2664
2664
|
getSubscriptions;
|
|
2665
2665
|
getLogger;
|
|
2666
2666
|
getSdkServer;
|
|
2667
|
-
clearDefinedResources;
|
|
2668
|
-
clearDefinedResourceTemplates;
|
|
2669
2667
|
/**
|
|
2670
2668
|
* @internal
|
|
2671
2669
|
*/
|
|
@@ -2673,8 +2671,6 @@ var ServerResourceActions = class {
|
|
|
2673
2671
|
this.getSubscriptions = dependencies.getSubscriptions;
|
|
2674
2672
|
this.getLogger = dependencies.getLogger;
|
|
2675
2673
|
this.getSdkServer = dependencies.getSdkServer;
|
|
2676
|
-
this.clearDefinedResources = dependencies.clearDefinedResources;
|
|
2677
|
-
this.clearDefinedResourceTemplates = dependencies.clearDefinedResourceTemplates;
|
|
2678
2674
|
}
|
|
2679
2675
|
/**
|
|
2680
2676
|
* Notifies subscribed clients that a specific resource has been updated.
|
|
@@ -2723,8 +2719,9 @@ var ServerResourceActions = class {
|
|
|
2723
2719
|
/**
|
|
2724
2720
|
* Notifies clients that the overall list of available resources has changed.
|
|
2725
2721
|
*
|
|
2726
|
-
* This
|
|
2727
|
-
*
|
|
2722
|
+
* This sends a `notifications/resources/list_changed` message to all clients, prompting
|
|
2723
|
+
* them to re-fetch the resource list. Resource lists and templates are always evaluated
|
|
2724
|
+
* per request, so there is no server-side cache to clear.
|
|
2728
2725
|
*
|
|
2729
2726
|
* @throws {MastraError} If sending the notification fails
|
|
2730
2727
|
*
|
|
@@ -2735,11 +2732,7 @@ var ServerResourceActions = class {
|
|
|
2735
2732
|
* ```
|
|
2736
2733
|
*/
|
|
2737
2734
|
async notifyListChanged() {
|
|
2738
|
-
this.getLogger().info(
|
|
2739
|
-
"Resource list change externally notified. Clearing definedResources and sending notification."
|
|
2740
|
-
);
|
|
2741
|
-
this.clearDefinedResources();
|
|
2742
|
-
this.clearDefinedResourceTemplates();
|
|
2735
|
+
this.getLogger().info("Resource list change externally notified. Sending notification.");
|
|
2743
2736
|
try {
|
|
2744
2737
|
await this.getSdkServer().sendResourceListChanged();
|
|
2745
2738
|
} catch (error) {
|
|
@@ -2770,9 +2763,11 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2770
2763
|
streamableHTTPTransports = /* @__PURE__ */ new Map();
|
|
2771
2764
|
// Track server instances for each HTTP session
|
|
2772
2765
|
httpServerInstances = /* @__PURE__ */ new Map();
|
|
2773
|
-
definedResources;
|
|
2774
|
-
definedResourceTemplates;
|
|
2775
2766
|
resourceOptions;
|
|
2767
|
+
// Whether any UI (`ui://`) app resources are configured. Captured at construction so
|
|
2768
|
+
// per-request server instances can advertise the MCP Apps extension without relying on
|
|
2769
|
+
// a shared, per-caller resource cache.
|
|
2770
|
+
hasUiResources = false;
|
|
2776
2771
|
definedPrompts;
|
|
2777
2772
|
promptOptions;
|
|
2778
2773
|
jsonSchemaValidator;
|
|
@@ -2913,6 +2908,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2913
2908
|
constructor(opts) {
|
|
2914
2909
|
super(opts);
|
|
2915
2910
|
this.resourceOptions = this.mergeAppResources(opts.resources, opts.appResources);
|
|
2911
|
+
this.hasUiResources = !!opts.appResources && Object.keys(opts.appResources).length > 0;
|
|
2916
2912
|
this.promptOptions = opts.prompts;
|
|
2917
2913
|
this.jsonSchemaValidator = opts.jsonSchemaValidator;
|
|
2918
2914
|
this.mapAuthInfoToUser = opts.mapAuthInfoToUser;
|
|
@@ -2958,13 +2954,7 @@ var MCPServer = class extends MCPServerBase {
|
|
|
2958
2954
|
this.resources = new ServerResourceActions({
|
|
2959
2955
|
getSubscriptions: () => this.subscriptions,
|
|
2960
2956
|
getLogger: () => this.logger,
|
|
2961
|
-
getSdkServer: () => this.server
|
|
2962
|
-
clearDefinedResources: () => {
|
|
2963
|
-
this.definedResources = void 0;
|
|
2964
|
-
},
|
|
2965
|
-
clearDefinedResourceTemplates: () => {
|
|
2966
|
-
this.definedResourceTemplates = void 0;
|
|
2967
|
-
}
|
|
2957
|
+
getSdkServer: () => this.server
|
|
2968
2958
|
});
|
|
2969
2959
|
this.prompts = new ServerPromptActions({
|
|
2970
2960
|
getLogger: () => this.logger,
|
|
@@ -3123,14 +3113,11 @@ var MCPServer = class extends MCPServerBase {
|
|
|
3123
3113
|
const hasUiTools = Object.values(this.convertedTools).some(
|
|
3124
3114
|
(tool) => tool.mcp?._meta?.ui?.resourceUri
|
|
3125
3115
|
);
|
|
3126
|
-
if (hasUiTools || this.
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
"io.modelcontextprotocol/ui": {}
|
|
3132
|
-
};
|
|
3133
|
-
}
|
|
3116
|
+
if (hasUiTools || this.hasUiResources) {
|
|
3117
|
+
capabilities.extensions = {
|
|
3118
|
+
...capabilities.extensions,
|
|
3119
|
+
"io.modelcontextprotocol/ui": {}
|
|
3120
|
+
};
|
|
3134
3121
|
}
|
|
3135
3122
|
const serverInstance = new Server(
|
|
3136
3123
|
{
|
|
@@ -3347,18 +3334,13 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
3347
3334
|
if (!capturedResourceOptions) return;
|
|
3348
3335
|
if (capturedResourceOptions.listResources) {
|
|
3349
3336
|
serverInstance.setRequestHandler(ListResourcesRequestSchema, async (_request, extra) => {
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
return { resources: this.definedResources };
|
|
3358
|
-
} catch (error) {
|
|
3359
|
-
this.logger.error("Error fetching resources", { error });
|
|
3360
|
-
throw error;
|
|
3361
|
-
}
|
|
3337
|
+
try {
|
|
3338
|
+
const resources = await capturedResourceOptions.listResources({ extra });
|
|
3339
|
+
this.logger.debug("Fetched resources", { count: resources.length });
|
|
3340
|
+
return { resources };
|
|
3341
|
+
} catch (error) {
|
|
3342
|
+
this.logger.error("Error fetching resources", { error });
|
|
3343
|
+
throw error;
|
|
3362
3344
|
}
|
|
3363
3345
|
});
|
|
3364
3346
|
}
|
|
@@ -3367,12 +3349,9 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
3367
3349
|
const startTime = Date.now();
|
|
3368
3350
|
const uri = request.params.uri;
|
|
3369
3351
|
this.logger.debug("Handling ReadResource request", { uri });
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
this.definedResources = resources;
|
|
3374
|
-
}
|
|
3375
|
-
const resource = this.definedResources?.find((r) => r.uri === uri);
|
|
3352
|
+
const resources = await capturedResourceOptions.listResources?.({ extra });
|
|
3353
|
+
if (!resources) throw new Error("Failed to load resources");
|
|
3354
|
+
const resource = resources.find((r) => r.uri === uri);
|
|
3376
3355
|
if (!resource) {
|
|
3377
3356
|
this.logger.warn("Unknown resource URI requested", { uri });
|
|
3378
3357
|
throw new Error(`Resource not found: ${uri}`);
|
|
@@ -3412,18 +3391,13 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
3412
3391
|
}
|
|
3413
3392
|
if (capturedResourceOptions.resourceTemplates) {
|
|
3414
3393
|
serverInstance.setRequestHandler(ListResourceTemplatesRequestSchema, async (_request, extra) => {
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
return { resourceTemplates: this.definedResourceTemplates };
|
|
3423
|
-
} catch (error) {
|
|
3424
|
-
this.logger.error("Error fetching resource templates via resourceTemplates():", { error });
|
|
3425
|
-
throw error;
|
|
3426
|
-
}
|
|
3394
|
+
try {
|
|
3395
|
+
const templates = await capturedResourceOptions.resourceTemplates({ extra });
|
|
3396
|
+
this.logger.debug("Fetched resource templates", { count: templates.length });
|
|
3397
|
+
return { resourceTemplates: templates };
|
|
3398
|
+
} catch (error) {
|
|
3399
|
+
this.logger.error("Error fetching resource templates via resourceTemplates():", { error });
|
|
3400
|
+
throw error;
|
|
3427
3401
|
}
|
|
3428
3402
|
});
|
|
3429
3403
|
}
|
|
@@ -4747,11 +4721,7 @@ Provided arguments: ${JSON.stringify(args, null, 2)}`,
|
|
|
4747
4721
|
return { resources: [] };
|
|
4748
4722
|
}
|
|
4749
4723
|
const extra = {};
|
|
4750
|
-
if (this.definedResources) {
|
|
4751
|
-
return { resources: this.definedResources };
|
|
4752
|
-
}
|
|
4753
4724
|
const resources = await this.resourceOptions.listResources({ extra });
|
|
4754
|
-
this.definedResources = resources;
|
|
4755
4725
|
return { resources };
|
|
4756
4726
|
}
|
|
4757
4727
|
};
|