@mastra/mcp 1.2.2-alpha.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @mastra/mcp
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added new MCP client APIs for per-server control and diagnostics. ([#14377](https://github.com/mastra-ai/mastra/pull/14377))
8
+ - Added `reconnectServer(serverName)` to reconnect a single MCP server without restarting all servers.
9
+ - Added `listToolsetsWithErrors()` to return both toolsets and per-server errors.
10
+ - Added `getServerStderr(serverName)` to inspect piped stderr for stdio servers.
11
+
12
+ **Example**
13
+
14
+ ```ts
15
+ const { toolsets, errors } = await mcpClient.listToolsetsWithErrors();
16
+ await mcpClient.reconnectServer('slack');
17
+ const stderr = mcpClient.getServerStderr('slack');
18
+ ```
19
+
20
+ ### Patch Changes
21
+
22
+ - **Improved** ([#14260](https://github.com/mastra-ai/mastra/pull/14260))
23
+ - Updated `@modelcontextprotocol/sdk` from `^1.17.5` to `^1.27.1`.
24
+
25
+ **Deprecated**
26
+ - Deprecated prompt `version` usage in `@mastra/mcp`.
27
+ - Prompt versions are not part of MCP protocol behavior and will be removed.
28
+
29
+ **Migration**
30
+ - Use unique prompt names instead of prompt versions.
31
+ - Before: `client.prompts.get({ name: 'explain-code', version: 'v1', args })`
32
+ - After: `client.prompts.get({ name: 'explain-code-v1', args })`
33
+ - `MastraPrompt` is available for migration and is also deprecated.
34
+
35
+ - Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`b77aa19`](https://github.com/mastra-ai/mastra/commit/b77aa1981361c021f2c881bee8f0c703687f00da), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8b4ce84`](https://github.com/mastra-ai/mastra/commit/8b4ce84aed0808b9805cc4fd7147c1f8a2ef7a36), [`8d4cfe6`](https://github.com/mastra-ai/mastra/commit/8d4cfe6b9a7157d3876206227ec9f04cde6dbc4a), [`dd6ca1c`](https://github.com/mastra-ai/mastra/commit/dd6ca1cdea3b8b6182f4cf61df41070ba0cc0deb), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a), [`4cb4edf`](https://github.com/mastra-ai/mastra/commit/4cb4edf3c909d197ec356c1790d13270514ffef6), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a)]:
36
+ - @mastra/core@1.14.0
37
+
38
+ ## 1.3.0-alpha.1
39
+
40
+ ### Minor Changes
41
+
42
+ - Added new MCP client APIs for per-server control and diagnostics. ([#14377](https://github.com/mastra-ai/mastra/pull/14377))
43
+ - Added `reconnectServer(serverName)` to reconnect a single MCP server without restarting all servers.
44
+ - Added `listToolsetsWithErrors()` to return both toolsets and per-server errors.
45
+ - Added `getServerStderr(serverName)` to inspect piped stderr for stdio servers.
46
+
47
+ **Example**
48
+
49
+ ```ts
50
+ const { toolsets, errors } = await mcpClient.listToolsetsWithErrors();
51
+ await mcpClient.reconnectServer('slack');
52
+ const stderr = mcpClient.getServerStderr('slack');
53
+ ```
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f)]:
58
+ - @mastra/core@1.14.0-alpha.2
59
+
3
60
  ## 1.2.2-alpha.0
4
61
 
5
62
  ### Patch Changes
@@ -1,3 +1,4 @@
1
+ import type { Stream } from 'node:stream';
1
2
  import { MastraBase } from '@mastra/core/base';
2
3
  import type { Tool } from '@mastra/core/tools';
3
4
  import type { EmptyResult, GetPromptResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
@@ -111,6 +112,14 @@ export declare class InternalMastraMCPClient extends MastraBase {
111
112
  * @internal
112
113
  */
113
114
  get sessionId(): string | undefined;
115
+ /**
116
+ * Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`.
117
+ *
118
+ * Returns null if not connected, not using stdio transport, or stderr is not piped.
119
+ *
120
+ * @internal
121
+ */
122
+ get stderr(): Stream | null;
114
123
  disconnect(): Promise<void>;
115
124
  /**
116
125
  * Checks if an error indicates a session invalidation that requires reconnection.
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAS/C,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,2BAA2B,EAE3B,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAmB5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;A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
3
  import type { Tool } from '@mastra/core/tools';
3
4
  import type { ElicitRequest, ElicitResult, ProgressNotification, Prompt, Resource, ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
@@ -514,6 +515,22 @@ export declare class MCPClient extends MastraBase {
514
515
  * ```
515
516
  */
516
517
  disconnect(): Promise<void>;
518
+ /**
519
+ * Reconnects a single MCP server by name.
520
+ *
521
+ * If the server is already connected, it will be forcefully disconnected and reconnected.
522
+ * If the server has never been connected, a new connection will be established.
523
+ *
524
+ * @param serverName - The name of the server to reconnect (must match a key in `servers`)
525
+ * @throws {Error} If the server name is not found in the configuration
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * // Reconnect a specific server after it fails
530
+ * await mcp.reconnectServer('weatherServer');
531
+ * ```
532
+ */
533
+ reconnectServer(serverName: string): Promise<void>;
517
534
  /**
518
535
  * Retrieves all tools from all configured servers with namespaced names.
519
536
  *
@@ -559,6 +576,26 @@ export declare class MCPClient extends MastraBase {
559
576
  * ```
560
577
  */
561
578
  listToolsets(): Promise<Record<string, Record<string, Tool<any, any, any, any>>>>;
579
+ /**
580
+ * Returns toolsets organized by server name, along with any per-server errors.
581
+ *
582
+ * Like listToolsets(), but also returns errors for servers that failed to connect
583
+ * or list tools. This allows callers to report specific failure reasons per server.
584
+ *
585
+ * @returns Object with `toolsets` (successful servers) and `errors` (failed servers with error messages).
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const { toolsets, errors } = await mcp.listToolsetsWithErrors();
590
+ * for (const [name, err] of Object.entries(errors)) {
591
+ * console.error(`Server ${name} failed: ${err}`);
592
+ * }
593
+ * ```
594
+ */
595
+ listToolsetsWithErrors(): Promise<{
596
+ toolsets: Record<string, Record<string, Tool<any, any, any, any>>>;
597
+ errors: Record<string, string>;
598
+ }>;
562
599
  /**
563
600
  * Gets current session IDs for all connected MCP clients using Streamable HTTP transport.
564
601
  *
@@ -575,6 +612,16 @@ export declare class MCPClient extends MastraBase {
575
612
  * ```
576
613
  */
577
614
  get sessionIds(): Record<string, string>;
615
+ /**
616
+ * Gets the stderr stream of a connected stdio server.
617
+ *
618
+ * Only available for servers using stdio transport with `stderr: 'pipe'`.
619
+ * Returns null if the server is not connected, not using stdio, or stderr is not piped.
620
+ *
621
+ * @param serverName - The name of the server
622
+ * @returns The stderr stream, or null
623
+ */
624
+ getServerStderr(serverName: string): Stream | null;
578
625
  private getConnectedClient;
579
626
  private getConnectedClientForServer;
580
627
  }
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,QAAQ,EACR,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAI1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wHAAwH;IACxH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IACnD,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,OAAO,CAAC,aAAa,CAAiD;IACtE,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,iBAAiB,CAA8B;IAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;gBACS,IAAI,EAAE,gBAAgB;IA2ClC;;;;;;;;;;;;;;;;;;OAkBG;IACH,IAAW,Q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AC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAK9F;;;;;;;;;;;;;;;OAeG;IACU,sBAAsB,IAAI,OAAO,CAAC;QAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QACnE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IAiCF;;;;;;;;;;;;;;OAcG;IACH,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQvC;IAED;;;;;;;;OAQG;IACI,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;YAM3C,kBAAkB;YAyDlB,2BAA2B;CAO1C"}
@@ -3,7 +3,7 @@ name: mastra-mcp
3
3
  description: Documentation for @mastra/mcp. Use when working with @mastra/mcp APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mcp"
6
- version: "1.2.2-alpha.0"
6
+ version: "1.3.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.2-alpha.0",
2
+ "version": "1.3.0",
3
3
  "package": "@mastra/mcp",
4
4
  "exports": {
5
5
  "UnauthorizedError": {
@@ -82,7 +82,7 @@ export const testAgent = new Agent({
82
82
  - US National Weather Service
83
83
 
84
84
  Answer questions using the information you find using the MCP Servers.`,
85
- model: 'openai/gpt-5.1',
85
+ model: 'openai/gpt-5.4',
86
86
  tools: await testMcpClient.listTools(),
87
87
  })
88
88
  ```
@@ -737,7 +737,7 @@ const agent = new Agent({
737
737
  id: 'multi-tool-agent',
738
738
  name: 'Multi-tool Agent',
739
739
  instructions: 'You have access to multiple tool servers.',
740
- model: 'openai/gpt-5.1',
740
+ model: 'openai/gpt-5.4',
741
741
  tools: await mcp.listTools(),
742
742
  })
743
743
 
@@ -788,7 +788,7 @@ const agent = new Agent({
788
788
  id: 'multi-tool-agent',
789
789
  name: 'Multi-tool Agent',
790
790
  instructions: 'You help users check stocks and weather.',
791
- model: 'openai/gpt-5.1',
791
+ model: 'openai/gpt-5.4',
792
792
  })
793
793
 
794
794
  // Later, configure MCP with user-specific settings
@@ -22,7 +22,7 @@ const myAgent = new Agent({
22
22
  name: 'MyExampleAgent',
23
23
  description: 'A generalist to help with basic questions.',
24
24
  instructions: 'You are a helpful assistant.',
25
- model: 'openai/gpt-5.1',
25
+ model: 'openai/gpt-5.4',
26
26
  })
27
27
 
28
28
  const weatherTool = createTool({
package/dist/index.cjs CHANGED
@@ -692,6 +692,19 @@ var InternalMastraMCPClient = class extends base.MastraBase {
692
692
  }
693
693
  return void 0;
694
694
  }
695
+ /**
696
+ * Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`.
697
+ *
698
+ * Returns null if not connected, not using stdio transport, or stderr is not piped.
699
+ *
700
+ * @internal
701
+ */
702
+ get stderr() {
703
+ if (this.transport instanceof stdio_js.StdioClientTransport) {
704
+ return this.transport.stderr;
705
+ }
706
+ return null;
707
+ }
695
708
  async disconnect() {
696
709
  if (!this.transport) {
697
710
  this.log("debug", "Disconnect called but no transport was connected.");
@@ -1624,6 +1637,29 @@ To fix this you have three different options:
1624
1637
  })();
1625
1638
  return this.disconnectPromise;
1626
1639
  }
1640
+ /**
1641
+ * Reconnects a single MCP server by name.
1642
+ *
1643
+ * If the server is already connected, it will be forcefully disconnected and reconnected.
1644
+ * If the server has never been connected, a new connection will be established.
1645
+ *
1646
+ * @param serverName - The name of the server to reconnect (must match a key in `servers`)
1647
+ * @throws {Error} If the server name is not found in the configuration
1648
+ *
1649
+ * @example
1650
+ * ```typescript
1651
+ * // Reconnect a specific server after it fails
1652
+ * await mcp.reconnectServer('weatherServer');
1653
+ * ```
1654
+ */
1655
+ async reconnectServer(serverName) {
1656
+ const existingClient = this.mcpClientsById.get(serverName);
1657
+ if (existingClient) {
1658
+ await existingClient.forceReconnect();
1659
+ } else {
1660
+ await this.getConnectedClientForServer(serverName);
1661
+ }
1662
+ }
1627
1663
  /**
1628
1664
  * Retrieves all tools from all configured servers with namespaced names.
1629
1665
  *
@@ -1696,8 +1732,29 @@ To fix this you have three different options:
1696
1732
  * ```
1697
1733
  */
1698
1734
  async listToolsets() {
1735
+ const result = await this.listToolsetsWithErrors();
1736
+ return result.toolsets;
1737
+ }
1738
+ /**
1739
+ * Returns toolsets organized by server name, along with any per-server errors.
1740
+ *
1741
+ * Like listToolsets(), but also returns errors for servers that failed to connect
1742
+ * or list tools. This allows callers to report specific failure reasons per server.
1743
+ *
1744
+ * @returns Object with `toolsets` (successful servers) and `errors` (failed servers with error messages).
1745
+ *
1746
+ * @example
1747
+ * ```typescript
1748
+ * const { toolsets, errors } = await mcp.listToolsetsWithErrors();
1749
+ * for (const [name, err] of Object.entries(errors)) {
1750
+ * console.error(`Server ${name} failed: ${err}`);
1751
+ * }
1752
+ * ```
1753
+ */
1754
+ async listToolsetsWithErrors() {
1699
1755
  this.addToInstanceCache();
1700
1756
  const connectedToolsets = {};
1757
+ const errors = {};
1701
1758
  for (const serverName of Object.keys(this.serverConfigs)) {
1702
1759
  try {
1703
1760
  const client = await this.getConnectedClientForServer(serverName);
@@ -1719,9 +1776,10 @@ To fix this you have three different options:
1719
1776
  );
1720
1777
  this.logger.trackException(mastraError);
1721
1778
  this.logger.error("Failed to list toolsets from server:", { error: mastraError.toString() });
1779
+ errors[serverName] = error$1 instanceof Error ? error$1.message : String(error$1);
1722
1780
  }
1723
1781
  }
1724
- return connectedToolsets;
1782
+ return { toolsets: connectedToolsets, errors };
1725
1783
  }
1726
1784
  /**
1727
1785
  * Gets current session IDs for all connected MCP clients using Streamable HTTP transport.
@@ -1747,6 +1805,20 @@ To fix this you have three different options:
1747
1805
  }
1748
1806
  return sessionIds;
1749
1807
  }
1808
+ /**
1809
+ * Gets the stderr stream of a connected stdio server.
1810
+ *
1811
+ * Only available for servers using stdio transport with `stderr: 'pipe'`.
1812
+ * Returns null if the server is not connected, not using stdio, or stderr is not piped.
1813
+ *
1814
+ * @param serverName - The name of the server
1815
+ * @returns The stderr stream, or null
1816
+ */
1817
+ getServerStderr(serverName) {
1818
+ const client = this.mcpClientsById.get(serverName);
1819
+ if (!client) return null;
1820
+ return client.stderr;
1821
+ }
1750
1822
  async getConnectedClient(name, config) {
1751
1823
  if (this.disconnectPromise) {
1752
1824
  await this.disconnectPromise;