@mastra/mcp 1.2.2-alpha.0 → 1.3.0-alpha.1
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 +22 -0
- package/dist/client/client.d.ts +9 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +47 -0
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-mcp-overview.md +1 -1
- package/dist/docs/references/reference-tools-mcp-client.md +2 -2
- package/dist/docs/references/reference-tools-mcp-server.md +1 -1
- package/dist/index.cjs +73 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -685,6 +685,19 @@ var InternalMastraMCPClient = class extends MastraBase {
|
|
|
685
685
|
}
|
|
686
686
|
return void 0;
|
|
687
687
|
}
|
|
688
|
+
/**
|
|
689
|
+
* Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`.
|
|
690
|
+
*
|
|
691
|
+
* Returns null if not connected, not using stdio transport, or stderr is not piped.
|
|
692
|
+
*
|
|
693
|
+
* @internal
|
|
694
|
+
*/
|
|
695
|
+
get stderr() {
|
|
696
|
+
if (this.transport instanceof StdioClientTransport) {
|
|
697
|
+
return this.transport.stderr;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
688
701
|
async disconnect() {
|
|
689
702
|
if (!this.transport) {
|
|
690
703
|
this.log("debug", "Disconnect called but no transport was connected.");
|
|
@@ -1617,6 +1630,29 @@ To fix this you have three different options:
|
|
|
1617
1630
|
})();
|
|
1618
1631
|
return this.disconnectPromise;
|
|
1619
1632
|
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Reconnects a single MCP server by name.
|
|
1635
|
+
*
|
|
1636
|
+
* If the server is already connected, it will be forcefully disconnected and reconnected.
|
|
1637
|
+
* If the server has never been connected, a new connection will be established.
|
|
1638
|
+
*
|
|
1639
|
+
* @param serverName - The name of the server to reconnect (must match a key in `servers`)
|
|
1640
|
+
* @throws {Error} If the server name is not found in the configuration
|
|
1641
|
+
*
|
|
1642
|
+
* @example
|
|
1643
|
+
* ```typescript
|
|
1644
|
+
* // Reconnect a specific server after it fails
|
|
1645
|
+
* await mcp.reconnectServer('weatherServer');
|
|
1646
|
+
* ```
|
|
1647
|
+
*/
|
|
1648
|
+
async reconnectServer(serverName) {
|
|
1649
|
+
const existingClient = this.mcpClientsById.get(serverName);
|
|
1650
|
+
if (existingClient) {
|
|
1651
|
+
await existingClient.forceReconnect();
|
|
1652
|
+
} else {
|
|
1653
|
+
await this.getConnectedClientForServer(serverName);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1620
1656
|
/**
|
|
1621
1657
|
* Retrieves all tools from all configured servers with namespaced names.
|
|
1622
1658
|
*
|
|
@@ -1689,8 +1725,29 @@ To fix this you have three different options:
|
|
|
1689
1725
|
* ```
|
|
1690
1726
|
*/
|
|
1691
1727
|
async listToolsets() {
|
|
1728
|
+
const result = await this.listToolsetsWithErrors();
|
|
1729
|
+
return result.toolsets;
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Returns toolsets organized by server name, along with any per-server errors.
|
|
1733
|
+
*
|
|
1734
|
+
* Like listToolsets(), but also returns errors for servers that failed to connect
|
|
1735
|
+
* or list tools. This allows callers to report specific failure reasons per server.
|
|
1736
|
+
*
|
|
1737
|
+
* @returns Object with `toolsets` (successful servers) and `errors` (failed servers with error messages).
|
|
1738
|
+
*
|
|
1739
|
+
* @example
|
|
1740
|
+
* ```typescript
|
|
1741
|
+
* const { toolsets, errors } = await mcp.listToolsetsWithErrors();
|
|
1742
|
+
* for (const [name, err] of Object.entries(errors)) {
|
|
1743
|
+
* console.error(`Server ${name} failed: ${err}`);
|
|
1744
|
+
* }
|
|
1745
|
+
* ```
|
|
1746
|
+
*/
|
|
1747
|
+
async listToolsetsWithErrors() {
|
|
1692
1748
|
this.addToInstanceCache();
|
|
1693
1749
|
const connectedToolsets = {};
|
|
1750
|
+
const errors = {};
|
|
1694
1751
|
for (const serverName of Object.keys(this.serverConfigs)) {
|
|
1695
1752
|
try {
|
|
1696
1753
|
const client = await this.getConnectedClientForServer(serverName);
|
|
@@ -1712,9 +1769,10 @@ To fix this you have three different options:
|
|
|
1712
1769
|
);
|
|
1713
1770
|
this.logger.trackException(mastraError);
|
|
1714
1771
|
this.logger.error("Failed to list toolsets from server:", { error: mastraError.toString() });
|
|
1772
|
+
errors[serverName] = error instanceof Error ? error.message : String(error);
|
|
1715
1773
|
}
|
|
1716
1774
|
}
|
|
1717
|
-
return connectedToolsets;
|
|
1775
|
+
return { toolsets: connectedToolsets, errors };
|
|
1718
1776
|
}
|
|
1719
1777
|
/**
|
|
1720
1778
|
* Gets current session IDs for all connected MCP clients using Streamable HTTP transport.
|
|
@@ -1740,6 +1798,20 @@ To fix this you have three different options:
|
|
|
1740
1798
|
}
|
|
1741
1799
|
return sessionIds;
|
|
1742
1800
|
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Gets the stderr stream of a connected stdio server.
|
|
1803
|
+
*
|
|
1804
|
+
* Only available for servers using stdio transport with `stderr: 'pipe'`.
|
|
1805
|
+
* Returns null if the server is not connected, not using stdio, or stderr is not piped.
|
|
1806
|
+
*
|
|
1807
|
+
* @param serverName - The name of the server
|
|
1808
|
+
* @returns The stderr stream, or null
|
|
1809
|
+
*/
|
|
1810
|
+
getServerStderr(serverName) {
|
|
1811
|
+
const client = this.mcpClientsById.get(serverName);
|
|
1812
|
+
if (!client) return null;
|
|
1813
|
+
return client.stderr;
|
|
1814
|
+
}
|
|
1743
1815
|
async getConnectedClient(name, config) {
|
|
1744
1816
|
if (this.disconnectPromise) {
|
|
1745
1817
|
await this.disconnectPromise;
|