@mastra/mcp 0.13.3 → 0.13.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.
@@ -5,14 +5,33 @@ interface ServerPromptActionsDependencies {
5
5
  getSdkServer: () => Server;
6
6
  clearDefinedPrompts: () => void;
7
7
  }
8
+ /**
9
+ * Server-side prompt actions for notifying clients about prompt changes.
10
+ *
11
+ * This class provides methods for MCP servers to notify connected clients when
12
+ * the list of available prompts changes.
13
+ */
8
14
  export declare class ServerPromptActions {
9
15
  private readonly getLogger;
10
16
  private readonly getSdkServer;
11
17
  private readonly clearDefinedPrompts;
18
+ /**
19
+ * @internal
20
+ */
12
21
  constructor(dependencies: ServerPromptActionsDependencies);
13
22
  /**
14
- * Notifies the server that the overall list of available prompts has changed.
15
- * This will clear the internal cache of defined prompts and send a list_changed notification to clients.
23
+ * Notifies clients that the overall list of available prompts has changed.
24
+ *
25
+ * This clears the internal prompt cache and sends a `notifications/prompts/list_changed`
26
+ * message to all clients, prompting them to re-fetch the prompt list.
27
+ *
28
+ * @throws {MastraError} If sending the notification fails
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * // After adding or modifying prompts
33
+ * await server.prompts.notifyListChanged();
34
+ * ```
16
35
  */
17
36
  notifyListChanged(): Promise<void>;
18
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,UAAU,+BAA+B;IACvC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAa;gBAErC,YAAY,EAAE,+BAA+B;IAMzD;;;OAGG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAsBhD"}
1
+ {"version":3,"file":"promptActions.d.ts","sourceRoot":"","sources":["../../src/server/promptActions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,UAAU,+BAA+B;IACvC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAa;IAEjD;;OAEG;gBACS,YAAY,EAAE,+BAA+B;IAMzD;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAsBhD"}
@@ -7,23 +7,54 @@ interface ServerResourceActionsDependencies {
7
7
  clearDefinedResources: () => void;
8
8
  clearDefinedResourceTemplates: () => void;
9
9
  }
10
+ /**
11
+ * Server-side resource actions for notifying clients about resource changes.
12
+ *
13
+ * This class provides methods for MCP servers to notify connected clients when
14
+ * resources are updated or when the resource list changes.
15
+ */
10
16
  export declare class ServerResourceActions {
11
17
  private readonly getSubscriptions;
12
18
  private readonly getLogger;
13
19
  private readonly getSdkServer;
14
20
  private readonly clearDefinedResources;
15
21
  private readonly clearDefinedResourceTemplates;
22
+ /**
23
+ * @internal
24
+ */
16
25
  constructor(dependencies: ServerResourceActionsDependencies);
17
26
  /**
18
- * Checks if any resources have been updated.
19
- * If the resource is subscribed to by clients, an update notification will be sent.
27
+ * Notifies subscribed clients that a specific resource has been updated.
28
+ *
29
+ * If clients are subscribed to the resource URI, they will receive a
30
+ * `notifications/resources/updated` message to re-fetch the resource content.
31
+ *
32
+ * @param params - Notification parameters
33
+ * @param params.uri - URI of the resource that was updated
34
+ * @throws {MastraError} If sending the notification fails
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // After updating a file resource
39
+ * await server.resources.notifyUpdated({ uri: 'file://data.txt' });
40
+ * ```
20
41
  */
21
42
  notifyUpdated({ uri }: {
22
43
  uri: string;
23
44
  }): Promise<void>;
24
45
  /**
25
- * Notifies the server that the overall list of available resources has changed.
26
- * This will clear the internal cache of defined resources and send a list_changed notification to clients.
46
+ * Notifies clients that the overall list of available resources has changed.
47
+ *
48
+ * This clears the internal resource cache and sends a `notifications/resources/list_changed`
49
+ * message to all clients, prompting them to re-fetch the resource list.
50
+ *
51
+ * @throws {MastraError} If sending the notification fails
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // After adding a new resource to your resource handler
56
+ * await server.resources.notifyListChanged();
57
+ * ```
27
58
  */
28
59
  notifyListChanged(): Promise<void>;
29
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/server/resourceActions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE,UAAU,iCAAiC;IACzC,gBAAgB,EAAE,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,aAAa,CAAC;IAC/B,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,6BAA6B,EAAE,MAAM,IAAI,CAAC;CAC3C;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,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G,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BnE;;;;;;;;;;;;;OAaG;IACU,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAyBhD"}
@@ -12,6 +12,34 @@ import { SSETransport } from 'hono-mcp-server-sse-transport';
12
12
  import { ServerPromptActions } from './promptActions.js';
13
13
  import { ServerResourceActions } from './resourceActions.js';
14
14
  import type { MCPServerPrompts, MCPServerResources, ElicitationActions } from './types.js';
15
+ /**
16
+ * MCPServer exposes Mastra tools, agents, and workflows as a Model Context Protocol (MCP) server.
17
+ *
18
+ * This class allows any MCP client (like Cursor, Windsurf, or Claude Desktop) to connect and use your
19
+ * Mastra capabilities. It supports both stdio (subprocess) and SSE (HTTP) MCP transports.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { MCPServer } from '@mastra/mcp';
24
+ * import { createTool } from '@mastra/core/tools';
25
+ * import { z } from 'zod';
26
+ *
27
+ * const weatherTool = createTool({
28
+ * id: 'getWeather',
29
+ * description: 'Gets the current weather for a location.',
30
+ * inputSchema: z.object({ location: z.string() }),
31
+ * execute: async ({ context }) => `Weather in ${context.location} is sunny.`,
32
+ * });
33
+ *
34
+ * const server = new MCPServer({
35
+ * name: 'My Weather Server',
36
+ * version: '1.0.0',
37
+ * tools: { weatherTool },
38
+ * });
39
+ *
40
+ * await server.startStdio();
41
+ * ```
42
+ */
15
43
  export declare class MCPServer extends MCPServerBase {
16
44
  private server;
17
45
  private stdioTransport?;
@@ -26,28 +54,126 @@ export declare class MCPServer extends MCPServerBase {
26
54
  private promptOptions?;
27
55
  private subscriptions;
28
56
  private currentLoggingLevel;
57
+ /**
58
+ * Provides methods to notify clients about resource changes.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Notify that a specific resource was updated
63
+ * await server.resources.notifyUpdated({ uri: 'file://data.txt' });
64
+ *
65
+ * // Notify that the resource list changed
66
+ * await server.resources.notifyListChanged();
67
+ * ```
68
+ */
29
69
  readonly resources: ServerResourceActions;
70
+ /**
71
+ * Provides methods to notify clients about prompt changes.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Notify that the prompt list changed
76
+ * await server.prompts.notifyListChanged();
77
+ * ```
78
+ */
30
79
  readonly prompts: ServerPromptActions;
80
+ /**
81
+ * Provides methods for interactive user input collection during tool execution.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Within a tool's execute function
86
+ * const result = await options.elicitation.sendRequest({
87
+ * message: 'Please provide your email address',
88
+ * requestedSchema: {
89
+ * type: 'object',
90
+ * properties: {
91
+ * email: { type: 'string', format: 'email' }
92
+ * },
93
+ * required: ['email']
94
+ * }
95
+ * });
96
+ * ```
97
+ */
31
98
  readonly elicitation: ElicitationActions;
32
99
  /**
33
- * Get the current stdio transport.
100
+ * Gets the stdio transport instance if the server was started using stdio.
101
+ *
102
+ * This is primarily for internal checks or testing purposes.
103
+ *
104
+ * @returns The stdio transport instance, or undefined if not using stdio transport
34
105
  */
35
106
  getStdioTransport(): StdioServerTransport | undefined;
36
107
  /**
37
- * Get the current SSE transport.
108
+ * Gets the SSE transport instance if the server was started using SSE.
109
+ *
110
+ * This is primarily for internal checks or testing purposes.
111
+ *
112
+ * @returns The SSE transport instance, or undefined if not using SSE transport
38
113
  */
39
114
  getSseTransport(): SSEServerTransport | undefined;
40
115
  /**
41
- * Get the current SSE Hono transport.
116
+ * Gets the Hono SSE transport instance for a specific session.
117
+ *
118
+ * This is primarily for internal checks or testing purposes.
119
+ *
120
+ * @param sessionId - The session identifier
121
+ * @returns The Hono SSE transport instance, or undefined if session not found
42
122
  */
43
123
  getSseHonoTransport(sessionId: string): SSETransport | undefined;
44
124
  /**
45
- * Get the current server instance.
125
+ * Gets the underlying MCP SDK Server instance.
126
+ *
127
+ * This provides access to the low-level server instance for advanced use cases.
128
+ *
129
+ * @returns The Server instance from @modelcontextprotocol/sdk
46
130
  */
47
131
  getServer(): Server;
48
132
  /**
49
- * Construct a new MCPServer instance.
50
- * @param opts - Configuration options for the server, including registry metadata.
133
+ * Creates a new MCPServer instance.
134
+ *
135
+ * The server exposes tools, agents, and workflows to MCP clients. Agents are automatically
136
+ * converted to tools named `ask_<agentKey>`, and workflows become tools named `run_<workflowKey>`.
137
+ *
138
+ * @param opts - Configuration options for the server
139
+ * @param opts.name - Descriptive name for the server (e.g., 'My Weather Server')
140
+ * @param opts.version - Semantic version of the server (e.g., '1.0.0')
141
+ * @param opts.tools - Object mapping tool names to tool definitions
142
+ * @param opts.agents - Optional object mapping agent identifiers to Agent instances
143
+ * @param opts.workflows - Optional object mapping workflow identifiers to Workflow instances
144
+ * @param opts.resources - Optional resource configuration for exposing data and content
145
+ * @param opts.prompts - Optional prompt configuration for exposing reusable templates
146
+ * @param opts.id - Optional unique identifier (generated if not provided)
147
+ * @param opts.description - Optional description of what the server does
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { MCPServer } from '@mastra/mcp';
152
+ * import { Agent } from '@mastra/core/agent';
153
+ * import { createTool } from '@mastra/core/tools';
154
+ * import { z } from 'zod';
155
+ *
156
+ * const myAgent = new Agent({
157
+ * name: 'Helper',
158
+ * description: 'A helpful assistant',
159
+ * instructions: 'You are helpful.',
160
+ * model: openai('gpt-4o-mini'),
161
+ * });
162
+ *
163
+ * const server = new MCPServer({
164
+ * name: 'My Server',
165
+ * version: '1.0.0',
166
+ * tools: {
167
+ * weatherTool: createTool({
168
+ * id: 'getWeather',
169
+ * description: 'Gets weather',
170
+ * inputSchema: z.object({ location: z.string() }),
171
+ * execute: async ({ context }) => `Sunny in ${context.location}`,
172
+ * })
173
+ * },
174
+ * agents: { myAgent },
175
+ * });
176
+ * ```
51
177
  */
52
178
  constructor(opts: MCPServerConfig & {
53
179
  resources?: MCPServerResources;
@@ -92,39 +218,135 @@ export declare class MCPServer extends MCPServerBase {
92
218
  */
93
219
  convertTools(tools: ToolsInput, agentsConfig?: Record<string, Agent>, workflowsConfig?: Record<string, Workflow>): Record<string, ConvertedTool>;
94
220
  /**
95
- * Start the MCP server using stdio transport (for Windsurf integration).
221
+ * Starts the MCP server using standard input/output (stdio) transport.
222
+ *
223
+ * This is typically used when running the server as a command-line program that MCP clients
224
+ * spawn as a subprocess (e.g., integration with Windsurf, Cursor, or Claude Desktop).
225
+ *
226
+ * @throws {MastraError} If the stdio connection fails
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * const server = new MCPServer({
231
+ * name: 'My Server',
232
+ * version: '1.0.0',
233
+ * tools: { weatherTool },
234
+ * });
235
+ *
236
+ * await server.startStdio();
237
+ * ```
96
238
  */
97
239
  startStdio(): Promise<void>;
98
240
  /**
99
- * Handles MCP-over-SSE protocol for user-provided HTTP servers.
100
- * Call this from your HTTP server for both the SSE and message endpoints.
241
+ * Integrates the MCP server with an existing HTTP server using Server-Sent Events (SSE).
101
242
  *
102
- * @param url Parsed URL of the incoming request
103
- * @param ssePath Path for establishing the SSE connection (e.g. '/sse')
104
- * @param messagePath Path for POSTing client messages (e.g. '/message')
105
- * @param req Incoming HTTP request
106
- * @param res HTTP response (must support .write/.end)
243
+ * Call this method from your web server's request handler for both the SSE and message paths.
244
+ * This enables web-based MCP clients to connect to your server.
245
+ *
246
+ * @param options - Configuration for SSE integration
247
+ * @param options.url - Parsed URL of the incoming request
248
+ * @param options.ssePath - Path for establishing SSE connection (e.g., '/sse')
249
+ * @param options.messagePath - Path for POSTing client messages (e.g., '/message')
250
+ * @param options.req - Incoming HTTP request object
251
+ * @param options.res - HTTP response object (must support .write/.end)
252
+ *
253
+ * @throws {MastraError} If SSE connection setup fails
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import http from 'http';
258
+ *
259
+ * const httpServer = http.createServer(async (req, res) => {
260
+ * await server.startSSE({
261
+ * url: new URL(req.url || '', `http://localhost:1234`),
262
+ * ssePath: '/sse',
263
+ * messagePath: '/message',
264
+ * req,
265
+ * res,
266
+ * });
267
+ * });
268
+ *
269
+ * httpServer.listen(1234, () => {
270
+ * console.log('MCP server listening on http://localhost:1234/sse');
271
+ * });
272
+ * ```
107
273
  */
108
274
  startSSE({ url, ssePath, messagePath, req, res }: MCPServerSSEOptions): Promise<void>;
109
275
  /**
110
- * Handles MCP-over-SSE protocol for user-provided HTTP servers.
111
- * Call this from your HTTP server for both the SSE and message endpoints.
276
+ * Integrates the MCP server with a Hono web framework using Server-Sent Events (SSE).
277
+ *
278
+ * Call this method from your Hono server's request handler for both the SSE and message paths.
279
+ * This enables Hono-based web applications to expose MCP servers.
280
+ *
281
+ * @param options - Configuration for Hono SSE integration
282
+ * @param options.url - Parsed URL of the incoming request
283
+ * @param options.ssePath - Path for establishing SSE connection (e.g., '/hono-sse')
284
+ * @param options.messagePath - Path for POSTing client messages (e.g., '/message')
285
+ * @param options.context - Hono context object
286
+ *
287
+ * @throws {MastraError} If Hono SSE connection setup fails
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * import { Hono } from 'hono';
112
292
  *
113
- * @param url Parsed URL of the incoming request
114
- * @param ssePath Path for establishing the SSE connection (e.g. '/sse')
115
- * @param messagePath Path for POSTing client messages (e.g. '/message')
116
- * @param context Incoming Hono context
293
+ * const app = new Hono();
294
+ *
295
+ * app.all('*', async (c) => {
296
+ * const url = new URL(c.req.url);
297
+ * return await server.startHonoSSE({
298
+ * url,
299
+ * ssePath: '/hono-sse',
300
+ * messagePath: '/message',
301
+ * context: c,
302
+ * });
303
+ * });
304
+ *
305
+ * export default app;
306
+ * ```
117
307
  */
118
308
  startHonoSSE({ url, ssePath, messagePath, context }: MCPServerHonoSSEOptions): Promise<Response>;
119
309
  /**
120
- * Handles MCP-over-StreamableHTTP protocol for user-provided HTTP servers.
121
- * Call this from your HTTP server for the streamable HTTP endpoint.
310
+ * Integrates the MCP server with an existing HTTP server using streamable HTTP transport.
311
+ *
312
+ * This is the recommended modern transport method, providing better session management and
313
+ * reliability compared to SSE. Call this from your HTTP server's request handler.
314
+ *
315
+ * @param options - Configuration for HTTP integration
316
+ * @param options.url - Parsed URL of the incoming request
317
+ * @param options.httpPath - Path for the MCP endpoint (e.g., '/mcp')
318
+ * @param options.req - Incoming HTTP request (http.IncomingMessage)
319
+ * @param options.res - HTTP response object (http.ServerResponse)
320
+ * @param options.options - Optional transport options
321
+ * @param options.options.sessionIdGenerator - Function to generate unique session IDs (defaults to randomUUID)
322
+ * @param options.options.onsessioninitialized - Callback when a new session is initialized
323
+ * @param options.options.enableJsonResponse - If true, return JSON instead of SSE streaming
324
+ * @param options.options.eventStore - Event store for message resumability
325
+ *
326
+ * @throws {MastraError} If HTTP connection setup fails
122
327
  *
123
- * @param url Parsed URL of the incoming request
124
- * @param httpPath Path for establishing the streamable HTTP connection (e.g. '/mcp')
125
- * @param req Incoming HTTP request
126
- * @param res HTTP response (must support .write/.end)
127
- * @param options Optional options to pass to the transport (e.g. sessionIdGenerator)
328
+ * @example
329
+ * ```typescript
330
+ * import http from 'http';
331
+ * import { randomUUID } from 'crypto';
332
+ *
333
+ * const httpServer = http.createServer(async (req, res) => {
334
+ * await server.startHTTP({
335
+ * url: new URL(req.url || '', 'http://localhost:1234'),
336
+ * httpPath: '/mcp',
337
+ * req,
338
+ * res,
339
+ * options: {
340
+ * sessionIdGenerator: () => randomUUID(),
341
+ * onsessioninitialized: (sessionId) => {
342
+ * console.log(`New MCP session: ${sessionId}`);
343
+ * },
344
+ * },
345
+ * });
346
+ * });
347
+ *
348
+ * httpServer.listen(1234);
349
+ * ```
128
350
  */
129
351
  startHTTP({ url, httpPath, req, res, options, }: {
130
352
  url: URL;
@@ -133,32 +355,122 @@ export declare class MCPServer extends MCPServerBase {
133
355
  res: http.ServerResponse<http.IncomingMessage>;
134
356
  options?: StreamableHTTPServerTransportOptions;
135
357
  }): Promise<void>;
358
+ /**
359
+ * Establishes the SSE connection for the MCP server.
360
+ *
361
+ * This is a lower-level method called internally by `startSSE()`. In most cases,
362
+ * you should use `startSSE()` instead which handles both connection establishment
363
+ * and message routing.
364
+ *
365
+ * @param params - Connection parameters
366
+ * @param params.messagePath - Path for POST requests from the client
367
+ * @param params.res - HTTP response object for the SSE stream
368
+ * @throws {MastraError} If SSE connection establishment fails
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * // Usually called internally by startSSE()
373
+ * await server.connectSSE({
374
+ * messagePath: '/message',
375
+ * res: response
376
+ * });
377
+ * ```
378
+ */
136
379
  connectSSE({ messagePath, res, }: {
137
380
  messagePath: string;
138
381
  res: http.ServerResponse<http.IncomingMessage>;
139
382
  }): Promise<void>;
383
+ /**
384
+ * Establishes the Hono SSE connection for the MCP server.
385
+ *
386
+ * This is a lower-level method called internally by `startHonoSSE()`. In most cases,
387
+ * you should use `startHonoSSE()` instead which handles both connection establishment
388
+ * and message routing.
389
+ *
390
+ * @param params - Connection parameters
391
+ * @param params.messagePath - Path for POST requests from the client
392
+ * @param params.stream - Hono SSE streaming API object
393
+ * @throws {MastraError} If Hono SSE connection establishment fails
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * // Usually called internally by startHonoSSE()
398
+ * await server.connectHonoSSE({
399
+ * messagePath: '/message',
400
+ * stream: sseStream
401
+ * });
402
+ * ```
403
+ */
140
404
  connectHonoSSE({ messagePath, stream }: {
141
405
  messagePath: string;
142
406
  stream: SSEStreamingApi;
143
407
  }): Promise<void>;
144
408
  /**
145
- * Close the MCP server and all its connections
409
+ * Closes the MCP server and releases all resources.
410
+ *
411
+ * This method cleanly shuts down all active transports (stdio, SSE, HTTP) and their
412
+ * associated connections. Call this when your application is shutting down.
413
+ *
414
+ * @throws {MastraError} If closing the server fails
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * // Graceful shutdown
419
+ * process.on('SIGTERM', async () => {
420
+ * await server.close();
421
+ * process.exit(0);
422
+ * });
423
+ * ```
146
424
  */
147
425
  close(): Promise<void>;
148
426
  /**
149
- * Gets the basic information about the server, conforming to the Server schema.
150
- * @returns ServerInfo object.
427
+ * Gets basic information about the server.
428
+ *
429
+ * Returns metadata including server ID, name, description, repository, and version details.
430
+ * This information conforms to the MCP Server schema.
431
+ *
432
+ * @returns Server information object
433
+ *
434
+ * @example
435
+ * ```typescript
436
+ * const info = server.getServerInfo();
437
+ * console.log(`${info.name} v${info.version_detail.version}`);
438
+ * // Output: My Weather Server v1.0.0
439
+ * ```
151
440
  */
152
441
  getServerInfo(): ServerInfo;
153
442
  /**
154
- * Gets detailed information about the server, conforming to the ServerDetail schema.
155
- * @returns ServerDetailInfo object.
443
+ * Gets detailed information about the server including packaging and deployment metadata.
444
+ *
445
+ * Returns extended server information with package details, remotes, and deployment configurations.
446
+ * This information conforms to the MCP ServerDetail schema.
447
+ *
448
+ * @returns Detailed server information object
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const detail = server.getServerDetail();
453
+ * console.log(detail.package_canonical); // 'npm'
454
+ * console.log(detail.packages); // Package installation info
455
+ * ```
156
456
  */
157
457
  getServerDetail(): ServerDetailInfo;
158
458
  /**
159
- * Gets a list of tools provided by this MCP server, including their schemas.
160
- * This leverages the same tool information used by the internal ListTools MCP request.
161
- * @returns An object containing an array of tool information.
459
+ * Gets a list of all tools provided by this MCP server with their schemas.
460
+ *
461
+ * Returns information about all registered tools including explicit tools, agent-derived tools,
462
+ * and workflow-derived tools. Includes input/output schemas and tool types.
463
+ *
464
+ * @returns Object containing array of tool information
465
+ *
466
+ * @example
467
+ * ```typescript
468
+ * const toolList = server.getToolListInfo();
469
+ * toolList.tools.forEach(tool => {
470
+ * console.log(`${tool.name}: ${tool.description}`);
471
+ * console.log(`Type: ${tool.toolType || 'tool'}`);
472
+ * });
473
+ * ```
162
474
  */
163
475
  getToolListInfo(): {
164
476
  tools: Array<{
@@ -171,8 +483,21 @@ export declare class MCPServer extends MCPServerBase {
171
483
  };
172
484
  /**
173
485
  * Gets information for a specific tool provided by this MCP server.
174
- * @param toolId The ID/name of the tool to retrieve.
175
- * @returns Tool information (name, description, inputSchema) or undefined if not found.
486
+ *
487
+ * Returns detailed information about a single tool including its name, description, schemas, and type.
488
+ * Returns undefined if the tool is not found.
489
+ *
490
+ * @param toolId - The ID/name of the tool to retrieve
491
+ * @returns Tool information object or undefined if not found
492
+ *
493
+ * @example
494
+ * ```typescript
495
+ * const toolInfo = server.getToolInfo('getWeather');
496
+ * if (toolInfo) {
497
+ * console.log(toolInfo.description);
498
+ * console.log(toolInfo.inputSchema);
499
+ * }
500
+ * ```
176
501
  */
177
502
  getToolInfo(toolId: string): {
178
503
  name: string;
@@ -183,11 +508,25 @@ export declare class MCPServer extends MCPServerBase {
183
508
  } | undefined;
184
509
  /**
185
510
  * Executes a specific tool provided by this MCP server.
186
- * @param toolId The ID/name of the tool to execute.
187
- * @param args The arguments to pass to the tool's execute function.
188
- * @param executionContext Optional context for the tool execution.
189
- * @returns A promise that resolves to the result of the tool execution.
190
- * @throws Error if the tool is not found, validation fails, or execution fails.
511
+ *
512
+ * This method validates the tool arguments against the input schema and executes the tool.
513
+ * If validation fails, returns an error object instead of throwing.
514
+ *
515
+ * @param toolId - The ID/name of the tool to execute
516
+ * @param args - The arguments to pass to the tool's execute function
517
+ * @param executionContext - Optional context including messages and toolCallId
518
+ * @returns Promise resolving to the tool execution result
519
+ * @throws {MastraError} If the tool is not found or execution fails
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * const result = await server.executeTool(
524
+ * 'getWeather',
525
+ * { location: 'London' },
526
+ * { toolCallId: 'call_123' }
527
+ * );
528
+ * console.log(result);
529
+ * ```
191
530
  */
192
531
  executeTool(toolId: string, args: any, executionContext?: {
193
532
  messages?: any[];
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AACA,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,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EAC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