@mastra/mcp 1.13.1 → 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 +75 -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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sends a notification to every active server instance (the main stdio/SSE
|
|
5
|
+
* instance plus each streamable HTTP session instance).
|
|
6
|
+
*
|
|
7
|
+
* Failures are aggregated: if only some instances fail, the failure is logged
|
|
8
|
+
* and the broadcast is considered best-effort. A `MastraError` is thrown only
|
|
9
|
+
* when every send fails.
|
|
10
|
+
*
|
|
11
|
+
* Note: clients connected in stateless/serverless mode cannot receive
|
|
12
|
+
* notifications because each request uses a transient server instance.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function broadcastNotification({ servers, send, logger, errorId, errorText, errorDetails, }: {
|
|
17
|
+
servers: Server[];
|
|
18
|
+
send: (server: Server) => Promise<void>;
|
|
19
|
+
logger: IMastraLogger;
|
|
20
|
+
errorId: Uppercase<string>;
|
|
21
|
+
errorText: string;
|
|
22
|
+
errorDetails?: Record<string, string | number>;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=notificationBroadcast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notificationBroadcast.d.ts","sourceRoot":"","sources":["../../src/server/notificationBroadcast.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,EACT,YAAY,GACb,EAAE;IACD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CAChD,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChB"}
|
|
@@ -2,7 +2,7 @@ import type { IMastraLogger } from '@mastra/core/logger';
|
|
|
2
2
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
3
|
interface ServerPromptActionsDependencies {
|
|
4
4
|
getLogger: () => IMastraLogger;
|
|
5
|
-
|
|
5
|
+
getSdkServers: () => Server[];
|
|
6
6
|
clearDefinedPrompts: () => void;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
@@ -10,10 +10,15 @@ interface ServerPromptActionsDependencies {
|
|
|
10
10
|
*
|
|
11
11
|
* This class provides methods for MCP servers to notify connected clients when
|
|
12
12
|
* the list of available prompts changes.
|
|
13
|
+
*
|
|
14
|
+
* Notifications are broadcast to every active server instance (the main
|
|
15
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
16
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
17
|
+
* uses a transient server instance.
|
|
13
18
|
*/
|
|
14
19
|
export declare class ServerPromptActions {
|
|
15
20
|
private readonly getLogger;
|
|
16
|
-
private readonly
|
|
21
|
+
private readonly getSdkServers;
|
|
17
22
|
private readonly clearDefinedPrompts;
|
|
18
23
|
/**
|
|
19
24
|
* @internal
|
|
@@ -25,7 +30,7 @@ export declare class ServerPromptActions {
|
|
|
25
30
|
* This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
|
|
26
31
|
* message to all clients, prompting them to re-fetch the prompt list.
|
|
27
32
|
*
|
|
28
|
-
* @throws {MastraError} If sending the notification fails
|
|
33
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
29
34
|
*
|
|
30
35
|
* @example
|
|
31
36
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGxE,UAAU,+BAA+B;IACvC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAa;IAEjD;;OAEG;gBACS,YAAY,EAAE,+BAA+B;IAMzD;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAWhD"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { IMastraLogger } from '@mastra/core/logger';
|
|
2
2
|
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
3
|
interface ServerResourceActionsDependencies {
|
|
4
|
-
|
|
4
|
+
getSubscribedServers: (uri: string) => Server[];
|
|
5
5
|
getLogger: () => IMastraLogger;
|
|
6
|
-
|
|
6
|
+
getSdkServers: () => Server[];
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Server-side resource actions for notifying clients about resource changes.
|
|
10
10
|
*
|
|
11
11
|
* This class provides methods for MCP servers to notify connected clients when
|
|
12
12
|
* resources are updated or when the resource list changes.
|
|
13
|
+
*
|
|
14
|
+
* Notifications are broadcast to every active server instance (the main
|
|
15
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
16
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
17
|
+
* uses a transient server instance.
|
|
13
18
|
*/
|
|
14
19
|
export declare class ServerResourceActions {
|
|
15
|
-
private readonly
|
|
20
|
+
private readonly getSubscribedServers;
|
|
16
21
|
private readonly getLogger;
|
|
17
|
-
private readonly
|
|
22
|
+
private readonly getSdkServers;
|
|
18
23
|
/**
|
|
19
24
|
* @internal
|
|
20
25
|
*/
|
|
@@ -22,12 +27,13 @@ export declare class ServerResourceActions {
|
|
|
22
27
|
/**
|
|
23
28
|
* Notifies subscribed clients that a specific resource has been updated.
|
|
24
29
|
*
|
|
25
|
-
*
|
|
26
|
-
* `notifications/resources/updated` message
|
|
30
|
+
* Only clients that subscribed to the resource URI (via `resources/subscribe`)
|
|
31
|
+
* receive a `notifications/resources/updated` message prompting them to
|
|
32
|
+
* re-fetch the resource content.
|
|
27
33
|
*
|
|
28
34
|
* @param params - Notification parameters
|
|
29
35
|
* @param params.uri - URI of the resource that was updated
|
|
30
|
-
* @throws {MastraError} If sending the notification fails
|
|
36
|
+
* @throws {MastraError} If sending the notification fails on all subscribed server instances
|
|
31
37
|
*
|
|
32
38
|
* @example
|
|
33
39
|
* ```typescript
|
|
@@ -45,7 +51,7 @@ export declare class ServerResourceActions {
|
|
|
45
51
|
* them to re-fetch the resource list. Resource lists and templates are always evaluated
|
|
46
52
|
* per request, so there is no server-side cache to clear.
|
|
47
53
|
*
|
|
48
|
-
* @throws {MastraError} If sending the notification fails
|
|
54
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
49
55
|
*
|
|
50
56
|
* @example
|
|
51
57
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/server/resourceActions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/server/resourceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGxE,UAAU,iCAAiC;IACzC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAChD,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA4B;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAE/C;;OAEG;gBACS,YAAY,EAAE,iCAAiC;IAM3D;;;;;;;;;;;;;;;;OAgBG;IACU,aAAa,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBnE;;;;;;;;;;;;;;OAcG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAUhD"}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -9,12 +9,13 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
9
9
|
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
10
10
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
11
11
|
import type { StreamableHTTPServerTransportOptions } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
12
|
-
import type { Resource } from '@modelcontextprotocol/sdk/types.js';
|
|
12
|
+
import type { Resource, LoggingLevel } from '@modelcontextprotocol/sdk/types.js';
|
|
13
13
|
import type { jsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/types.js';
|
|
14
14
|
import type { SSEStreamingApi } from '../_types/hono/dist/types/helper/streaming/index.d.ts';
|
|
15
15
|
import { SSETransport } from '../_types/hono-mcp-server-sse-transport/build/index.d.ts';
|
|
16
16
|
import { ServerPromptActions } from './promptActions.js';
|
|
17
17
|
import { ServerResourceActions } from './resourceActions.js';
|
|
18
|
+
import { ServerToolActions } from './toolActions.js';
|
|
18
19
|
import type { MCPServerPrompts, MCPServerResources, ElicitationActions, AppResources } from './types.js';
|
|
19
20
|
/**
|
|
20
21
|
* MCPServer exposes Mastra tools, agents, and workflows as a Model Context Protocol (MCP) server.
|
|
@@ -58,8 +59,8 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
58
59
|
private jsonSchemaValidator?;
|
|
59
60
|
private mapAuthInfoToUser?;
|
|
60
61
|
private fga?;
|
|
61
|
-
private
|
|
62
|
-
private
|
|
62
|
+
private subscriptionsByInstance;
|
|
63
|
+
private loggingLevels;
|
|
63
64
|
/**
|
|
64
65
|
* Provides methods to notify clients about resource changes.
|
|
65
66
|
*
|
|
@@ -83,6 +84,24 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
83
84
|
* ```
|
|
84
85
|
*/
|
|
85
86
|
readonly prompts: ServerPromptActions;
|
|
87
|
+
/**
|
|
88
|
+
* Provides methods to dynamically manage tools and notify clients about
|
|
89
|
+
* tool list changes. Named `toolActions` because `tools()` is the tool
|
|
90
|
+
* registry getter inherited from `MCPServerBase`.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Register a new tool at runtime and notify clients
|
|
95
|
+
* await server.toolActions.add({ myNewTool });
|
|
96
|
+
*
|
|
97
|
+
* // Remove a tool and notify clients
|
|
98
|
+
* await server.toolActions.remove(['myNewTool']);
|
|
99
|
+
*
|
|
100
|
+
* // Notify that the tool list changed (e.g. authorization changes)
|
|
101
|
+
* await server.toolActions.notifyListChanged();
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
readonly toolActions: ServerToolActions;
|
|
86
105
|
/**
|
|
87
106
|
* Provides methods for interactive user input collection during tool execution.
|
|
88
107
|
*
|
|
@@ -237,6 +256,67 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
237
256
|
*/
|
|
238
257
|
jsonSchemaValidator?: jsonSchemaValidator;
|
|
239
258
|
});
|
|
259
|
+
/**
|
|
260
|
+
* Returns every connected SDK server instance: the main instance (stdio/SSE
|
|
261
|
+
* transports) plus one instance per streamable HTTP session. Used to
|
|
262
|
+
* broadcast notifications to all connected clients. Instances without a
|
|
263
|
+
* connected transport are skipped.
|
|
264
|
+
*
|
|
265
|
+
* Note: stateless/serverless requests use transient server instances and
|
|
266
|
+
* cannot receive notifications.
|
|
267
|
+
*/
|
|
268
|
+
private getAllSdkServers;
|
|
269
|
+
/**
|
|
270
|
+
* Determines whether a log message at the given level should be sent to the
|
|
271
|
+
* client connected to the given server instance, honoring the minimum level
|
|
272
|
+
* the client set via `logging/setLevel` (RFC 5424 severity ordering).
|
|
273
|
+
* When the client never set a level, all messages are sent.
|
|
274
|
+
*/
|
|
275
|
+
private shouldSendLog;
|
|
276
|
+
/**
|
|
277
|
+
* Sends a `notifications/message` log notification to connected clients.
|
|
278
|
+
*
|
|
279
|
+
* The notification is broadcast to every active server instance, honoring
|
|
280
|
+
* the minimum logging level each client set via `logging/setLevel`.
|
|
281
|
+
*
|
|
282
|
+
* @param params - Log message parameters
|
|
283
|
+
* @param params.level - Log severity level
|
|
284
|
+
* @param params.data - Arbitrary JSON-serializable data to log
|
|
285
|
+
* @param params.logger - Optional logger name
|
|
286
|
+
* @throws {MastraError} If sending the notification fails on all eligible server instances
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* await server.sendLoggingMessage({
|
|
291
|
+
* level: 'info',
|
|
292
|
+
* data: { message: 'Sync completed', itemsProcessed: 42 },
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
sendLoggingMessage(params: {
|
|
297
|
+
level: LoggingLevel;
|
|
298
|
+
data: unknown;
|
|
299
|
+
logger?: string;
|
|
300
|
+
}): Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Registers new tools on the running server. Tools are merged into both the
|
|
303
|
+
* converted tool registry (used by list/call handlers) and the original
|
|
304
|
+
* tools config so they survive tool re-conversion when the server is
|
|
305
|
+
* registered with a Mastra instance.
|
|
306
|
+
*/
|
|
307
|
+
private addTools;
|
|
308
|
+
/**
|
|
309
|
+
* Removes tools from the running server by tool ID.
|
|
310
|
+
*
|
|
311
|
+
* @returns The IDs of the tools that were actually removed
|
|
312
|
+
*/
|
|
313
|
+
private removeTools;
|
|
314
|
+
/**
|
|
315
|
+
* The key a tool is registered under in the Mastra instance's tool
|
|
316
|
+
* registry: the tool's intrinsic ID when present (avoids collisions across
|
|
317
|
+
* MCP servers), falling back to its record key. Mirrors __registerMastra.
|
|
318
|
+
*/
|
|
319
|
+
private mastraToolKey;
|
|
240
320
|
/**
|
|
241
321
|
* Handle an elicitation request by sending it to the connected client.
|
|
242
322
|
* This method sends an elicitation/create request to the client and waits for the response.
|
|
@@ -457,6 +537,19 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
457
537
|
res: http.ServerResponse<http.IncomingMessage>;
|
|
458
538
|
options?: Partial<StreamableHTTPServerTransportOptions> & {
|
|
459
539
|
serverless?: boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Opt into request-scoped SSE streaming for serverless requests.
|
|
542
|
+
*
|
|
543
|
+
* When `true`, the transient serverless transport is created with
|
|
544
|
+
* `enableJsonResponse: false`, which allows in-request `notifications/progress`
|
|
545
|
+
* to stream back to the client before the final result. Defaults to `false`,
|
|
546
|
+
* preserving the JSON-response behavior that buffers only the final result.
|
|
547
|
+
*
|
|
548
|
+
* This only enables notifications scoped to the current request (e.g. progress).
|
|
549
|
+
* Elicitation, subscriptions, and out-of-request resource/list-change
|
|
550
|
+
* notifications still require a stateful session or another protocol model.
|
|
551
|
+
*/
|
|
552
|
+
serverlessStreaming?: boolean;
|
|
460
553
|
};
|
|
461
554
|
}): Promise<void>;
|
|
462
555
|
/**
|
|
@@ -470,6 +563,10 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
470
563
|
*
|
|
471
564
|
* @param req - Incoming HTTP request
|
|
472
565
|
* @param res - HTTP response object
|
|
566
|
+
* @param options - Transport options for this request
|
|
567
|
+
* @param options.enableJsonResponse - When `true` (default), buffers and returns a single
|
|
568
|
+
* JSON-RPC response. When `false`, the request is handled with request-scoped SSE streaming,
|
|
569
|
+
* so in-request `notifications/progress` reach the client before the final result.
|
|
473
570
|
* @private
|
|
474
571
|
*/
|
|
475
572
|
private handleServerlessRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAGV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAA+B,MAAM,oBAAoB,CAAC;AAErG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,oDAAoD,CAAC;AAiB/G,OAAO,KAAK,EAGV,QAAQ,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAGV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAA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U,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;IAuBnH;;;;;;OAMG;IACU,aAAa,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;KAAE,CAAC;CASjE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ToolsInput } from '@mastra/core/agent';
|
|
2
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
3
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
interface ServerToolActionsDependencies {
|
|
5
|
+
getLogger: () => IMastraLogger;
|
|
6
|
+
getSdkServers: () => Server[];
|
|
7
|
+
addTools: (tools: ToolsInput) => void;
|
|
8
|
+
removeTools: (toolIds: string[]) => string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Server-side tool actions for dynamic tool management and notifying clients
|
|
12
|
+
* about tool list changes.
|
|
13
|
+
*
|
|
14
|
+
* Notifications are broadcast to every active server instance (the main
|
|
15
|
+
* stdio/SSE instance plus each streamable HTTP session). Clients connected in
|
|
16
|
+
* stateless/serverless mode cannot receive notifications because each request
|
|
17
|
+
* uses a transient server instance.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ServerToolActions {
|
|
20
|
+
private readonly getLogger;
|
|
21
|
+
private readonly getSdkServers;
|
|
22
|
+
private readonly addTools;
|
|
23
|
+
private readonly removeTools;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
constructor(dependencies: ServerToolActionsDependencies);
|
|
28
|
+
/**
|
|
29
|
+
* Registers new tools on the running server and notifies connected clients
|
|
30
|
+
* that the tool list has changed.
|
|
31
|
+
*
|
|
32
|
+
* Tools are keyed by their record key, the same as tools passed to the
|
|
33
|
+
* `MCPServer` constructor. Adding a tool under an existing key replaces it.
|
|
34
|
+
*
|
|
35
|
+
* @param tools - Tools to register
|
|
36
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* await server.toolActions.add({ myNewTool });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
add(tools: ToolsInput): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Removes tools from the running server and notifies connected clients that
|
|
46
|
+
* the tool list has changed.
|
|
47
|
+
*
|
|
48
|
+
* Unknown tool IDs are ignored (logged as a warning). If no tools were
|
|
49
|
+
* actually removed, no notification is sent.
|
|
50
|
+
*
|
|
51
|
+
* @param toolIds - IDs of the tools to remove
|
|
52
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* await server.toolActions.remove(['myNewTool']);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
remove(toolIds: string[]): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Notifies clients that the overall list of available tools has changed.
|
|
62
|
+
*
|
|
63
|
+
* This sends a `notifications/tools/list_changed` message to all clients,
|
|
64
|
+
* prompting them to re-fetch the tool list.
|
|
65
|
+
*
|
|
66
|
+
* @throws {MastraError} If sending the notification fails on all server instances
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // After changing which tools are available
|
|
71
|
+
* await server.toolActions.notifyListChanged();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
notifyListChanged(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=toolActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolActions.d.ts","sourceRoot":"","sources":["../../src/server/toolActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGxE,UAAU,6BAA6B;IACrC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACtC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAE9D;;OAEG;gBACS,YAAY,EAAE,6BAA6B;IAOvD;;;;;;;;;;;;;;OAcG;IACU,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;;;;;;;;;;;;;OAcG;IACU,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASrD;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAUhD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@hono/node-server": "^1.19.11",
|
|
39
39
|
"@mendable/firecrawl-js": "^1.29.3",
|
|
40
40
|
"@types/node": "22.19.21",
|
|
41
|
-
"@vitest/coverage-v8": "4.1.
|
|
42
|
-
"@vitest/ui": "4.1.
|
|
41
|
+
"@vitest/coverage-v8": "4.1.9",
|
|
42
|
+
"@vitest/ui": "4.1.9",
|
|
43
43
|
"ai": "^5.0.185",
|
|
44
44
|
"eslint": "^10.4.1",
|
|
45
45
|
"get-port": "^7.1.0",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"tsup": "^8.5.1",
|
|
49
49
|
"tsx": "^4.22.4",
|
|
50
50
|
"typescript": "^6.0.3",
|
|
51
|
-
"vitest": "4.1.
|
|
51
|
+
"vitest": "4.1.9",
|
|
52
52
|
"zod": "^4.4.3",
|
|
53
53
|
"zod-to-json-schema": "^3.25.1",
|
|
54
|
-
"@internal/lint": "0.0.
|
|
55
|
-
"@internal/
|
|
56
|
-
"@internal/test-utils": "0.0.
|
|
57
|
-
"@mastra/core": "1.
|
|
58
|
-
"@
|
|
59
|
-
"@mastra/schema-compat": "1.3.
|
|
60
|
-
"@
|
|
54
|
+
"@internal/lint": "0.0.113",
|
|
55
|
+
"@internal/types-builder": "0.0.88",
|
|
56
|
+
"@internal/test-utils": "0.0.49",
|
|
57
|
+
"@mastra/core": "1.51.0-alpha.4",
|
|
58
|
+
"@mastra/observability": "1.16.0",
|
|
59
|
+
"@mastra/schema-compat": "1.3.4-alpha.1",
|
|
60
|
+
"@internal/llm-recorder": "0.0.49"
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://mastra.ai",
|
|
63
63
|
"repository": {
|