@mastra/mcp 1.18.1-alpha.2 → 2.0.0-alpha.4
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/dist/client/actions/resource.d.ts +9 -59
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +71 -124
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +30 -120
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/error-utils.d.ts +9 -0
- package/dist/client/error-utils.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/oauth-callback-server.d.ts +8 -4
- package/dist/client/oauth-callback-server.d.ts.map +1 -1
- package/dist/client/oauth-provider.d.ts +91 -45
- package/dist/client/oauth-provider.d.ts.map +1 -1
- package/dist/client/server-proxy.d.ts +26 -46
- package/dist/client/server-proxy.d.ts.map +1 -1
- package/dist/client/types.d.ts +106 -143
- package/dist/client/types.d.ts.map +1 -1
- package/dist/conformance/fixture.d.ts +3 -0
- package/dist/conformance/fixture.d.ts.map +1 -0
- package/dist/conformance/run.d.ts +2 -0
- package/dist/conformance/run.d.ts.map +1 -0
- package/dist/conformance/stdio-server.d.ts +2 -0
- package/dist/conformance/stdio-server.d.ts.map +1 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-migrations-mcp-v2.md +268 -0
- package/dist/docs/references/reference-tools-mcp-client.md +36 -14
- package/dist/docs/references/reference-tools-mcp-server.md +24 -83
- package/dist/index.cjs +1532 -3284
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1535 -3288
- package/dist/index.js.map +1 -1
- package/dist/server/actions.d.ts +34 -0
- package/dist/server/actions.d.ts.map +1 -0
- package/dist/server/oauth-middleware.d.ts +1 -1
- package/dist/server/request.d.ts +54 -0
- package/dist/server/request.d.ts.map +1 -0
- package/dist/server/server.d.ts +112 -808
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/types.d.ts +82 -138
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +3 -3
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/dist/shared/trace-context.d.ts +20 -0
- package/dist/shared/trace-context.d.ts.map +1 -0
- package/package.json +12 -17
- package/dist/_types/hono/dist/types/client/client.d.ts +0 -4
- package/dist/_types/hono/dist/types/client/fetch-result-please.d.ts +0 -35
- package/dist/_types/hono/dist/types/client/index.d.ts +0 -7
- package/dist/_types/hono/dist/types/client/types.d.ts +0 -229
- package/dist/_types/hono/dist/types/client/utils.d.ts +0 -18
- package/dist/_types/hono/dist/types/context.d.ts +0 -455
- package/dist/_types/hono/dist/types/helper/streaming/index.d.ts +0 -8
- package/dist/_types/hono/dist/types/helper/streaming/sse.d.ts +0 -13
- package/dist/_types/hono/dist/types/helper/streaming/stream.d.ts +0 -3
- package/dist/_types/hono/dist/types/helper/streaming/text.d.ts +0 -3
- package/dist/_types/hono/dist/types/hono-base.d.ts +0 -220
- package/dist/_types/hono/dist/types/hono.d.ts +0 -19
- package/dist/_types/hono/dist/types/index.d.ts +0 -37
- package/dist/_types/hono/dist/types/request/constants.d.ts +0 -1
- package/dist/_types/hono/dist/types/request.d.ts +0 -324
- package/dist/_types/hono/dist/types/router.d.ts +0 -97
- package/dist/_types/hono/dist/types/types.d.ts +0 -573
- package/dist/_types/hono/dist/types/utils/body.d.ts +0 -79
- package/dist/_types/hono/dist/types/utils/headers.d.ts +0 -8
- package/dist/_types/hono/dist/types/utils/http-status.d.ts +0 -32
- package/dist/_types/hono/dist/types/utils/mime.d.ts +0 -70
- package/dist/_types/hono/dist/types/utils/stream.d.ts +0 -31
- package/dist/_types/hono/dist/types/utils/types.d.ts +0 -74
- package/dist/_types/hono/package.json +0 -1
- package/dist/_types/hono-mcp-server-sse-transport/build/index.d.ts +0 -1
- package/dist/_types/hono-mcp-server-sse-transport/build/sse.d.ts +0 -25
- package/dist/_types/hono-mcp-server-sse-transport/package.json +0 -1
- package/dist/client/actions/elicitation.d.ts +0 -63
- package/dist/client/actions/elicitation.d.ts.map +0 -1
- package/dist/server/__tests__/mock-extra.d.ts +0 -15
- package/dist/server/__tests__/mock-extra.d.ts.map +0 -1
- package/dist/server/mrtrElicitation.d.ts +0 -39
- package/dist/server/mrtrElicitation.d.ts.map +0 -1
- package/dist/server/notificationBroadcast.d.ts +0 -24
- package/dist/server/notificationBroadcast.d.ts.map +0 -1
- package/dist/server/promptActions.d.ts +0 -49
- package/dist/server/promptActions.d.ts.map +0 -1
- package/dist/server/resourceActions.d.ts +0 -72
- package/dist/server/resourceActions.d.ts.map +0 -1
- package/dist/server/toolActions.d.ts +0 -84
- package/dist/server/toolActions.d.ts.map +0 -1
package/dist/server/server.d.ts
CHANGED
|
@@ -1,51 +1,46 @@
|
|
|
1
1
|
import type * as http from 'node:http';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Agent, ToolsInput } from '@mastra/core/agent';
|
|
3
3
|
import { MCPServerBase } from '@mastra/core/mcp';
|
|
4
|
-
import type { MCPServerConfig,
|
|
4
|
+
import type { MCPServerConfig as CoreMCPServerConfig, MCPToolExecutionResultV2, ServerDetailInfo, ServerInfo } from '@mastra/core/mcp';
|
|
5
5
|
import { RequestContext } from '@mastra/core/request-context';
|
|
6
6
|
import type { InternalCoreTool, MCPToolType } from '@mastra/core/tools';
|
|
7
7
|
import type { Workflow } from '@mastra/core/workflows';
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Opt into request-scoped SSE streaming for legacy serverless requests.
|
|
39
|
-
*
|
|
40
|
-
* The `2026-07-28` handler accepts `true` as a compatibility declaration because
|
|
41
|
-
* its automatic response mode already streams request-scoped messages when needed.
|
|
42
|
-
*/
|
|
43
|
-
serverlessStreaming?: boolean;
|
|
8
|
+
import type { Resource, jsonSchemaValidator } from '@modelcontextprotocol/server';
|
|
9
|
+
import { ServerPromptActions, ServerResourceActions, ServerToolActions } from './actions.js';
|
|
10
|
+
import type { AppResources, MCPServerCacheHints, MCPServerHTTPRequestOptions, MCPServerPrompts, MCPServerRequestStateOptions, MCPServerResources } from './types.js';
|
|
11
|
+
export interface MCPServerConfig extends CoreMCPServerConfig {
|
|
12
|
+
resources?: MCPServerResources;
|
|
13
|
+
prompts?: MCPServerPrompts;
|
|
14
|
+
/** MCP Apps (SEP-1865) HTML resources served under `ui://`. */
|
|
15
|
+
appResources?: AppResources;
|
|
16
|
+
/** Custom JSON Schema validator, for runtimes where the SDK default is unavailable. */
|
|
17
|
+
jsonSchemaValidator?: jsonSchemaValidator;
|
|
18
|
+
cacheHints?: MCPServerCacheHints;
|
|
19
|
+
/** Integrity protection for `input_required` continuation state. */
|
|
20
|
+
requestState?: MCPServerRequestStateOptions;
|
|
21
|
+
}
|
|
22
|
+
export interface MCPServerHTTPOptions {
|
|
23
|
+
url: URL;
|
|
24
|
+
httpPath: string;
|
|
25
|
+
req: http.IncomingMessage;
|
|
26
|
+
res: http.ServerResponse<http.IncomingMessage>;
|
|
27
|
+
options?: MCPServerHTTPRequestOptions;
|
|
28
|
+
}
|
|
29
|
+
/** Tool description served over Mastra's REST routes; `id` is what Studio keys tools by. */
|
|
30
|
+
type ToolInfo = {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
inputSchema: Record<string, unknown>;
|
|
35
|
+
outputSchema?: Record<string, unknown>;
|
|
36
|
+
toolType?: MCPToolType;
|
|
37
|
+
_meta?: Record<string, unknown>;
|
|
44
38
|
};
|
|
45
39
|
/**
|
|
46
|
-
* Exposes Mastra tools, agents, and
|
|
47
|
-
*
|
|
48
|
-
*
|
|
40
|
+
* Exposes Mastra tools, agents, workflows, resources and prompts to Model Context
|
|
41
|
+
* Protocol (MCP) clients using protocol revision 2026-07-28: self-contained requests
|
|
42
|
+
* over Streamable HTTP or stdio, native `input_required` continuation and
|
|
43
|
+
* per-request logging.
|
|
49
44
|
*
|
|
50
45
|
* @example
|
|
51
46
|
* `yourTool` is a tool you have already configured.
|
|
@@ -58,6 +53,7 @@ type MCPServerStreamableHTTPOptions = Partial<StreamableHTTPServerTransportOptio
|
|
|
58
53
|
* version: '1.0.0',
|
|
59
54
|
* tools: { yourTool },
|
|
60
55
|
* });
|
|
56
|
+
* await server.startStdio();
|
|
61
57
|
* ```
|
|
62
58
|
*
|
|
63
59
|
* @see For documentation bundled with your installed package, locate
|
|
@@ -69,789 +65,103 @@ type MCPServerStreamableHTTPOptions = Partial<StreamableHTTPServerTransportOptio
|
|
|
69
65
|
* if packaged docs are unavailable.
|
|
70
66
|
*/
|
|
71
67
|
export declare class MCPServer extends MCPServerBase {
|
|
72
|
-
|
|
73
|
-
private stdioTransport?;
|
|
74
|
-
private sseTransport?;
|
|
75
|
-
private sseHonoTransports;
|
|
76
|
-
/** Auth info for the in-flight Hono SSE message POST, keyed by session id. */
|
|
77
|
-
private sseHonoAuthInfo;
|
|
78
|
-
private streamableHTTPTransports;
|
|
79
|
-
private httpServerInstances;
|
|
80
|
-
private resourceOptions?;
|
|
81
|
-
private hasUiResources;
|
|
82
|
-
private promptOptions?;
|
|
83
|
-
private jsonSchemaValidator?;
|
|
84
|
-
private mapAuthInfoToUser?;
|
|
85
|
-
private fga?;
|
|
86
|
-
private subscriptionsByInstance;
|
|
87
|
-
private loggingLevels;
|
|
88
|
-
private protocolVersion?;
|
|
89
|
-
private cacheHints?;
|
|
90
|
-
private modernEraHandler?;
|
|
91
|
-
private modernEraNodeHandler?;
|
|
92
|
-
private stdioHandle?;
|
|
93
|
-
private stdioServerInstance?;
|
|
94
|
-
/**
|
|
95
|
-
* Provides methods to notify clients about resource changes.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* // Notify that a specific resource was updated
|
|
100
|
-
* await server.resources.notifyUpdated({ uri: 'file://data.txt' });
|
|
101
|
-
*
|
|
102
|
-
* // Notify that the resource list changed
|
|
103
|
-
* await server.resources.notifyListChanged();
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
68
|
+
readonly mcpVersion: 2;
|
|
106
69
|
readonly resources: ServerResourceActions;
|
|
107
|
-
/**
|
|
108
|
-
* Provides methods to notify clients about prompt changes.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* // Notify that the prompt list changed
|
|
113
|
-
* await server.prompts.notifyListChanged();
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
70
|
readonly prompts: ServerPromptActions;
|
|
117
|
-
/**
|
|
118
|
-
* Provides methods to dynamically manage tools and notify clients about
|
|
119
|
-
* tool list changes. Named `toolActions` because `tools()` is the tool
|
|
120
|
-
* registry getter inherited from `MCPServerBase`.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* // Register a new tool at runtime and notify clients
|
|
125
|
-
* await server.toolActions.add({ myNewTool });
|
|
126
|
-
*
|
|
127
|
-
* // Remove a tool and notify clients
|
|
128
|
-
* await server.toolActions.remove(['myNewTool']);
|
|
129
|
-
*
|
|
130
|
-
* // Notify that the tool list changed (e.g. authorization changes)
|
|
131
|
-
* await server.toolActions.notifyListChanged();
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
71
|
readonly toolActions: ServerToolActions;
|
|
72
|
+
private readonly resourceOptions?;
|
|
73
|
+
private readonly promptOptions?;
|
|
74
|
+
private readonly appResourceList;
|
|
75
|
+
private readonly appResourceHtml;
|
|
76
|
+
private readonly jsonSchemaValidator?;
|
|
77
|
+
private readonly cacheHints?;
|
|
78
|
+
private readonly mapAuthInfoToUser?;
|
|
79
|
+
private readonly fga?;
|
|
80
|
+
private readonly requestStateCodec;
|
|
81
|
+
private httpHandler?;
|
|
82
|
+
private nodeHandler?;
|
|
83
|
+
private stdioHandle?;
|
|
84
|
+
private stdioInstance?;
|
|
85
|
+
constructor(config: MCPServerConfig);
|
|
86
|
+
private createRequestStateCodec;
|
|
87
|
+
convertTools(tools: ToolsInput, agents?: Record<string, Agent>, workflows?: Record<string, Workflow>): Record<string, InternalCoreTool>;
|
|
135
88
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* ```typescript
|
|
140
|
-
* // Within a tool's execute function
|
|
141
|
-
* const result = await options.elicitation.sendRequest({
|
|
142
|
-
* message: 'Please provide your email address',
|
|
143
|
-
* requestedSchema: {
|
|
144
|
-
* type: 'object',
|
|
145
|
-
* properties: {
|
|
146
|
-
* email: { type: 'string', format: 'email' }
|
|
147
|
-
* },
|
|
148
|
-
* required: ['email']
|
|
149
|
-
* }
|
|
150
|
-
* });
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
readonly elicitation: ElicitationActions;
|
|
154
|
-
/**
|
|
155
|
-
* Gets the stdio transport instance if the server was started using stdio.
|
|
156
|
-
*
|
|
157
|
-
* This is primarily for internal checks or testing purposes.
|
|
158
|
-
*
|
|
159
|
-
* @returns The stdio transport instance, or undefined if not using stdio transport
|
|
160
|
-
*/
|
|
161
|
-
getStdioTransport(): StdioServerTransport | undefined;
|
|
162
|
-
/**
|
|
163
|
-
* Gets the SSE transport instance if the server was started using SSE.
|
|
164
|
-
*
|
|
165
|
-
* This is primarily for internal checks or testing purposes.
|
|
166
|
-
*
|
|
167
|
-
* @returns The SSE transport instance, or undefined if not using SSE transport
|
|
168
|
-
*/
|
|
169
|
-
getSseTransport(): SSEServerTransport | undefined;
|
|
170
|
-
/**
|
|
171
|
-
* Gets the Hono SSE transport instance for a specific session.
|
|
172
|
-
*
|
|
173
|
-
* This is primarily for internal checks or testing purposes.
|
|
174
|
-
*
|
|
175
|
-
* @param sessionId - The session identifier
|
|
176
|
-
* @returns The Hono SSE transport instance, or undefined if session not found
|
|
177
|
-
*/
|
|
178
|
-
getSseHonoTransport(sessionId: string): HonoSSETransport | undefined;
|
|
179
|
-
/**
|
|
180
|
-
* Gets the underlying MCP Server instance.
|
|
181
|
-
*
|
|
182
|
-
* This provides access to the low-level server instance for advanced use cases.
|
|
183
|
-
*
|
|
184
|
-
* @returns The Server instance from @modelcontextprotocol/server
|
|
185
|
-
*/
|
|
186
|
-
getServer(): Server;
|
|
187
|
-
/**
|
|
188
|
-
* Creates a new MCPServer instance.
|
|
189
|
-
*
|
|
190
|
-
* The server exposes tools, agents, and workflows to MCP clients. Agents are automatically
|
|
191
|
-
* converted to tools named `ask_<agentKey>`, and workflows become tools named `run_<workflowKey>`.
|
|
192
|
-
*
|
|
193
|
-
* @param opts - Configuration options for the server
|
|
194
|
-
* @param opts.name - Descriptive name for the server (e.g., 'My Weather Server')
|
|
195
|
-
* @param opts.version - Semantic version of the server (e.g., '1.0.0')
|
|
196
|
-
* @param opts.tools - Object mapping tool names to tool definitions
|
|
197
|
-
* @param opts.agents - Optional object mapping agent identifiers to Agent instances
|
|
198
|
-
* @param opts.workflows - Optional object mapping workflow identifiers to Workflow instances
|
|
199
|
-
* @param opts.resources - Optional resource configuration for exposing data and content
|
|
200
|
-
* @param opts.prompts - Optional prompt configuration for exposing reusable templates
|
|
201
|
-
* @param opts.id - Optional unique identifier (generated if not provided)
|
|
202
|
-
* @param opts.description - Optional description of what the server does
|
|
203
|
-
* @param opts.mapAuthInfoToUser - Optional mapper from MCP `extra.authInfo` to the FGA user context
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```typescript
|
|
207
|
-
* import { MCPServer } from '@mastra/mcp';
|
|
208
|
-
* import { Agent } from '@mastra/core/agent';
|
|
209
|
-
* import { createTool } from '@mastra/core/tools';
|
|
210
|
-
* import { z } from 'zod';
|
|
211
|
-
*
|
|
212
|
-
* const myAgent = new Agent({
|
|
213
|
-
* id: 'helper',
|
|
214
|
-
* name: 'Helper Agent',
|
|
215
|
-
* description: 'A helpful assistant',
|
|
216
|
-
* instructions: 'You are helpful.',
|
|
217
|
-
* model: 'openai/gpt-4o-mini',
|
|
218
|
-
* });
|
|
219
|
-
*
|
|
220
|
-
* const server = new MCPServer({
|
|
221
|
-
* name: 'My Server',
|
|
222
|
-
* version: '1.0.0',
|
|
223
|
-
* tools: {
|
|
224
|
-
* weatherTool: createTool({
|
|
225
|
-
* id: 'getWeather',
|
|
226
|
-
* description: 'Gets weather',
|
|
227
|
-
* inputSchema: z.object({ location: z.string() }),
|
|
228
|
-
* execute: async (inputData) => `Sunny in ${inputData.location}`,
|
|
229
|
-
* })
|
|
230
|
-
* },
|
|
231
|
-
* agents: { myAgent },
|
|
232
|
-
* });
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
constructor(opts: MCPServerConfig & {
|
|
236
|
-
resources?: MCPServerResources;
|
|
237
|
-
prompts?: MCPServerPrompts;
|
|
238
|
-
/**
|
|
239
|
-
* Optional MCP App resources configuration.
|
|
240
|
-
*
|
|
241
|
-
* Registers `ui://` resources that serve interactive HTML UIs as defined
|
|
242
|
-
* by the MCP Apps extension (SEP-1865). These are automatically merged
|
|
243
|
-
* into the resource system and served alongside any user-provided resources.
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```typescript
|
|
247
|
-
* const server = new MCPServer({
|
|
248
|
-
* name: 'My Server',
|
|
249
|
-
* version: '1.0.0',
|
|
250
|
-
* tools: { ... },
|
|
251
|
-
* appResources: {
|
|
252
|
-
* 'ui://weather/dashboard': {
|
|
253
|
-
* name: 'Weather Dashboard',
|
|
254
|
-
* html: '<html>...</html>',
|
|
255
|
-
* meta: { csp: { connectDomains: ['https://api.weather.com'] } },
|
|
256
|
-
* },
|
|
257
|
-
* },
|
|
258
|
-
* });
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
appResources?: AppResources;
|
|
262
|
-
/**
|
|
263
|
-
* Optional custom JSON Schema validator forwarded to the underlying MCP
|
|
264
|
-
* server. Use this to opt into a non-default validator implementation.
|
|
265
|
-
*
|
|
266
|
-
* Pass `CfWorkerJsonSchemaValidator` (from
|
|
267
|
-
* `@modelcontextprotocol/server/validators/cf-worker`) when running in
|
|
268
|
-
* Cloudflare Workers / V8 isolates: the default
|
|
269
|
-
* `AjvJsonSchemaValidator` compiles validators with `new Function(...)`,
|
|
270
|
-
* which workerd refuses to evaluate when a registered tool has an
|
|
271
|
-
* `outputSchema`.
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```typescript
|
|
275
|
-
* import { MCPServer } from '@mastra/mcp';
|
|
276
|
-
* import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker';
|
|
277
|
-
*
|
|
278
|
-
* const server = new MCPServer({
|
|
279
|
-
* name: 'My Server',
|
|
280
|
-
* version: '1.0.0',
|
|
281
|
-
* tools: { ... },
|
|
282
|
-
* jsonSchemaValidator: new CfWorkerJsonSchemaValidator(),
|
|
283
|
-
* });
|
|
284
|
-
* ```
|
|
285
|
-
*/
|
|
286
|
-
jsonSchemaValidator?: jsonSchemaValidator;
|
|
287
|
-
/**
|
|
288
|
-
* Opt-in MCP protocol revision.
|
|
289
|
-
*
|
|
290
|
-
* Omitted (or `'2025-11-25'`) keeps today's behavior exactly. Set to
|
|
291
|
-
* `'2026-07-28'` to serve the stateless MCP revision: HTTP and serverless
|
|
292
|
-
* requests go through the SDK's dual-era handler (modern clients served
|
|
293
|
-
* natively, legacy clients via the built-in stateless fallback on the same
|
|
294
|
-
* endpoint), and stdio serves both eras via the `server/discover` probe.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```typescript
|
|
298
|
-
* const server = new MCPServer({
|
|
299
|
-
* name: 'My Server',
|
|
300
|
-
* version: '1.0.0',
|
|
301
|
-
* tools: { ... },
|
|
302
|
-
* protocolVersion: '2026-07-28',
|
|
303
|
-
* });
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
protocolVersion?: MCPServerProtocolVersion;
|
|
307
|
-
/**
|
|
308
|
-
* Cache hints (`ttlMs` / `cacheScope`) advertised on cacheable results of the
|
|
309
|
-
* `2026-07-28` protocol revision, keyed by operation (e.g. `'tools/list'`).
|
|
310
|
-
* Only applied when `protocolVersion: '2026-07-28'` is set; legacy responses
|
|
311
|
-
* are never affected.
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```typescript
|
|
315
|
-
* const server = new MCPServer({
|
|
316
|
-
* name: 'My Server',
|
|
317
|
-
* version: '1.0.0',
|
|
318
|
-
* tools: { ... },
|
|
319
|
-
* protocolVersion: '2026-07-28',
|
|
320
|
-
* cacheHints: { 'tools/list': { ttlMs: 60_000, cacheScope: 'private' } },
|
|
321
|
-
* });
|
|
322
|
-
* ```
|
|
323
|
-
*/
|
|
324
|
-
cacheHints?: MCPServerCacheHints;
|
|
325
|
-
});
|
|
326
|
-
/**
|
|
327
|
-
* Returns every connected SDK server instance: the main instance (stdio/SSE
|
|
328
|
-
* transports) plus one instance per streamable HTTP session. Used to
|
|
329
|
-
* broadcast notifications to all connected clients. Instances without a
|
|
330
|
-
* connected transport are skipped.
|
|
331
|
-
*
|
|
332
|
-
* Note: stateless/serverless requests use transient server instances and
|
|
333
|
-
* cannot receive notifications.
|
|
334
|
-
*/
|
|
335
|
-
private getAllSdkServers;
|
|
336
|
-
/**
|
|
337
|
-
* Whether the server is pinned to the `2026-07-28` protocol revision.
|
|
338
|
-
* When false (the default), all behavior is byte-identical to the legacy era.
|
|
339
|
-
*/
|
|
340
|
-
private servesModernEra;
|
|
341
|
-
private assertModernEraHTTPOptions;
|
|
342
|
-
private validateHTTPRequestHeaders;
|
|
343
|
-
/**
|
|
344
|
-
* Lazily creates the dual-era HTTP handler used when `protocolVersion: '2026-07-28'`
|
|
345
|
-
* is set: modern (per-request envelope) clients are served natively and legacy
|
|
346
|
-
* clients are served through the SDK's built-in stateless fallback, both from the
|
|
347
|
-
* same endpoint. Each request gets a fresh server instance from
|
|
348
|
-
* `createServerInstance()`, so all registered handlers apply to both eras.
|
|
349
|
-
*/
|
|
350
|
-
private getModernEraHandler;
|
|
351
|
-
/**
|
|
352
|
-
* Node `(req, res)` adapter over the dual-era handler's web-standard `fetch`.
|
|
353
|
-
*/
|
|
354
|
-
private getModernEraNodeHandler;
|
|
355
|
-
/**
|
|
356
|
-
* Determines whether a log message at the given level should be sent to the
|
|
357
|
-
* client connected to the given server instance, honoring the minimum level
|
|
358
|
-
* the client set via `logging/setLevel` (RFC 5424 severity ordering).
|
|
359
|
-
* When the client never set a level, all messages are sent.
|
|
89
|
+
* A suspended handler's `resumeSchema` becomes the form the client fills in, and
|
|
90
|
+
* the protocol only allows a flat object of primitives there. Checked at registration
|
|
91
|
+
* so a tool cannot suspend into a request no client can answer.
|
|
360
92
|
*/
|
|
361
|
-
private
|
|
93
|
+
private assertFormRepresentable;
|
|
362
94
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
* The notification is broadcast to every active server instance, honoring
|
|
366
|
-
* the minimum logging level each client set via `logging/setLevel`.
|
|
367
|
-
*
|
|
368
|
-
* @param params - Log message parameters
|
|
369
|
-
* @param params.level - Log severity level
|
|
370
|
-
* @param params.data - Arbitrary JSON-serializable data to log
|
|
371
|
-
* @param params.logger - Optional logger name
|
|
372
|
-
* @throws {MastraError} If sending the notification fails on all eligible server instances
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```typescript
|
|
376
|
-
* await server.sendLoggingMessage({
|
|
377
|
-
* level: 'info',
|
|
378
|
-
* data: { message: 'Sync completed', itemsProcessed: 42 },
|
|
379
|
-
* });
|
|
380
|
-
* ```
|
|
95
|
+
* Input-request forms are a restricted flat-object subset of JSON Schema, so
|
|
96
|
+
* the dialect declaration is left off the requested schema.
|
|
381
97
|
*/
|
|
382
|
-
|
|
383
|
-
level: LoggingLevel;
|
|
384
|
-
data: unknown;
|
|
385
|
-
logger?: string;
|
|
386
|
-
}): Promise<void>;
|
|
98
|
+
private formSchema;
|
|
387
99
|
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* registered with a Mastra instance.
|
|
100
|
+
* Converts a tool schema to JSON Schema 2020-12, the dialect MCP 2026-07-28
|
|
101
|
+
* assumes when none is declared. The dialect declaration is kept so validators
|
|
102
|
+
* that dispatch on `$schema` pick the same draft on both sides.
|
|
392
103
|
*/
|
|
104
|
+
private jsonSchema;
|
|
393
105
|
private addTools;
|
|
394
|
-
/**
|
|
395
|
-
* Removes tools from the running server by tool ID.
|
|
396
|
-
*
|
|
397
|
-
* @returns The IDs of the tools that were actually removed
|
|
398
|
-
*/
|
|
399
106
|
private removeTools;
|
|
400
|
-
/**
|
|
401
|
-
* The key a tool is registered under in the Mastra instance's tool
|
|
402
|
-
* registry: the tool's intrinsic ID when present (avoids collisions across
|
|
403
|
-
* MCP servers), falling back to its record key. Mirrors __registerMastra.
|
|
404
|
-
*/
|
|
107
|
+
/** Mirrors `__registerMastra`: the tool's intrinsic id when it has one, else its key. */
|
|
405
108
|
private mastraToolKey;
|
|
406
|
-
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
* it uses the pre-parsed body from req.body. Otherwise, it reads from the stream.
|
|
420
|
-
*
|
|
421
|
-
* This allows the MCP server to work with Express apps that use express.json()
|
|
422
|
-
* globally without requiring special route exclusions.
|
|
423
|
-
*
|
|
424
|
-
* @param req - The incoming HTTP request
|
|
425
|
-
* @param options - Optional configuration
|
|
426
|
-
* @param options.preParsedOnly - If true, only return pre-parsed body from middleware,
|
|
427
|
-
* returning undefined if not available. This allows the caller to fall back to
|
|
428
|
-
* their own body reading logic (e.g., SDK's getRawBody with size limits).
|
|
429
|
-
*/
|
|
430
|
-
private readJsonBody;
|
|
431
|
-
/**
|
|
432
|
-
* Merges appResources into the resource system alongside any user-provided resources.
|
|
433
|
-
*
|
|
434
|
-
* App resources are auto-registered as `ui://` resources with the MCP Apps MIME type.
|
|
435
|
-
* If the user also provides a `resources` config, the two are merged — user callbacks
|
|
436
|
-
* take precedence for overlapping URIs.
|
|
437
|
-
*/
|
|
438
|
-
private mergeAppResources;
|
|
439
|
-
/**
|
|
440
|
-
* Creates a new Server instance configured with all handlers for HTTP sessions.
|
|
441
|
-
* Each HTTP client connection gets its own Server instance to avoid routing conflicts.
|
|
442
|
-
*/
|
|
109
|
+
/** Schema-less tools advertise an open empty object rather than the default validator schema. */
|
|
110
|
+
private hasInputSchema;
|
|
111
|
+
private resumeSchemaOf;
|
|
112
|
+
/**
|
|
113
|
+
* Prefers the tool's own schema over the converted core tool's, which has
|
|
114
|
+
* already been lowered to draft-07, so 2020-12 shapes survive advertisement.
|
|
115
|
+
*/
|
|
116
|
+
private advertisedSchema;
|
|
117
|
+
private toolInfo;
|
|
118
|
+
/** Builds the wire tool description, validated against the spec schema. */
|
|
119
|
+
private toMCPTool;
|
|
120
|
+
private hasUiMetadata;
|
|
121
|
+
private capabilities;
|
|
443
122
|
private createServerInstance;
|
|
444
|
-
/**
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
*
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
private
|
|
457
|
-
private
|
|
458
|
-
private
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
* @param workflowsConfig Workflow definitions to be converted to tools, expected from MCPServerConfig
|
|
465
|
-
* @returns Converted tools registry
|
|
466
|
-
*/
|
|
467
|
-
convertTools(tools: ToolsInput, agentsConfig?: Record<string, Agent>, workflowsConfig?: Record<string, Workflow>): Record<string, InternalCoreTool>;
|
|
468
|
-
/**
|
|
469
|
-
* Starts the MCP server using standard input/output (stdio) transport.
|
|
470
|
-
*
|
|
471
|
-
* This is typically used when running the server as a command-line program that MCP clients
|
|
472
|
-
* spawn as a subprocess (e.g., integration with Windsurf, Cursor, or Claude Desktop).
|
|
473
|
-
*
|
|
474
|
-
* @throws {MastraError} If the stdio connection fails
|
|
475
|
-
*
|
|
476
|
-
* @example
|
|
477
|
-
* ```typescript
|
|
478
|
-
* const server = new MCPServer({
|
|
479
|
-
* name: 'My Server',
|
|
480
|
-
* version: '1.0.0',
|
|
481
|
-
* tools: { weatherTool },
|
|
482
|
-
* });
|
|
483
|
-
*
|
|
484
|
-
* await server.startStdio();
|
|
485
|
-
* ```
|
|
486
|
-
*/
|
|
123
|
+
/** Answers a suspended round: one keyed form derived from the handler's `resumeSchema`. */
|
|
124
|
+
private inputRequired;
|
|
125
|
+
private serverRequest;
|
|
126
|
+
private registerToolHandlers;
|
|
127
|
+
/**
|
|
128
|
+
* Runs one round of a tool. The tool sees the same `suspend` / `resumeData` /
|
|
129
|
+
* `suspendPayload` vocabulary as under an agent or workflow; nothing else is
|
|
130
|
+
* carried between rounds.
|
|
131
|
+
*/
|
|
132
|
+
private runTool;
|
|
133
|
+
private toCallToolResult;
|
|
134
|
+
private registerResourceHandlers;
|
|
135
|
+
private resourceContents;
|
|
136
|
+
private registerPromptHandlers;
|
|
137
|
+
private loadAppResources;
|
|
138
|
+
private enforceToolExecutionFGA;
|
|
139
|
+
private authorizedToolEntries;
|
|
140
|
+
private notifier;
|
|
141
|
+
private getNodeHandler;
|
|
142
|
+
/** Serves the current process's stdio. Legacy openings are rejected. */
|
|
487
143
|
startStdio(): Promise<void>;
|
|
488
144
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
* Call this method from your web server's request handler for both the SSE and message paths.
|
|
492
|
-
* This enables web-based MCP clients to connect to your server.
|
|
493
|
-
*
|
|
494
|
-
* @param options - Configuration for SSE integration
|
|
495
|
-
* @param options.url - Parsed URL of the incoming request
|
|
496
|
-
* @param options.ssePath - Path for establishing SSE connection (e.g., '/sse')
|
|
497
|
-
* @param options.messagePath - Path for POSTing client messages (e.g., '/message')
|
|
498
|
-
* @param options.req - Incoming HTTP request object
|
|
499
|
-
* @param options.res - HTTP response object (must support .write/.end)
|
|
500
|
-
*
|
|
501
|
-
* @throws {MastraError} If SSE connection setup fails
|
|
502
|
-
*
|
|
503
|
-
* @example
|
|
504
|
-
* ```typescript
|
|
505
|
-
* import http from 'node:http';
|
|
506
|
-
*
|
|
507
|
-
* const httpServer = http.createServer(async (req, res) => {
|
|
508
|
-
* await server.startSSE({
|
|
509
|
-
* url: new URL(req.url || '', `http://localhost:1234`),
|
|
510
|
-
* ssePath: '/sse',
|
|
511
|
-
* messagePath: '/message',
|
|
512
|
-
* req,
|
|
513
|
-
* res,
|
|
514
|
-
* });
|
|
515
|
-
* });
|
|
516
|
-
*
|
|
517
|
-
* httpServer.listen(1234, () => {
|
|
518
|
-
* console.log('MCP server listening on http://localhost:1234/sse');
|
|
519
|
-
* });
|
|
520
|
-
* ```
|
|
521
|
-
*/
|
|
522
|
-
startSSE({ url, ssePath, messagePath, req, res }: MCPServerSSEOptions): Promise<void>;
|
|
523
|
-
/**
|
|
524
|
-
* Integrates the MCP server with a Hono web framework using Server-Sent Events (SSE).
|
|
525
|
-
*
|
|
526
|
-
* Call this method from your Hono server's request handler for both the SSE and message paths.
|
|
527
|
-
* This enables Hono-based web applications to expose MCP servers.
|
|
528
|
-
*
|
|
529
|
-
* @param options - Configuration for Hono SSE integration
|
|
530
|
-
* @param options.url - Parsed URL of the incoming request
|
|
531
|
-
* @param options.ssePath - Path for establishing SSE connection (e.g., '/hono-sse')
|
|
532
|
-
* @param options.messagePath - Path for POSTing client messages (e.g., '/message')
|
|
533
|
-
* @param options.context - Hono context object
|
|
534
|
-
*
|
|
535
|
-
* @throws {MastraError} If Hono SSE connection setup fails
|
|
536
|
-
*
|
|
537
|
-
* @example
|
|
538
|
-
* ```typescript
|
|
539
|
-
* import { Hono } from 'hono';
|
|
540
|
-
*
|
|
541
|
-
* const app = new Hono();
|
|
542
|
-
*
|
|
543
|
-
* app.all('*', async (c) => {
|
|
544
|
-
* const url = new URL(c.req.url);
|
|
545
|
-
* return await server.startHonoSSE({
|
|
546
|
-
* url,
|
|
547
|
-
* ssePath: '/hono-sse',
|
|
548
|
-
* messagePath: '/message',
|
|
549
|
-
* context: c,
|
|
550
|
-
* });
|
|
551
|
-
* });
|
|
552
|
-
*
|
|
553
|
-
* export default app;
|
|
554
|
-
* ```
|
|
555
|
-
*/
|
|
556
|
-
startHonoSSE({ url, ssePath, messagePath, context, authInfo }: MCPServerHonoSSEOptions): Promise<Response>;
|
|
557
|
-
/**
|
|
558
|
-
* Integrates the MCP server with an existing HTTP server using streamable HTTP transport.
|
|
559
|
-
*
|
|
560
|
-
* This is the recommended modern transport method, providing better session management and
|
|
561
|
-
* reliability compared to SSE. Call this from your HTTP server's request handler.
|
|
562
|
-
*
|
|
563
|
-
* @param options - Configuration for HTTP integration
|
|
564
|
-
* @param options.url - Parsed URL of the incoming request
|
|
565
|
-
* @param options.httpPath - Path for the MCP endpoint (e.g., '/mcp')
|
|
566
|
-
* @param options.req - Incoming HTTP request (http.IncomingMessage)
|
|
567
|
-
* @param options.res - HTTP response object (http.ServerResponse)
|
|
568
|
-
* @param options.options - Optional transport options
|
|
569
|
-
* @param options.options.sessionIdGenerator - Function to generate unique session IDs (defaults to randomUUID)
|
|
570
|
-
* @param options.options.onsessioninitialized - Callback when a new session is initialized
|
|
571
|
-
* @param options.options.enableJsonResponse - If true, return JSON instead of SSE streaming
|
|
572
|
-
* @param options.options.eventStore - Event store for message resumability
|
|
573
|
-
* @param options.options.serverless - If true, run in stateless mode without session management (ideal for serverless environments)
|
|
574
|
-
*
|
|
575
|
-
* @throws {MastraError} If HTTP connection setup fails
|
|
576
|
-
*
|
|
577
|
-
* @example
|
|
578
|
-
* ```typescript
|
|
579
|
-
* import http from 'node:http';
|
|
580
|
-
* import { randomUUID } from 'node:crypto';
|
|
581
|
-
*
|
|
582
|
-
* const httpServer = http.createServer(async (req, res) => {
|
|
583
|
-
* await server.startHTTP({
|
|
584
|
-
* url: new URL(req.url || '', 'http://localhost:1234'),
|
|
585
|
-
* httpPath: '/mcp',
|
|
586
|
-
* req,
|
|
587
|
-
* res,
|
|
588
|
-
* options: {
|
|
589
|
-
* sessionIdGenerator: () => randomUUID(),
|
|
590
|
-
* onsessioninitialized: (sessionId) => {
|
|
591
|
-
* console.log(`New MCP session: ${sessionId}`);
|
|
592
|
-
* },
|
|
593
|
-
* },
|
|
594
|
-
* });
|
|
595
|
-
* });
|
|
596
|
-
*
|
|
597
|
-
* httpServer.listen(1234);
|
|
598
|
-
* ```
|
|
599
|
-
*
|
|
600
|
-
* @example Serverless mode (Cloudflare Workers, Vercel Edge, etc.)
|
|
601
|
-
* ```typescript
|
|
602
|
-
* export default {
|
|
603
|
-
* async fetch(request: Request) {
|
|
604
|
-
* const url = new URL(request.url);
|
|
605
|
-
* if (url.pathname === '/mcp') {
|
|
606
|
-
* await server.startHTTP({
|
|
607
|
-
* url,
|
|
608
|
-
* httpPath: '/mcp',
|
|
609
|
-
* req: request,
|
|
610
|
-
* res: response,
|
|
611
|
-
* options: { serverless: true },
|
|
612
|
-
* });
|
|
613
|
-
* }
|
|
614
|
-
* return new Response('Not found', { status: 404 });
|
|
615
|
-
* },
|
|
616
|
-
* };
|
|
617
|
-
* ```
|
|
618
|
-
*/
|
|
619
|
-
startHTTP({ url, httpPath, req, res, options, }: {
|
|
620
|
-
url: URL;
|
|
621
|
-
httpPath: string;
|
|
622
|
-
req: http.IncomingMessage;
|
|
623
|
-
res: http.ServerResponse<http.IncomingMessage>;
|
|
624
|
-
/**
|
|
625
|
-
* Streamable HTTP transport options for the legacy protocol path.
|
|
626
|
-
*
|
|
627
|
-
* With `protocolVersion: '2026-07-28'`, stateless declarations and DNS rebinding
|
|
628
|
-
* protection remain supported. Session and response-mode options are rejected
|
|
629
|
-
* because they cannot configure the shared modern-era handler per request.
|
|
630
|
-
*/
|
|
631
|
-
options?: MCPServerStreamableHTTPOptions;
|
|
632
|
-
}): Promise<void>;
|
|
633
|
-
/**
|
|
634
|
-
* Handles a stateless, serverless HTTP request without session management.
|
|
635
|
-
*
|
|
636
|
-
* This method bypasses all session/transport state and handles each request independently.
|
|
637
|
-
* For serverless environments (Cloudflare Workers, Vercel Edge, etc.) where
|
|
638
|
-
* persistent connections and session state cannot be maintained across requests.
|
|
639
|
-
*
|
|
640
|
-
* Each request gets a fresh transport and server instance that are discarded after the response.
|
|
641
|
-
*
|
|
642
|
-
* @param req - Incoming HTTP request
|
|
643
|
-
* @param res - HTTP response object
|
|
644
|
-
* @param options - Transport options for this request
|
|
645
|
-
* @param options.enableJsonResponse - When `true` (default), buffers and returns a single
|
|
646
|
-
* JSON-RPC response. When `false`, the request is handled with request-scoped SSE streaming,
|
|
647
|
-
* so in-request `notifications/progress` reach the client before the final result.
|
|
648
|
-
* @private
|
|
649
|
-
*/
|
|
650
|
-
private handleServerlessRequest;
|
|
651
|
-
/**
|
|
652
|
-
* Establishes the SSE connection for the MCP server.
|
|
653
|
-
*
|
|
654
|
-
* This is a lower-level method called internally by `startSSE()`. In most cases,
|
|
655
|
-
* you should use `startSSE()` instead which handles both connection establishment
|
|
656
|
-
* and message routing.
|
|
657
|
-
*
|
|
658
|
-
* @param params - Connection parameters
|
|
659
|
-
* @param params.messagePath - Path for POST requests from the client
|
|
660
|
-
* @param params.res - HTTP response object for the SSE stream
|
|
661
|
-
* @throws {MastraError} If SSE connection establishment fails
|
|
662
|
-
*
|
|
663
|
-
* @example
|
|
664
|
-
* ```typescript
|
|
665
|
-
* // Usually called internally by startSSE()
|
|
666
|
-
* await server.connectSSE({
|
|
667
|
-
* messagePath: '/message',
|
|
668
|
-
* res: response
|
|
669
|
-
* });
|
|
670
|
-
* ```
|
|
671
|
-
*/
|
|
672
|
-
connectSSE({ messagePath, res, }: {
|
|
673
|
-
messagePath: string;
|
|
674
|
-
res: http.ServerResponse<http.IncomingMessage>;
|
|
675
|
-
}): Promise<void>;
|
|
676
|
-
/**
|
|
677
|
-
* Establishes the Hono SSE connection for the MCP server.
|
|
678
|
-
*
|
|
679
|
-
* This is a lower-level method called internally by `startHonoSSE()`. In most cases,
|
|
680
|
-
* you should use `startHonoSSE()` instead which handles both connection establishment
|
|
681
|
-
* and message routing.
|
|
682
|
-
*
|
|
683
|
-
* @param params - Connection parameters
|
|
684
|
-
* @param params.messagePath - Path for POST requests from the client
|
|
685
|
-
* @param params.stream - Hono SSE streaming API object
|
|
686
|
-
* @throws {MastraError} If Hono SSE connection establishment fails
|
|
687
|
-
*
|
|
688
|
-
* @example
|
|
689
|
-
* ```typescript
|
|
690
|
-
* // Usually called internally by startHonoSSE()
|
|
691
|
-
* await server.connectHonoSSE({
|
|
692
|
-
* messagePath: '/message',
|
|
693
|
-
* stream: sseStream
|
|
694
|
-
* });
|
|
695
|
-
* ```
|
|
696
|
-
*/
|
|
697
|
-
connectHonoSSE({ messagePath, stream }: {
|
|
698
|
-
messagePath: string;
|
|
699
|
-
stream: HonoSSEStreamingApi;
|
|
700
|
-
}): Promise<void>;
|
|
701
|
-
/**
|
|
702
|
-
* Closes the MCP server and releases all resources.
|
|
703
|
-
*
|
|
704
|
-
* This method cleanly shuts down all active transports (stdio, SSE, HTTP) and their
|
|
705
|
-
* associated connections. Call this when your application is shutting down.
|
|
706
|
-
*
|
|
707
|
-
* @throws {MastraError} If closing the server fails
|
|
708
|
-
*
|
|
709
|
-
* @example
|
|
710
|
-
* ```typescript
|
|
711
|
-
* // Graceful shutdown
|
|
712
|
-
* process.on('SIGTERM', async () => {
|
|
713
|
-
* await server.close();
|
|
714
|
-
* process.exit(0);
|
|
715
|
-
* });
|
|
716
|
-
* ```
|
|
145
|
+
* Handles one Streamable HTTP request at `httpPath`. Every request is
|
|
146
|
+
* self-contained; requests without a 2026-07-28 envelope are rejected.
|
|
717
147
|
*/
|
|
148
|
+
startHTTP({ url, httpPath, req, res, options }: MCPServerHTTPOptions): Promise<void>;
|
|
718
149
|
close(): Promise<void>;
|
|
719
|
-
/**
|
|
720
|
-
* Gets basic information about the server.
|
|
721
|
-
*
|
|
722
|
-
* Returns metadata including server ID, name, description, repository, and version details.
|
|
723
|
-
* This information conforms to the MCP Server schema.
|
|
724
|
-
*
|
|
725
|
-
* @returns Server information object
|
|
726
|
-
*
|
|
727
|
-
* @example
|
|
728
|
-
* ```typescript
|
|
729
|
-
* const info = server.getServerInfo();
|
|
730
|
-
* console.log(`${info.name} v${info.version_detail.version}`);
|
|
731
|
-
* // Output: My Weather Server v1.0.0
|
|
732
|
-
* ```
|
|
733
|
-
*/
|
|
734
150
|
getServerInfo(): ServerInfo;
|
|
735
|
-
/**
|
|
736
|
-
* Gets detailed information about the server including packaging and deployment metadata.
|
|
737
|
-
*
|
|
738
|
-
* Returns extended server information with package details, remotes, and deployment configurations.
|
|
739
|
-
* This information conforms to the MCP ServerDetail schema.
|
|
740
|
-
*
|
|
741
|
-
* @returns Detailed server information object
|
|
742
|
-
*
|
|
743
|
-
* @example
|
|
744
|
-
* ```typescript
|
|
745
|
-
* const detail = server.getServerDetail();
|
|
746
|
-
* console.log(detail.package_canonical); // 'npm'
|
|
747
|
-
* console.log(detail.packages); // Package installation info
|
|
748
|
-
* ```
|
|
749
|
-
*/
|
|
750
151
|
getServerDetail(): ServerDetailInfo;
|
|
751
|
-
private convertSchema;
|
|
752
|
-
private convertInputSchema;
|
|
753
|
-
/**
|
|
754
|
-
* Gets a list of all tools provided by this MCP server with their schemas.
|
|
755
|
-
*
|
|
756
|
-
* Returns information about all registered tools including explicit tools, agent-derived tools,
|
|
757
|
-
* and workflow-derived tools. Includes input/output schemas and tool types.
|
|
758
|
-
*
|
|
759
|
-
* @returns Object containing array of tool information
|
|
760
|
-
*
|
|
761
|
-
* @example
|
|
762
|
-
* ```typescript
|
|
763
|
-
* const toolList = server.getToolListInfo();
|
|
764
|
-
* toolList.tools.forEach(tool => {
|
|
765
|
-
* console.log(`${tool.name}: ${tool.description}`);
|
|
766
|
-
* console.log(`Type: ${tool.toolType || 'tool'}`);
|
|
767
|
-
* });
|
|
768
|
-
* ```
|
|
769
|
-
*/
|
|
770
152
|
getToolListInfo(requestContext?: RequestContext): {
|
|
771
|
-
tools:
|
|
772
|
-
name: string;
|
|
773
|
-
description?: string;
|
|
774
|
-
inputSchema: any;
|
|
775
|
-
outputSchema?: any;
|
|
776
|
-
toolType?: MCPToolType;
|
|
777
|
-
_meta?: Record<string, unknown>;
|
|
778
|
-
}>;
|
|
153
|
+
tools: ToolInfo[];
|
|
779
154
|
} | Promise<{
|
|
780
|
-
tools:
|
|
781
|
-
name: string;
|
|
782
|
-
description?: string;
|
|
783
|
-
inputSchema: any;
|
|
784
|
-
outputSchema?: any;
|
|
785
|
-
toolType?: MCPToolType;
|
|
786
|
-
_meta?: Record<string, unknown>;
|
|
787
|
-
}>;
|
|
155
|
+
tools: ToolInfo[];
|
|
788
156
|
}>;
|
|
157
|
+
getToolInfo(toolId: string): ToolInfo | undefined;
|
|
789
158
|
/**
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
* Returns undefined if the tool is not found.
|
|
794
|
-
*
|
|
795
|
-
* @param toolId - The ID/name of the tool to retrieve
|
|
796
|
-
* @returns Tool information object or undefined if not found
|
|
797
|
-
*
|
|
798
|
-
* @example
|
|
799
|
-
* ```typescript
|
|
800
|
-
* const toolInfo = server.getToolInfo('getWeather');
|
|
801
|
-
* if (toolInfo) {
|
|
802
|
-
* console.log(toolInfo.description);
|
|
803
|
-
* console.log(toolInfo.inputSchema);
|
|
804
|
-
* }
|
|
805
|
-
* ```
|
|
806
|
-
*/
|
|
807
|
-
getToolInfo(toolId: string): {
|
|
808
|
-
name: string;
|
|
809
|
-
description?: string;
|
|
810
|
-
inputSchema: any;
|
|
811
|
-
outputSchema?: any;
|
|
812
|
-
toolType?: MCPToolType;
|
|
813
|
-
_meta?: Record<string, unknown>;
|
|
814
|
-
} | undefined;
|
|
815
|
-
private createProxiedRequestContext;
|
|
816
|
-
private resolveMappedFGAUser;
|
|
817
|
-
private getAuthorizedConvertedToolEntries;
|
|
818
|
-
private enforceToolExecutionFGA;
|
|
819
|
-
private resolveToolFGAParams;
|
|
820
|
-
/**
|
|
821
|
-
* Executes a specific tool provided by this MCP server.
|
|
822
|
-
*
|
|
823
|
-
* This method validates the tool arguments against the input schema and executes the tool.
|
|
824
|
-
* If validation fails, returns an error object instead of throwing.
|
|
825
|
-
*
|
|
826
|
-
* @param toolId - The ID/name of the tool to execute
|
|
827
|
-
* @param args - The arguments to pass to the tool's execute function
|
|
828
|
-
* @param executionContext - Optional context including messages and toolCallId
|
|
829
|
-
* @returns Promise resolving to the tool execution result
|
|
830
|
-
* @throws {MastraError} If the tool is not found or execution fails
|
|
831
|
-
*
|
|
832
|
-
* @example
|
|
833
|
-
* ```typescript
|
|
834
|
-
* const result = await server.executeTool(
|
|
835
|
-
* 'getWeather',
|
|
836
|
-
* { location: 'London' },
|
|
837
|
-
* { toolCallId: 'call_123' }
|
|
838
|
-
* );
|
|
839
|
-
* console.log(result);
|
|
840
|
-
* ```
|
|
841
|
-
*/
|
|
842
|
-
executeTool(toolId: string, args: any, executionContext?: {
|
|
843
|
-
messages?: any[];
|
|
844
|
-
toolCallId?: string;
|
|
845
|
-
requestContext?: RequestContext;
|
|
846
|
-
}): Promise<any>;
|
|
847
|
-
/**
|
|
848
|
-
* Reads the content of a resource by URI.
|
|
849
|
-
*
|
|
850
|
-
* Used by the Studio API to proxy `ui://` resource reads for MCP Apps rendering.
|
|
851
|
-
*
|
|
852
|
-
* @param uri - The resource URI to read (e.g. `ui://weather/dashboard`)
|
|
853
|
-
* @returns Promise resolving to the resource content
|
|
159
|
+
* Runs a tool without a protocol client (the Studio/REST route). A tool that
|
|
160
|
+
* suspends is reported as such; the caller continues by sending the same
|
|
161
|
+
* arguments with `resumeData` and `suspendPayload`.
|
|
854
162
|
*/
|
|
163
|
+
executeTool(toolId: string, args: unknown, executionContext?: Parameters<MCPServerBase['executeTool']>[2]): Promise<MCPToolExecutionResultV2>;
|
|
164
|
+
/** Reads an `ui://` app resource; application resources require a protocol request. */
|
|
855
165
|
readResource(uri: string): Promise<{
|
|
856
166
|
contents: Array<{
|
|
857
167
|
uri: string;
|
|
@@ -859,16 +169,10 @@ export declare class MCPServer extends MCPServerBase {
|
|
|
859
169
|
blob?: string;
|
|
860
170
|
}>;
|
|
861
171
|
}>;
|
|
862
|
-
/**
|
|
863
|
-
* Lists all resources available on this MCP server.
|
|
864
|
-
*
|
|
865
|
-
* Used by the Studio API to discover `ui://` resources for MCP Apps.
|
|
866
|
-
*
|
|
867
|
-
* @returns Promise resolving to the list of resources
|
|
868
|
-
*/
|
|
172
|
+
/** Lists `ui://` app resources; application resources require a protocol request. */
|
|
869
173
|
listResources(): Promise<{
|
|
870
174
|
resources: Resource[];
|
|
871
175
|
}>;
|
|
872
176
|
}
|
|
873
|
-
export {};
|
|
177
|
+
export { ServerPromptActions, ServerResourceActions, ServerToolActions };
|
|
874
178
|
//# sourceMappingURL=server.d.ts.map
|