@mastra/mcp 0.10.2 → 0.10.3-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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/mcp@0.10.2-alpha.1 build /home/runner/work/mastra/mastra/packages/mcp
2
+ > @mastra/mcp@0.10.3-alpha.0 build /home/runner/work/mastra/mastra/packages/mcp
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.4.0
7
+ CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 18165ms
9
+ TSC ⚡️ Build success in 21509ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/packages/mcp/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 17929ms
16
+ DTS ⚡️ Build success in 23126ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 58.42 KB
21
- ESM ⚡️ Build success in 582ms
22
- CJS dist/index.cjs 58.63 KB
23
- CJS ⚡️ Build success in 807ms
20
+ CJS dist/index.cjs 67.33 KB
21
+ CJS ⚡️ Build success in 1667ms
22
+ ESM dist/index.js 67.20 KB
23
+ ESM ⚡️ Build success in 1667ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 0.10.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fc579cd: [MASTRA-3554] Support MCP prompts for MCPServer and MCPClient
8
+ - Updated dependencies [f6fd25f]
9
+ - Updated dependencies [dffb67b]
10
+ - Updated dependencies [f1309d3]
11
+ - Updated dependencies [f7f8293]
12
+ - @mastra/core@0.10.4-alpha.1
13
+
3
14
  ## 0.10.2
4
15
 
5
16
  ### Patch Changes
