@mastra/mcp 1.13.1-alpha.0 → 1.14.0-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 +95 -0
- package/dist/client/client.d.ts +6 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +36 -0
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-mcp-mcp-apps.md +3 -3
- package/dist/docs/references/docs-mcp-overview.md +6 -10
- package/dist/docs/references/reference-tools-mcp-client.md +22 -0
- package/dist/docs/references/reference-tools-mcp-server.md +161 -4
- package/dist/index.cjs +490 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +491 -123
- package/dist/index.js.map +1 -1
- package/dist/server/notificationBroadcast.d.ts +24 -0
- package/dist/server/notificationBroadcast.d.ts.map +1 -0
- package/dist/server/promptActions.d.ts +8 -3
- package/dist/server/promptActions.d.ts.map +1 -1
- package/dist/server/resourceActions.d.ts +14 -8
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +100 -3
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/toolActions.d.ts +77 -0
- package/dist/server/toolActions.d.ts.map +1 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 1.14.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add `serverlessStreaming` option to `MCPServer.startHTTP()` for request-scoped progress notifications in serverless mode. ([#17927](https://github.com/mastra-ai/mastra/pull/17927))
|
|
8
|
+
|
|
9
|
+
Serverless mode (`serverless: true`) buffers each request into a single JSON response, which silently drops any `notifications/progress` a tool emits via `extra.sendNotification()`. Setting `options: { serverless: true, serverlessStreaming: true }` now handles the request with request-scoped SSE streaming (`enableJsonResponse: false` on the transient transport), so progress notifications reach the MCP client's `onprogress` handler before the final result. An explicit `enableJsonResponse` is also honored.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
await server.startHTTP({
|
|
13
|
+
url,
|
|
14
|
+
httpPath: '/mcp',
|
|
15
|
+
req,
|
|
16
|
+
res,
|
|
17
|
+
options: { serverless: true, serverlessStreaming: true },
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This is still fully stateless — no `mcp-session-id` is required or persisted — and the default behavior is unchanged (`enableJsonResponse: true`), so existing serverless JSON-response users are unaffected. It enables only notifications scoped to the current request, such as progress; elicitation, resource subscriptions, and out-of-request resource/list-change notifications still require session state.
|
|
22
|
+
|
|
23
|
+
- Fixed MCP server notifications (resource updates, resource/prompt list changes) not reaching clients connected over streamable HTTP. Notifications are now broadcast to every connected session across all transports. ([#19193](https://github.com/mastra-ai/mastra/pull/19193))
|
|
24
|
+
|
|
25
|
+
Fixed resource subscriptions being shared globally across all clients. Subscriptions are now tracked per session, so `resources.notifyUpdated()` only notifies sessions that subscribed to the resource URI, and one client unsubscribing no longer removes another client's subscription. Clients that relied on receiving `notifications/resources/updated` without subscribing must now call `resources/subscribe` first.
|
|
26
|
+
|
|
27
|
+
Added support for the remaining MCP notification features:
|
|
28
|
+
|
|
29
|
+
**Dynamic tools and tools/list_changed**
|
|
30
|
+
|
|
31
|
+
Servers can now add and remove tools at runtime and notify clients via `notifications/tools/list_changed`:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Server: manage tools at runtime
|
|
35
|
+
await server.toolActions.add({ myNewTool });
|
|
36
|
+
await server.toolActions.remove(['myNewTool']);
|
|
37
|
+
await server.toolActions.notifyListChanged();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
When the server is registered with a Mastra instance, dynamic add/remove also keeps the Mastra instance's tool registry in sync.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Client: react to tool list changes
|
|
44
|
+
await mcp.tools.onListChanged('myServer', async () => {
|
|
45
|
+
const tools = await mcp.listTools();
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Server-side log messages**
|
|
50
|
+
|
|
51
|
+
Servers can now emit `notifications/message` log notifications. The minimum level a client sets via `logging/setLevel` is honored per session:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// Broadcast to all connected clients
|
|
55
|
+
await server.sendLoggingMessage({ level: 'info', data: { message: 'Sync completed' } });
|
|
56
|
+
|
|
57
|
+
// From inside a tool, send to the calling client
|
|
58
|
+
await context.mcp.log('debug', 'Fetching weather', { location });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Progress notifications from tools**
|
|
62
|
+
|
|
63
|
+
Tools can now report progress to the calling client:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
await context.mcp.progress({ progress: 1, total: 3, message: 'step 1' });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Patch Changes
|
|
70
|
+
|
|
71
|
+
- Fixed MCP clients advertising elicitation support before a handler is registered. ([#19192](https://github.com/mastra-ai/mastra/pull/19192))
|
|
72
|
+
|
|
73
|
+
- Fixed `MCPServer` dropping a resource's `_meta` from `resources/read` results. The read handler rebuilt each content item with only `{ uri, mimeType, text | blob }`, so `appResources` (MCP Apps / SEP-1865) metadata attached during `resources/list` as `_meta: { ui: meta }` never reached the client. Hosts read the UI CSP from `contents[]._meta.ui.csp`, so `connectDomains` was silently ignored and widget `fetch`/XHR calls failed with `Failed to fetch`. The resource's `_meta` is now preserved on the read contents. ([#19163](https://github.com/mastra-ai/mastra/pull/19163))
|
|
74
|
+
|
|
75
|
+
- Updated dependencies [[`a5c6337`](https://github.com/mastra-ai/mastra/commit/a5c6337d23c7686c81a32ce62f550f610543a240), [`8b97958`](https://github.com/mastra-ai/mastra/commit/8b979589f9aa59ba67cac565949475f2ffeb4ac3), [`8410541`](https://github.com/mastra-ai/mastra/commit/84105412c60ecd3bb33a9838146f59c4b588228f), [`01b338c`](https://github.com/mastra-ai/mastra/commit/01b338c56271f0219606710e3e8b26dee27ac6c2), [`8b7361d`](https://github.com/mastra-ai/mastra/commit/8b7361d35de68b80d05d30a74e0c69e7218fd612), [`c43f3a9`](https://github.com/mastra-ai/mastra/commit/c43f3a9d1efde99b38789364ba4d0ba670f430e3)]:
|
|
76
|
+
- @mastra/core@1.51.0-alpha.4
|
|
77
|
+
|
|
78
|
+
## 1.13.1
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Fixed MCP client tools missing output schemas in tool listings. Fixes #18850. ([#18854](https://github.com/mastra-ai/mastra/pull/18854))
|
|
83
|
+
|
|
84
|
+
MCP tools that declare an `outputSchema` now expose that schema on the Mastra tool wrapper, so Studio and other consumers can document expected tool outputs.
|
|
85
|
+
|
|
86
|
+
Mastra does not re-validate MCP tool results. The MCP SDK still validates `structuredContent` via AJV. This keeps full `CallToolResult` envelopes and extra fields intact while making output shapes visible again.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const tools = await mcp.listTools();
|
|
90
|
+
const outputSchema = tools['weather_getForecast'].outputSchema?.['~standard'].jsonSchema.output({
|
|
91
|
+
target: 'draft-07',
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- Updated dependencies [[`b291760`](https://github.com/mastra-ai/mastra/commit/b291760df9d6c7e4fc72606c8f0a4af2cf6e946c), [`3ffb8b7`](https://github.com/mastra-ai/mastra/commit/3ffb8b720e90f5e6977129ec1f6707d43c2bebe0), [`6ef59fe`](https://github.com/mastra-ai/mastra/commit/6ef59fef1da52ed8da5fbb2a892c71cf4fb6c739), [`4039488`](https://github.com/mastra-ai/mastra/commit/403948898af7293198d9e8b3e7fb47f623c78b94), [`29b7ea6`](https://github.com/mastra-ai/mastra/commit/29b7ea64e72b5523d5bdcbd34ee03d2b854d54e1), [`b2c9d70`](https://github.com/mastra-ai/mastra/commit/b2c9d70757207fb01a9069549e69b6f0d73a6636), [`a51c63d`](https://github.com/mastra-ai/mastra/commit/a51c63d8ee639e4daeba2a0be093efa6a1b5e52f), [`252f63d`](https://github.com/mastra-ai/mastra/commit/252f63d8fec723955adb2202be2f01a75ad0e69c), [`5ea76a7`](https://github.com/mastra-ai/mastra/commit/5ea76a723d966c72da9aa3ab30ae20276e049765), [`6445560`](https://github.com/mastra-ai/mastra/commit/6445560327045d20b239585fc63fed72e9ce36ec), [`e2b9f33`](https://github.com/mastra-ai/mastra/commit/e2b9f33456fd638eca555f9466c6519d8d049666), [`10959d5`](https://github.com/mastra-ai/mastra/commit/10959d509d824f682d40ff96e05ee044aec3b0e5), [`c547a77`](https://github.com/mastra-ai/mastra/commit/c547a7729bdf64dfc2df29c965046c0712a18f10), [`a0085fa`](https://github.com/mastra-ai/mastra/commit/a0085fa0934e52c37c8c8b3d75a6bb5cd199af36), [`a2ba369`](https://github.com/mastra-ai/mastra/commit/a2ba369e796dfab610f41c6875965b488272fa55), [`ffc3c17`](https://github.com/mastra-ai/mastra/commit/ffc3c17274ea17c11aa6f73d3140649cd7fc8abc), [`81542c1`](https://github.com/mastra-ai/mastra/commit/81542c1835c35bc32f2ce4fa9136ee11993cd299), [`3908e53`](https://github.com/mastra-ai/mastra/commit/3908e53ce04bbea04f5e0c097d7aa298c35fabee), [`cb24ce7`](https://github.com/mastra-ai/mastra/commit/cb24ce76bd16ca88eb6a963f6277f8780e703029), [`02705fd`](https://github.com/mastra-ai/mastra/commit/02705fd2f5a9062210d64ea061adeeb10dc9452e), [`ae51e81`](https://github.com/mastra-ai/mastra/commit/ae51e818825582d42500338dfc1929a082eff0ba), [`6f304ef`](https://github.com/mastra-ai/mastra/commit/6f304ef319e99725e884bdb8d3193c001b6e5964), [`5f9858f`](https://github.com/mastra-ai/mastra/commit/5f9858f791f1137ca7d52d23559fb4568f7a9026)]:
|
|
96
|
+
- @mastra/core@1.50.0
|
|
97
|
+
|
|
3
98
|
## 1.13.1-alpha.0
|
|
4
99
|
|
|
5
100
|
### Patch Changes
|
package/dist/client/client.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class InternalMastraMCPClient extends MastraBase {
|
|
|
31
31
|
private sigHupHandler?;
|
|
32
32
|
private serverInstructions?;
|
|
33
33
|
private _roots;
|
|
34
|
+
private hasElicitationCapability;
|
|
34
35
|
private readonly requireToolApproval;
|
|
35
36
|
private readonly onToolError;
|
|
36
37
|
/** Provides access to resource operations (list, read, subscribe, etc.) */
|
|
@@ -164,6 +165,11 @@ export declare class InternalMastraMCPClient extends MastraBase {
|
|
|
164
165
|
* Use this to refresh cached prompt lists in the client/UI if needed.
|
|
165
166
|
*/
|
|
166
167
|
setPromptListChangedNotificationHandler(handler: () => void): void;
|
|
168
|
+
/**
|
|
169
|
+
* Register a handler to be called when the tool list changes on the server.
|
|
170
|
+
* Use this to re-fetch tools via `tools()` when notified.
|
|
171
|
+
*/
|
|
172
|
+
setToolListChangedNotificationHandler(handler: () => void): void;
|
|
167
173
|
setResourceUpdatedNotificationHandler(handler: (params: any) => void): void;
|
|
168
174
|
setResourceListChangedNotificationHandler(handler: () => void): void;
|
|
169
175
|
setElicitationRequestHandler(handler: ElicitationHandler): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAShE,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAE3B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAEA,OAAO,K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CAAC,CAAC;IA+LhE,OAAO,CAAC,mBAAmB;CAQ5B"}
|
|
@@ -499,6 +499,38 @@ export declare class MCPClient extends MastraBase {
|
|
|
499
499
|
*/
|
|
500
500
|
onListChanged: (serverName: string, handler: () => void) => Promise<void>;
|
|
501
501
|
};
|
|
502
|
+
/**
|
|
503
|
+
* Provides access to tool-related notification operations across all configured servers.
|
|
504
|
+
*
|
|
505
|
+
* To fetch tools, use `listTools()` or `listToolsets()`.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* // React to tool list changes on a server
|
|
510
|
+
* await mcp.tools.onListChanged('weatherServer', async () => {
|
|
511
|
+
* console.log('Tool list changed, re-fetching...');
|
|
512
|
+
* const tools = await mcp.listTools();
|
|
513
|
+
* });
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
get tools(): {
|
|
517
|
+
/**
|
|
518
|
+
* Sets a notification handler for when the tool list changes on a server.
|
|
519
|
+
*
|
|
520
|
+
* @param serverName - Name of the server to monitor
|
|
521
|
+
* @param handler - Callback function invoked when tools are added/removed/modified
|
|
522
|
+
* @returns Promise resolving when handler is registered
|
|
523
|
+
* @throws {MastraError} If setting up the handler fails
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```typescript
|
|
527
|
+
* await mcp.tools.onListChanged('weatherServer', async () => {
|
|
528
|
+
* const tools = await mcp.listTools();
|
|
529
|
+
* });
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
onListChanged: (serverName: string, handler: () => void) => Promise<void>;
|
|
533
|
+
};
|
|
502
534
|
private addToInstanceCache;
|
|
503
535
|
private makeId;
|
|
504
536
|
/**
|
|
@@ -679,8 +711,12 @@ export declare class MCPClient extends MastraBase {
|
|
|
679
711
|
* @returns The stderr stream, or null
|
|
680
712
|
*/
|
|
681
713
|
getServerStderr(serverName: string): Stream | null;
|
|
714
|
+
private getServerConfig;
|
|
715
|
+
private getOrCreateClient;
|
|
682
716
|
private getConnectedClient;
|
|
717
|
+
private handleConnectError;
|
|
683
718
|
private getConnectedClientForServer;
|
|
719
|
+
private getClientForServer;
|
|
684
720
|
private getToolsForServer;
|
|
685
721
|
}
|
|
686
722
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAO1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wHAAwH;IACxH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IACnD,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,OAAO,CAAC,aAAa,CAAiD;IACtE,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,iBAAiB,CAA8B;IAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;gBACS,IAAI,EAAE,gBAAgB;IA2ClC;;;;;;;;;;;;;;;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AM,CAAC,CAAC;KAChC,CAAC;IAgCF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAK9F;;;;;;;;;;;;;;;;OAgBG;IACU,sBAAsB,IAAI,OAAO,CAAC;QAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACnE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IAgCF;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAU1D;;;;;;;;;;;;;;OAcG;IACH,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQvC;IAED;;;;;;;;OAQG;IACI,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMzD,OAAO,CAAC,eAAe;YAQT,iBAAiB;YAiCjB,kBAAkB;IAchC,OAAO,CAAC,kBAAkB;YAqBZ,2BAA2B;YAI3B,kBAAkB;YAIlB,iBAAiB;CAuBhC"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -81,7 +81,7 @@ calculatorTool._meta = {
|
|
|
81
81
|
}
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Visit [MCPServer reference](https://mastra.ai/reference/tools/mcp-server) for the full `appResources` configuration.
|
|
85
85
|
|
|
86
86
|
## Connecting MCP Apps to agents
|
|
87
87
|
|
|
@@ -249,7 +249,7 @@ Establishes the connection to the host. Call this after registering all event ha
|
|
|
249
249
|
await app.connect()
|
|
250
250
|
```
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
See the [`App` class API reference](https://apps.extensions.modelcontextprotocol.io/api/classes/app.App.html) for the full list of methods, callbacks, and lifecycle hooks.
|
|
253
253
|
|
|
254
254
|
## Using external MCP servers with apps
|
|
255
255
|
|
|
@@ -284,7 +284,7 @@ export const mastra = new Mastra({
|
|
|
284
284
|
})
|
|
285
285
|
```
|
|
286
286
|
|
|
287
|
-
|
|
287
|
+
Visit [MCPClient reference](https://mastra.ai/reference/tools/mcp-client) for more details on proxying external servers.
|
|
288
288
|
|
|
289
289
|
## Sandbox security
|
|
290
290
|
|
|
@@ -62,7 +62,7 @@ export const testMcpClient = new MCPClient({
|
|
|
62
62
|
})
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
Visit [MCPClient](https://mastra.ai/reference/tools/mcp-client) for a full list of configuration options.
|
|
66
66
|
|
|
67
67
|
> **Authentication:** For connecting to OAuth-protected MCP servers, see the [OAuth Authentication](https://mastra.ai/reference/tools/mcp-client) section.
|
|
68
68
|
|
|
@@ -89,7 +89,7 @@ export const testAgent = new Agent({
|
|
|
89
89
|
})
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
Visit [Agent Class](https://mastra.ai/reference/agents/agent) for a full list of configuration options.
|
|
93
93
|
|
|
94
94
|
## Tool approval
|
|
95
95
|
|
|
@@ -129,7 +129,7 @@ export const testMcpServer = new MCPServer({
|
|
|
129
129
|
})
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
Visit [MCPServer](https://mastra.ai/reference/tools/mcp-server) for a full list of configuration options.
|
|
133
133
|
|
|
134
134
|
> **Authentication:** To protect your MCP server with OAuth, see the [OAuth Protection](https://mastra.ai/reference/tools/mcp-server) section.
|
|
135
135
|
|
|
@@ -160,9 +160,7 @@ export const mastra = new Mastra({
|
|
|
160
160
|
|
|
161
161
|
### Static tools
|
|
162
162
|
|
|
163
|
-
Use the `.listTools()` method to fetch tools from all configured MCP servers. This is suitable when configuration (such as API keys) is static and consistent across users or requests. Call it once and pass the result to the `tools` property when defining your agent.
|
|
164
|
-
|
|
165
|
-
> **Info:** Visit [listTools()](https://mastra.ai/reference/tools/mcp-client) for more information.
|
|
163
|
+
Use the `.listTools()` method to fetch tools from all configured MCP servers. This is suitable when configuration (such as API keys) is static and consistent across users or requests. Call it once and pass the result to the `tools` property when defining your agent. Visit [listTools()](https://mastra.ai/reference/tools/mcp-client) for more information.
|
|
166
164
|
|
|
167
165
|
```typescript
|
|
168
166
|
import { Agent } from '@mastra/core/agent'
|
|
@@ -211,7 +209,7 @@ async function handleRequest(userPrompt: string, userApiKey: string) {
|
|
|
211
209
|
}
|
|
212
210
|
```
|
|
213
211
|
|
|
214
|
-
|
|
212
|
+
Visit [listToolsets()](https://mastra.ai/reference/tools/mcp-client) for more information.
|
|
215
213
|
|
|
216
214
|
## Connecting to an MCP registry
|
|
217
215
|
|
|
@@ -412,9 +410,7 @@ As an alternative to MCP, Ampersand's AI SDK also has an adapter for Mastra, so
|
|
|
412
410
|
|
|
413
411
|
## MCP Apps
|
|
414
412
|
|
|
415
|
-
MCP servers can serve interactive HTML UIs via the MCP Apps extension. Tools with associated `ui://` resources render sandboxed iframes in Studio — both on tool detail pages and inline in agent chat. The app iframe can call server tools and inject messages into the conversation.
|
|
416
|
-
|
|
417
|
-
> **Note:** Visit [MCP Apps](https://mastra.ai/docs/mcp/mcp-apps) for setup instructions and the app bridge API.
|
|
413
|
+
MCP servers can serve interactive HTML UIs via the MCP Apps extension. Tools with associated `ui://` resources render sandboxed iframes in Studio — both on tool detail pages and inline in agent chat. The app iframe can call server tools and inject messages into the conversation. Visit [MCP Apps](https://mastra.ai/docs/mcp/mcp-apps) for setup instructions and the app bridge API.
|
|
418
414
|
|
|
419
415
|
## Related
|
|
420
416
|
|
|
@@ -601,6 +601,28 @@ mcpClient.prompts.onListChanged('myWeatherServer', () => {
|
|
|
601
601
|
})
|
|
602
602
|
```
|
|
603
603
|
|
|
604
|
+
### `tools` Property
|
|
605
|
+
|
|
606
|
+
The `MCPClient` instance has a `tools` property for subscribing to tool list change notifications. To fetch tools, use `listTools()` or `listToolsets()`.
|
|
607
|
+
|
|
608
|
+
#### `tools.onListChanged(serverName: string, handler: () => void)`
|
|
609
|
+
|
|
610
|
+
Sets a notification handler that will be called when the list of available tools changes on a specific server (for example, when the server adds or removes tools at runtime).
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
async onListChanged(serverName: string, handler: () => void): Promise<void>
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
Example:
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
await mcpClient.tools.onListChanged('myWeatherServer', async () => {
|
|
620
|
+
console.log('Tool list changed on myWeatherServer.')
|
|
621
|
+
// You should re-fetch the tools
|
|
622
|
+
// const tools = await mcpClient.listTools();
|
|
623
|
+
})
|
|
624
|
+
```
|
|
625
|
+
|
|
604
626
|
### `progress` Property
|
|
605
627
|
|
|
606
628
|
The `MCPClient` instance has a `progress` property for subscribing to progress notifications emitted by MCP servers while tools execute.
|
|
@@ -399,12 +399,31 @@ serve(async req => {
|
|
|
399
399
|
>
|
|
400
400
|
> The serverless mode disables session management and creates fresh server instances per request, which is necessary for stateless environments where memory doesn't persist between invocations.
|
|
401
401
|
>
|
|
402
|
-
>
|
|
402
|
+
> By default, serverless mode buffers each request into a single JSON response, so `notifications/progress` sent by a tool never reach the client. Set `serverlessStreaming: true` to handle the request with request-scoped SSE streaming instead, which delivers progress notifications before the final result:
|
|
403
|
+
>
|
|
404
|
+
> ```typescript
|
|
405
|
+
> await server.startHTTP({
|
|
406
|
+
> url,
|
|
407
|
+
> httpPath: '/mcp',
|
|
408
|
+
> req: nodeReq,
|
|
409
|
+
> res: nodeRes,
|
|
410
|
+
> options: {
|
|
411
|
+
> serverless: true,
|
|
412
|
+
> serverlessStreaming: true, // ← Stream request-scoped notifications/progress
|
|
413
|
+
> },
|
|
414
|
+
> })
|
|
415
|
+
> ```
|
|
416
|
+
>
|
|
417
|
+
> This is still stateless: no `mcp-session-id` is required or persisted. It only enables notifications scoped to the current request (such as progress). The session-dependent features below remain unavailable.
|
|
418
|
+
>
|
|
419
|
+
> **Note:** The following MCP features require session state or persistent connections and **won't work** in serverless mode (including with `serverlessStreaming: true`):
|
|
403
420
|
>
|
|
404
421
|
> - **Elicitation** - Interactive user input requests during tool execution require session management to route responses back to the correct client
|
|
405
422
|
> - **Resource subscriptions** - `resources/subscribe` and `resources/unsubscribe` need persistent connections to maintain subscription state
|
|
406
423
|
> - **Resource update notifications** - `resources.notifyUpdated()` requires active subscriptions and persistent connections to notify clients
|
|
407
424
|
> - **Prompt list change notifications** - `prompts.notifyListChanged()` requires persistent connections to push updates to clients
|
|
425
|
+
> - **Tool list change notifications** - `toolActions.notifyListChanged()` requires persistent connections to push updates to clients
|
|
426
|
+
> - **Server log notifications** - `sendLoggingMessage()` requires persistent connections to push log messages to clients
|
|
408
427
|
>
|
|
409
428
|
> These features work normally in long-lived server environments (Node.js servers, Docker containers, etc.).
|
|
410
429
|
|
|
@@ -424,6 +443,8 @@ The `StreamableHTTPServerTransportOptions` object allows you to customize the be
|
|
|
424
443
|
|
|
425
444
|
**serverless** (`boolean`): If true, runs in stateless mode without session management. Each request is handled independently with a fresh server instance. Essential for serverless environments (Cloudflare Workers, Supabase Edge Functions, Vercel Edge, etc.) where sessions cannot persist between invocations. Defaults to false.
|
|
426
445
|
|
|
446
|
+
**serverlessStreaming** (`boolean`): If true, serverless requests use request-scoped SSE streaming instead of a buffered JSON response, allowing in-request notifications/progress to reach the client before the final result. Only takes effect together with serverless: true. Defaults to false (buffered JSON responses), which preserves backward-compatible behavior. This enables only request-scoped notifications such as progress; elicitation, subscriptions, and out-of-request notifications still require session state.
|
|
447
|
+
|
|
427
448
|
**sessionIdGenerator** (`(() => string) | undefined`): A function that generates a unique session ID. This should be a cryptographically secure, globally unique string. Return undefined to disable session management.
|
|
428
449
|
|
|
429
450
|
**onsessioninitialized** (`(sessionId: string) => void`): A callback that is invoked when a new session is initialized. This is useful for tracking active MCP sessions.
|
|
@@ -776,6 +797,144 @@ await serverWithPrompts.prompts.notifyListChanged()
|
|
|
776
797
|
- Handle errors with informative messages.
|
|
777
798
|
- Document argument expectations and available versions.
|
|
778
799
|
|
|
800
|
+
## Dynamic tool management
|
|
801
|
+
|
|
802
|
+
Tools are usually provided when constructing the `MCPServer`, but you can also add or remove tools while the server is running. The server exposes these operations through the `toolActions` property. When the tool list changes, connected clients receive a `notifications/tools/list_changed` message prompting them to re-fetch the tool list.
|
|
803
|
+
|
|
804
|
+
The property is named `toolActions` because `tools()` is the method that returns the registered tool registry.
|
|
805
|
+
|
|
806
|
+
### `toolActions.add(tools)`
|
|
807
|
+
|
|
808
|
+
Registers new tools on the running server and notifies connected clients. Tools are keyed by their record key, the same as tools passed to the constructor. Adding a tool under an existing key replaces it.
|
|
809
|
+
|
|
810
|
+
```typescript
|
|
811
|
+
async server.toolActions.add(tools: ToolsInput): Promise<void>
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
Example:
|
|
815
|
+
|
|
816
|
+
```typescript
|
|
817
|
+
import { createTool } from '@mastra/core/tools'
|
|
818
|
+
import { z } from 'zod'
|
|
819
|
+
|
|
820
|
+
const searchTool = createTool({
|
|
821
|
+
id: 'search',
|
|
822
|
+
description: 'Searches the knowledge base.',
|
|
823
|
+
inputSchema: z.object({ query: z.string() }),
|
|
824
|
+
execute: async ({ query }) => ({ results: [] }),
|
|
825
|
+
})
|
|
826
|
+
|
|
827
|
+
await server.toolActions.add({ searchTool })
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
### `toolActions.remove(toolIds)`
|
|
831
|
+
|
|
832
|
+
Removes tools from the running server by tool ID and notifies connected clients. Unknown tool IDs are ignored. If no tools were removed, no notification is sent.
|
|
833
|
+
|
|
834
|
+
```typescript
|
|
835
|
+
async server.toolActions.remove(toolIds: string[]): Promise<void>
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
Example:
|
|
839
|
+
|
|
840
|
+
```typescript
|
|
841
|
+
await server.toolActions.remove(['searchTool'])
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
### `toolActions.notifyListChanged()`
|
|
845
|
+
|
|
846
|
+
Sends a `notifications/tools/list_changed` message to connected clients without modifying the tool registry. Call this when tool availability changes through other means (for example, authorization changes).
|
|
847
|
+
|
|
848
|
+
```typescript
|
|
849
|
+
async server.toolActions.notifyListChanged(): Promise<void>
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
### Mastra registry synchronization
|
|
853
|
+
|
|
854
|
+
When the server is registered with a Mastra instance, `toolActions.add()` and `toolActions.remove()` also update the Mastra instance's tool registry, matching the automatic tool registration that happens at startup. Added tools become available through `mastra.listTools()` (keyed by the tool's intrinsic `id` when present), and removed tools are deleted from the registry.
|
|
855
|
+
|
|
856
|
+
## Logging
|
|
857
|
+
|
|
858
|
+
MCP servers can send structured log messages to clients using `notifications/message`. Clients control verbosity by sending a `logging/setLevel` request; the server drops messages below the requested minimum level (following RFC 5424 severity ordering). The level is tracked per session, so different clients can request different verbosity.
|
|
859
|
+
|
|
860
|
+
### `sendLoggingMessage()`
|
|
861
|
+
|
|
862
|
+
Sends a log notification to all connected clients, honoring each client's minimum logging level.
|
|
863
|
+
|
|
864
|
+
```typescript
|
|
865
|
+
async server.sendLoggingMessage(params: {
|
|
866
|
+
level: LoggingLevel;
|
|
867
|
+
data: unknown;
|
|
868
|
+
logger?: string;
|
|
869
|
+
}): Promise<void>
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
Example:
|
|
873
|
+
|
|
874
|
+
```typescript
|
|
875
|
+
await server.sendLoggingMessage({
|
|
876
|
+
level: 'info',
|
|
877
|
+
data: { message: 'Sync completed', itemsProcessed: 42 },
|
|
878
|
+
})
|
|
879
|
+
```
|
|
880
|
+
|
|
881
|
+
### `context.mcp.log()`
|
|
882
|
+
|
|
883
|
+
Inside a tool's `execute` function, use `context.mcp.log()` to send a log message to the client that called the tool.
|
|
884
|
+
|
|
885
|
+
```typescript
|
|
886
|
+
async context.mcp.log(
|
|
887
|
+
level: LoggingLevel,
|
|
888
|
+
message: string,
|
|
889
|
+
data?: Record<string, unknown>
|
|
890
|
+
): Promise<void>
|
|
891
|
+
```
|
|
892
|
+
|
|
893
|
+
Example:
|
|
894
|
+
|
|
895
|
+
```typescript
|
|
896
|
+
execute: async ({ location }, context) => {
|
|
897
|
+
await context.mcp.log('debug', 'Fetching weather', { location })
|
|
898
|
+
const weather = await fetchWeather(location)
|
|
899
|
+
await context.mcp.log('info', 'Weather fetched')
|
|
900
|
+
return weather
|
|
901
|
+
}
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
## Progress notifications
|
|
905
|
+
|
|
906
|
+
Long-running tools can report progress to the calling client with `notifications/progress`. Progress is only sent when the caller requested progress tracking by including a `progressToken` in the request (the Mastra `MCPClient` does this when `enableProgressTracking` is set). When no token was sent, `context.mcp.progress()` is a no-op.
|
|
907
|
+
|
|
908
|
+
### `context.mcp.progress()`
|
|
909
|
+
|
|
910
|
+
```typescript
|
|
911
|
+
async context.mcp.progress(params: {
|
|
912
|
+
progress: number;
|
|
913
|
+
total?: number;
|
|
914
|
+
message?: string;
|
|
915
|
+
}): Promise<void>
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
Example:
|
|
919
|
+
|
|
920
|
+
```typescript
|
|
921
|
+
execute: async ({ items }, context) => {
|
|
922
|
+
for (const [index, item] of items.entries()) {
|
|
923
|
+
await processItem(item)
|
|
924
|
+
await context.mcp.progress({
|
|
925
|
+
progress: index + 1,
|
|
926
|
+
total: items.length,
|
|
927
|
+
message: `Processed ${item.name}`,
|
|
928
|
+
})
|
|
929
|
+
}
|
|
930
|
+
return { done: true }
|
|
931
|
+
}
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
## Notification delivery
|
|
935
|
+
|
|
936
|
+
Notification methods (`resources.notifyListChanged()`, `prompts.notifyListChanged()`, `toolActions.notifyListChanged()`, and `sendLoggingMessage()`) broadcast to every connected client across all transports: the stdio/SSE connection and each streamable HTTP session. `resources.notifyUpdated()` is the exception: it only notifies clients that subscribed to the resource URI via `resources/subscribe`. Subscriptions are tracked per session for streamable HTTP clients; legacy SSE clients share the main server instance and therefore share one subscription set. Clients using the stateless serverless mode can't receive notifications because each request uses a transient server instance.
|
|
937
|
+
|
|
779
938
|
## Examples
|
|
780
939
|
|
|
781
940
|
For practical examples of setting up and deploying an MCPServer, see the [Publishing an MCP Server guide](https://mastra.ai/guides/guide/publishing-mcp-server).
|
|
@@ -1402,9 +1561,7 @@ const server = new MCPServer({
|
|
|
1402
1561
|
})
|
|
1403
1562
|
```
|
|
1404
1563
|
|
|
1405
|
-
Link a tool to its app resource by setting `_meta.ui.resourceUri` on the tool to the matching `ui://` URI. The server auto-normalizes this metadata when registering tools.
|
|
1406
|
-
|
|
1407
|
-
> **Note:** Visit [MCP Apps](https://mastra.ai/docs/mcp/mcp-apps) for the full app bridge API and usage patterns.
|
|
1564
|
+
Link a tool to its app resource by setting `_meta.ui.resourceUri` on the tool to the matching `ui://` URI. The server auto-normalizes this metadata when registering tools. Visit [MCP Apps](https://mastra.ai/docs/mcp/mcp-apps) for the full app bridge API and usage patterns.
|
|
1408
1565
|
|
|
1409
1566
|
## Related information
|
|
1410
1567
|
|