package/README.md CHANGED
@@ -346,6 +346,38 @@ if (resources.weather) {
346
346
 
347
347
  The `getResources()` method handles errors gracefully - if a server fails or doesn't support resources, it will be omitted from the results without causing the entire operation to fail.
348
348
 
349
+ ## Prompts
350
+
351
+ MCP servers can also expose prompts, which represent structured message templates or conversational context for agents.
352
+
353
+ ### Listing Prompts
354
+
355
+ ```typescript
356
+ const prompts = await mcp.prompts.list();
357
+ console.log(prompts.weather); // [ { name: 'current', ... }, ... ]
358
+ ```
359
+
360
+ ### Getting a Prompt and Messages
361
+
362
+ ```typescript
363
+ const { prompt, messages } = await mcp.prompts.get({ serverName: 'weather', name: 'current' });
364
+ console.log(prompt); // { name: 'current', version: 'v1', ... }
365
+ console.log(messages); // [ { role: 'assistant', content: { type: 'text', text: '...' } }, ... ]
366
+ ```
367
+
368
+ ### Handling Prompt List Change Notifications
369
+
370
+ ```typescript
371
+ mcp.prompts.onListChanged({
372
+ serverName: 'weather',
373
+ handler: () => {
374
+ // Refresh prompt list or update UI
375
+ },
376
+ });
377
+ ```
378
+
379
+ Prompt notifications are delivered via SSE or compatible transports. Register handlers before expecting notifications.
380
+
349
381
  ## SSE Authentication and Headers (Legacy Fallback)
350
382
 
351
383
  When the client falls back to using the legacy SSE (Server-Sent Events) transport and you need to include authentication or custom headers, you need to configure headers in a specific way. The standard `requestInit` headers won't work alone because SSE connections using the browser's `EventSource` API don't support custom headers directly.
@@ -1,8 +1,10 @@
1
1
  import { Agent } from '@mastra/core/agent';
2
2
  import type { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
3
3
  import type { ConvertedTool } from '@mastra/core/mcp';
4
+ import type { GetPromptResult } from '@modelcontextprotocol/sdk/types.js';
4
5
  import type * as http from 'node:http';
5
6
  import type { IMastraLogger } from '@mastra/core/logger';
7
+ import type { ListPromptsResult } from '@modelcontextprotocol/sdk/types.js';
6
8
  import { LoggingLevel } from '@modelcontextprotocol/sdk/types.js';
7
9
  import { MastraBase } from '@mastra/core/base';
8
10
  import { MCPServerBase } from '@mastra/core/mcp';
@@ -13,6 +15,8 @@ import type { MCPToolType } from '@mastra/core/mcp';
13
15
  import { objectInputType } from 'zod';
14
16
  import { objectOutputType } from 'zod';
15
17
  import { objectUtil } from 'zod';
18
+ import type { Prompt } from '@modelcontextprotocol/sdk/types.js';
19
+ import type { PromptMessage } from '@modelcontextprotocol/sdk/types.js';
16
20
  import type { Resource } from '@modelcontextprotocol/sdk/types.js';
17
21
  import type { ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
18
22
  import { ResourceUpdatedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
@@ -70,6 +74,7 @@ export declare class InternalMastraMCPClient extends MastraBase {
70
74
  private transport?;
71
75
  private currentOperationContext;
72
76
  readonly resources: ResourceClientActions;
77
+ readonly prompts: PromptClientActions;
73
78
  constructor({ name, version, server, capabilities, timeout, }: InternalMastraMCPClientOptions);
74
79
  /**
75
80
  * Log a message at the specified level
@@ -170,6 +175,26 @@ export declare class InternalMastraMCPClient extends MastraBase {
170
175
  mimeType: z.ZodOptional<z.ZodString>;
171
176
  }, z.ZodTypeAny, "passthrough">>, "many">;
172
177
  }, z.ZodTypeAny, "passthrough">>;
178
+ /**
179
+ * Fetch the list of available prompts from the MCP server.
180
+ */
181
+ listPrompts(): Promise<ListPromptsResult>;
182
+ /**
183
+ * Get a prompt and its dynamic messages from the server.
184
+ * @param name The prompt name
185
+ * @param args Arguments for the prompt
186
+ * @param version (optional) The prompt version to retrieve
187
+ */
188
+ getPrompt({ name, args, version }: {
189
+ name: string;
190
+ args?: Record<string, any>;
191
+ version?: string;
192
+ }): Promise<GetPromptResult>;
193
+ /**
194
+ * Register a handler to be called when the prompt list changes on the server.
195
+ * Use this to refresh cached prompt lists in the client/UI if needed.
196
+ */
197
+ setPromptListChangedNotificationHandler(handler: () => void): void;
173
198
  setResourceUpdatedNotificationHandler(handler: (params: z.infer<typeof ResourceUpdatedNotificationSchema>['params']) => void): void;
174
199
  setResourceListChangedNotificationHandler(handler: () => void): void;
175
200
  private convertInputSchema;
@@ -186,10 +211,12 @@ export declare type InternalMastraMCPClientOptions = {
186
211
 
187
212
  export { LoggingLevel }
188
213
  export { LoggingLevel as LoggingLevel_alias_1 }
214
+ export { LoggingLevel as LoggingLevel_alias_2 }
189
215
 
190
216
  declare type LogHandler = (logMessage: LogMessage) => void;
191
217
  export { LogHandler }
192
218
  export { LogHandler as LogHandler_alias_1 }
219
+ export { LogHandler as LogHandler_alias_2 }
193
220
 
194
221
  declare interface LogMessage {
195
222
  level: LoggingLevel;
@@ -201,6 +228,7 @@ declare interface LogMessage {
201
228
  }
202
229
  export { LogMessage }
203
230
  export { LogMessage as LogMessage_alias_1 }
231
+ export { LogMessage as LogMessage_alias_2 }
204
232
 
205
233
  /**
206
234
  * @deprecated MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.
@@ -210,10 +238,12 @@ declare class MastraMCPClient extends InternalMastraMCPClient {
210
238
  }
211
239
  export { MastraMCPClient }
212
240
  export { MastraMCPClient as MastraMCPClient_alias_1 }
241
+ export { MastraMCPClient as MastraMCPClient_alias_2 }
213
242
 
214
243
  declare type MastraMCPServerDefinition = StdioServerDefinition | HttpServerDefinition;
215
244
  export { MastraMCPServerDefinition }
216
245
  export { MastraMCPServerDefinition as MastraMCPServerDefinition_alias_1 }
246
+ export { MastraMCPServerDefinition as MastraMCPServerDefinition_alias_2 }
217
247
 
218
248
  declare class MCPClient extends MastraBase {
219
249
  private serverConfigs;
@@ -267,6 +297,55 @@ declare class MCPClient extends MastraBase {
267
297
  }) => void) => Promise<void>;
268
298
  onListChanged: (serverName: string, handler: () => void) => Promise<void>;
269
299
  };
300
+ get prompts(): {
301
+ list: () => Promise<Record<string, Prompt[]>>;
302
+ get: ({ serverName, name, args, version }: {
303
+ serverName: string;
304
+ name: string;
305
+ args?: Record<string, any>;
306
+ version?: string;
307
+ }) => Promise<{
308
+ [x: string]: unknown;
309
+ messages: {
310
+ [x: string]: unknown;
311
+ role: "user" | "assistant";
312
+ content: {
313
+ [x: string]: unknown;
314
+ type: "text";
315
+ text: string;
316
+ } | {
317
+ [x: string]: unknown;
318
+ type: "image";
319
+ data: string;
320
+ mimeType: string;
321
+ } | {
322
+ [x: string]: unknown;
323
+ type: "audio";
324
+ data: string;
325
+ mimeType: string;
326
+ } | {
327
+ [x: string]: unknown;
328
+ type: "resource";
329
+ resource: {
330
+ [x: string]: unknown;
331
+ text: string;
332
+ uri: string;
333
+ mimeType?: string | undefined;
334
+ } | {
335
+ [x: string]: unknown;
336
+ uri: string;
337
+ blob: string;
338
+ mimeType?: string | undefined;
339
+ };
340
+ };
341
+ }[];
342
+ description?: string | undefined;
343
+ _meta?: {
344
+ [x: string]: unknown;
345
+ } | undefined;
346
+ }>;
347
+ onListChanged: (serverName: string, handler: () => void) => Promise<void>;
348
+ };
270
349
  private addToInstanceCache;
271
350
  private makeId;
272
351
  disconnect(): Promise<void>;
@@ -277,8 +356,8 @@ declare class MCPClient extends MastraBase {
277
356
  */
278
357
  getResources(): Promise<Record<string, {
279
358
  [x: string]: unknown;
280
- uri: string;
281
359
  name: string;
360
+ uri: string;
282
361
  description?: string | undefined;
283
362
  mimeType?: string | undefined;
284
363
  }[]>>;
@@ -293,6 +372,7 @@ declare class MCPClient extends MastraBase {
293
372
  }
294
373
  export { MCPClient }
295
374
  export { MCPClient as MCPClient_alias_1 }
375
+ export { MCPClient as MCPClient_alias_2 }
296
376
 
297
377
  declare interface MCPClientOptions {
298
378
  id?: string;
@@ -301,6 +381,7 @@ declare interface MCPClientOptions {
301
381
  }
302
382
  export { MCPClientOptions }
303
383
  export { MCPClientOptions as MCPClientOptions_alias_1 }
384
+ export { MCPClientOptions as MCPClientOptions_alias_2 }
304
385
 
305
386
  /**
306
387
  * @deprecated MCPConfiguration is deprecated and will be removed in a future release. Use MCPClient instead.
@@ -310,6 +391,7 @@ declare class MCPConfiguration extends MCPClient {
310
391
  }
311
392
  export { MCPConfiguration }
312
393
  export { MCPConfiguration as MCPConfiguration_alias_1 }
394
+ export { MCPConfiguration as MCPConfiguration_alias_2 }
313
395
 
314
396
  /**
315
397
  * @deprecated MCPConfigurationOptions is deprecated and will be removed in a future release. Use MCPClientOptions instead.
@@ -321,6 +403,7 @@ declare interface MCPConfigurationOptions {
321
403
  }
322
404
  export { MCPConfigurationOptions }
323
405
  export { MCPConfigurationOptions as MCPConfigurationOptions_alias_1 }
406
+ export { MCPConfigurationOptions as MCPConfigurationOptions_alias_2 }
324
407
 
325
408
  declare class MCPServer extends MCPServerBase {
326
409
  private server;
@@ -335,11 +418,16 @@ declare class MCPServer extends MCPServerBase {
335
418
  private listResourceTemplatesHandlerIsRegistered;
336
419
  private subscribeResourceHandlerIsRegistered;
337
420
  private unsubscribeResourceHandlerIsRegistered;
421
+ private listPromptsHandlerIsRegistered;
422
+ private getPromptHandlerIsRegistered;
338
423
  private definedResources?;
339
424
  private definedResourceTemplates?;
340
425
  private resourceOptions?;
426
+ private definedPrompts?;
427
+ private promptOptions?;
341
428
  private subscriptions;
342
429
  readonly resources: ServerResourceActions;
430
+ readonly prompts: ServerPromptActions;
343
431
  /**
344
432
  * Get the current stdio transport.
345
433
  */
@@ -366,6 +454,7 @@ declare class MCPServer extends MCPServerBase {
366
454
  */
367
455
  constructor(opts: MCPServerConfig & {
368
456
  resources?: MCPServerResources;
457
+ prompts?: MCPServerPrompts;
369
458
  });
370
459
  private convertAgentsToTools;
371
460
  private convertWorkflowsToTools;
@@ -406,6 +495,14 @@ declare class MCPServer extends MCPServerBase {
406
495
  * Register the UnsubscribeResource handler.
407
496
  */
408
497
  private registerUnsubscribeResourceHandler;
498
+ /**
499
+ * Register the ListPrompts handler.
500
+ */
501
+ private registerListPromptsHandler;
502
+ /**
503
+ * Register the GetPrompt handler.
504
+ */
505
+ private registerGetPromptHandler;
409
506
  /**
410
507
  * Start the MCP server using stdio transport (for Windsurf integration).
411
508
  */
@@ -509,9 +606,27 @@ declare class MCPServer extends MCPServerBase {
509
606
  }
510
607
  export { MCPServer }
511
608
  export { MCPServer as MCPServer_alias_1 }
609
+ export { MCPServer as MCPServer_alias_2 }
512
610
 
513
611
  export declare const mcpServerName = "firecrawl-mcp-fixture";
514
612
 
613
+ declare type MCPServerPromptMessagesCallback = ({ name, version, args, }: {
614
+ name: string;
615
+ version?: string;
616
+ args?: any;
617
+ }) => Promise<PromptMessage[]>;
618
+ export { MCPServerPromptMessagesCallback }
619
+ export { MCPServerPromptMessagesCallback as MCPServerPromptMessagesCallback_alias_1 }
620
+ export { MCPServerPromptMessagesCallback as MCPServerPromptMessagesCallback_alias_2 }
621
+
622
+ declare type MCPServerPrompts = {
623
+ listPrompts: () => Promise<Prompt[]>;
624
+ getPromptMessages?: MCPServerPromptMessagesCallback;
625
+ };
626
+ export { MCPServerPrompts }
627
+ export { MCPServerPrompts as MCPServerPrompts_alias_1 }
628
+ export { MCPServerPrompts as MCPServerPrompts_alias_2 }
629
+
515
630
  declare type MCPServerResourceContent = {
516
631
  text?: string;
517
632
  } | {
@@ -519,12 +634,14 @@ declare type MCPServerResourceContent = {
519
634
  };
520
635
  export { MCPServerResourceContent }
521
636
  export { MCPServerResourceContent as MCPServerResourceContent_alias_1 }
637
+ export { MCPServerResourceContent as MCPServerResourceContent_alias_2 }
522
638
 
523
639
  declare type MCPServerResourceContentCallback = ({ uri, }: {
524
640
  uri: string;
525
641
  }) => Promise<MCPServerResourceContent | MCPServerResourceContent[]>;
526
642
  export { MCPServerResourceContentCallback }
527
643
  export { MCPServerResourceContentCallback as MCPServerResourceContentCallback_alias_1 }
644
+ export { MCPServerResourceContentCallback as MCPServerResourceContentCallback_alias_2 }
528
645
 
529
646
  declare type MCPServerResources = {
530
647
  listResources: () => Promise<Resource[]>;
@@ -533,9 +650,47 @@ declare type MCPServerResources = {
533
650
  };
534
651
  export { MCPServerResources }
535
652
  export { MCPServerResources as MCPServerResources_alias_1 }
653
+ export { MCPServerResources as MCPServerResources_alias_2 }
654
+
655
+ /**
656
+ * Client-side prompt actions for listing, getting, and subscribing to prompt changes.
657
+ */
658
+ export declare class PromptClientActions {
659
+ private readonly client;
660
+ private readonly logger;
661
+ constructor({ client, logger }: PromptClientActionsConfig);
662
+ /**
663
+ * Get all prompts from the connected MCP server.
664
+ * @returns A list of prompts with their versions.
665
+ */
666
+ list(): Promise<Prompt[]>;
667
+ /**
668
+ * Get a specific prompt.
669
+ * @param name The name of the prompt to get.
670
+ * @param args Optional arguments for the prompt.
671
+ * @param version Optional version of the prompt to get.
672
+ * @returns The prompt content.
673
+ */
674
+ get({ name, args, version }: {
675
+ name: string;
676
+ args?: Record<string, any>;
677
+ version?: string;
678
+ }): Promise<GetPromptResult>;
679
+ /**
680
+ * Set a notification handler for when the list of available prompts changes.
681
+ * @param handler The callback function to handle the notification.
682
+ */
683
+ onListChanged(handler: () => void): Promise<void>;
684
+ }
685
+
686
+ declare interface PromptClientActionsConfig {
687
+ client: InternalMastraMCPClient;
688
+ logger: IMastraLogger;
689
+ }
536
690
 
537
691
  export { Resource }
538
692
  export { Resource as Resource_alias_1 }
693
+ export { Resource as Resource_alias_2 }
539
694
 
540
695
  export declare class ResourceClientActions {
541
696
  private readonly client;
@@ -622,6 +777,7 @@ declare interface ResourceClientActionsConfig {
622
777
 
623
778
  export { ResourceTemplate }
624
779
  export { ResourceTemplate as ResourceTemplate_alias_1 }
780
+ export { ResourceTemplate as ResourceTemplate_alias_2 }
625
781
 
626
782
  export declare const server: Server<{
627
783
  method: string;
@@ -649,6 +805,24 @@ export declare const server: Server<{
649
805
 
650
806
  export declare const server_alias_1: MCPServer;
651
807
 
808
+ export declare class ServerPromptActions {
809
+ private readonly getLogger;
810
+ private readonly getSdkServer;
811
+ private readonly clearDefinedPrompts;
812
+ constructor(dependencies: ServerPromptActionsDependencies);
813
+ /**
814
+ * Notifies the server that the overall list of available prompts has changed.
815
+ * This will clear the internal cache of defined prompts and send a list_changed notification to clients.
816
+ */
817
+ notifyListChanged(): Promise<void>;
818
+ }
819
+
820
+ declare interface ServerPromptActionsDependencies {
821
+ getLogger: () => IMastraLogger;
822
+ getSdkServer: () => Server;
823
+ clearDefinedPrompts: () => void;
824
+ }
825
+
652
826
  export declare class ServerResourceActions {
653
827
  private readonly getSubscriptions;
654
828
  private readonly getLogger;