@mastra/mcp 1.4.1 → 1.4.2-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 +17 -0
- package/dist/client/client.d.ts +0 -15
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +3 -0
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/error-utils.d.ts +2 -0
- package/dist/client/error-utils.d.ts.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +49 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +49 -27
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 1.4.2-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed MCP server to return HTTP 404 (instead of 400) when a client sends a stale or unknown session ID. Per the MCP spec, this tells clients to re-initialize with a new session, which fixes broken tool calls after server redeploys. ([#15160](https://github.com/mastra-ai/mastra/pull/15160))
|
|
8
|
+
|
|
9
|
+
## 1.4.2-alpha.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Improved MCP tool discovery to retry once after reconnectable connection errors like `Connection closed` during `tools/list`. ([#15141](https://github.com/mastra-ai/mastra/pull/15141))
|
|
14
|
+
|
|
15
|
+
`MCPClient.listToolsets()`, `listToolsetsWithErrors()`, and `listTools()` now attempt a reconnect before treating transient discovery failures as missing tools.
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`153e864`](https://github.com/mastra-ai/mastra/commit/153e86476b425db7cd0dc8490050096e92964a38)]:
|
|
18
|
+
- @mastra/core@1.23.1-alpha.0
|
|
19
|
+
|
|
3
20
|
## 1.4.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/client/client.d.ts
CHANGED
|
@@ -122,21 +122,6 @@ export declare class InternalMastraMCPClient extends MastraBase {
|
|
|
122
122
|
*/
|
|
123
123
|
get stderr(): Stream | null;
|
|
124
124
|
disconnect(): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Checks if an error indicates a session invalidation that requires reconnection.
|
|
127
|
-
*
|
|
128
|
-
* Common session-related errors include:
|
|
129
|
-
* - "No valid session ID provided" (HTTP 400)
|
|
130
|
-
* - "Server not initialized" (HTTP 400)
|
|
131
|
-
* - "Not connected" (protocol state error)
|
|
132
|
-
* - Connection refused errors
|
|
133
|
-
*
|
|
134
|
-
* @param error - The error to check
|
|
135
|
-
* @returns true if the error indicates a session problem requiring reconnection
|
|
136
|
-
*
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
private isSessionError;
|
|
140
125
|
/**
|
|
141
126
|
* Forces a reconnection to the MCP server by disconnecting and reconnecting.
|
|
142
127
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,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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E,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOpD,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOtD,qBAAqB,IAAI,OAAO,CAAC,2BAA2B,CAAC;IAOnE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAO/C;;;;OAIG;IACG,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;IASvG;;;OAGG;IACH,uCAAuC,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAOlE,qCAAqC,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAO3E,yCAAyC,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAOpE,4BAA4B,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAQ/D,8BAA8B,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;YAOhD,kBAAkB;IA+B1B,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;CAoHjE"}
|
|
@@ -539,6 +539,7 @@ export declare class MCPClient extends MastraBase {
|
|
|
539
539
|
*
|
|
540
540
|
* @returns Object mapping namespaced tool names to tool implementations.
|
|
541
541
|
* Errors for individual servers are logged but don't throw - failed servers are skipped.
|
|
542
|
+
* Transient connection failures are retried once after reconnecting the affected server.
|
|
542
543
|
*
|
|
543
544
|
* @example
|
|
544
545
|
* ```typescript
|
|
@@ -583,6 +584,7 @@ export declare class MCPClient extends MastraBase {
|
|
|
583
584
|
* or list tools. This allows callers to report specific failure reasons per server.
|
|
584
585
|
*
|
|
585
586
|
* @returns Object with `toolsets` (successful servers) and `errors` (failed servers with error messages).
|
|
587
|
+
* Transient connection failures are retried once after reconnecting the affected server.
|
|
586
588
|
*
|
|
587
589
|
* @example
|
|
588
590
|
* ```typescript
|
|
@@ -624,5 +626,6 @@ export declare class MCPClient extends MastraBase {
|
|
|
624
626
|
getServerStderr(serverName: string): Stream | null;
|
|
625
627
|
private getConnectedClient;
|
|
626
628
|
private getConnectedClientForServer;
|
|
629
|
+
private getToolsForServer;
|
|
627
630
|
}
|
|
628
631
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,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;
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,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;AAM1D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AC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAK9F;;;;;;;;;;;;;;;;OAgBG;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;IAgCF;;;;;;;;;;;;;;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;YAQ3B,iBAAiB;CAuBhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/client/error-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAuB/D"}
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -388,6 +388,15 @@ var ResourceClientActions = class {
|
|
|
388
388
|
}
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
+
// src/client/error-utils.ts
|
|
392
|
+
function isReconnectableMCPError(error) {
|
|
393
|
+
if (!(error instanceof Error)) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
const errorMessage = error.message.toLowerCase();
|
|
397
|
+
return errorMessage.includes("no valid session") || errorMessage.includes("session") || errorMessage.includes("server not initialized") || errorMessage.includes("not connected") || errorMessage.includes("http 400") || errorMessage.includes("http 401") || errorMessage.includes("http 403") || errorMessage.includes("http 404") || errorMessage.includes("econnrefused") || errorMessage.includes("fetch failed") || errorMessage.includes("connection refused") || errorMessage.includes("connection closed") || errorMessage.includes("sse stream disconnected") || errorMessage.includes("typeerror: terminated");
|
|
398
|
+
}
|
|
399
|
+
|
|
391
400
|
// src/client/client.ts
|
|
392
401
|
var DEFAULT_SERVER_CONNECT_TIMEOUT_MSEC = 3e3;
|
|
393
402
|
var SSE_FALLBACK_STATUS_CODES = [400, 404, 405];
|
|
@@ -746,27 +755,6 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
746
755
|
}
|
|
747
756
|
}
|
|
748
757
|
}
|
|
749
|
-
/**
|
|
750
|
-
* Checks if an error indicates a session invalidation that requires reconnection.
|
|
751
|
-
*
|
|
752
|
-
* Common session-related errors include:
|
|
753
|
-
* - "No valid session ID provided" (HTTP 400)
|
|
754
|
-
* - "Server not initialized" (HTTP 400)
|
|
755
|
-
* - "Not connected" (protocol state error)
|
|
756
|
-
* - Connection refused errors
|
|
757
|
-
*
|
|
758
|
-
* @param error - The error to check
|
|
759
|
-
* @returns true if the error indicates a session problem requiring reconnection
|
|
760
|
-
*
|
|
761
|
-
* @internal
|
|
762
|
-
*/
|
|
763
|
-
isSessionError(error) {
|
|
764
|
-
if (!(error instanceof Error)) {
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
const errorMessage = error.message.toLowerCase();
|
|
768
|
-
return errorMessage.includes("no valid session") || errorMessage.includes("session") || errorMessage.includes("server not initialized") || errorMessage.includes("not connected") || errorMessage.includes("http 400") || errorMessage.includes("http 401") || errorMessage.includes("http 403") || errorMessage.includes("econnrefused") || errorMessage.includes("fetch failed") || errorMessage.includes("connection refused") || errorMessage.includes("sse stream disconnected") || errorMessage.includes("typeerror: terminated");
|
|
769
|
-
}
|
|
770
758
|
/**
|
|
771
759
|
* Forces a reconnection to the MCP server by disconnecting and reconnecting.
|
|
772
760
|
*
|
|
@@ -956,7 +944,7 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
956
944
|
try {
|
|
957
945
|
return await executeToolCall();
|
|
958
946
|
} catch (e) {
|
|
959
|
-
if (
|
|
947
|
+
if (isReconnectableMCPError(e)) {
|
|
960
948
|
this.log("debug", `Session error detected for tool ${tool.name}, attempting reconnection...`, {
|
|
961
949
|
error: e instanceof Error ? e.message : String(e)
|
|
962
950
|
});
|
|
@@ -996,6 +984,7 @@ var InternalMastraMCPClient = class extends base.MastraBase {
|
|
|
996
984
|
}
|
|
997
985
|
};
|
|
998
986
|
var mcpClientInstances = /* @__PURE__ */ new Map();
|
|
987
|
+
var TOOL_DISCOVERY_MAX_ATTEMPTS = 2;
|
|
999
988
|
var MCPClient = class extends base.MastraBase {
|
|
1000
989
|
serverConfigs = {};
|
|
1001
990
|
id;
|
|
@@ -1649,6 +1638,7 @@ To fix this you have three different options:
|
|
|
1649
1638
|
*
|
|
1650
1639
|
* @returns Object mapping namespaced tool names to tool implementations.
|
|
1651
1640
|
* Errors for individual servers are logged but don't throw - failed servers are skipped.
|
|
1641
|
+
* Transient connection failures are retried once after reconnecting the affected server.
|
|
1652
1642
|
*
|
|
1653
1643
|
* @example
|
|
1654
1644
|
* ```typescript
|
|
@@ -1666,8 +1656,7 @@ To fix this you have three different options:
|
|
|
1666
1656
|
const connectedTools = {};
|
|
1667
1657
|
for (const serverName of Object.keys(this.serverConfigs)) {
|
|
1668
1658
|
try {
|
|
1669
|
-
const
|
|
1670
|
-
const tools = await client.tools();
|
|
1659
|
+
const tools = await this.getToolsForServer(serverName);
|
|
1671
1660
|
for (const [toolName, toolConfig] of Object.entries(tools)) {
|
|
1672
1661
|
connectedTools[`${serverName}_${toolName}`] = toolConfig;
|
|
1673
1662
|
}
|
|
@@ -1723,6 +1712,7 @@ To fix this you have three different options:
|
|
|
1723
1712
|
* or list tools. This allows callers to report specific failure reasons per server.
|
|
1724
1713
|
*
|
|
1725
1714
|
* @returns Object with `toolsets` (successful servers) and `errors` (failed servers with error messages).
|
|
1715
|
+
* Transient connection failures are retried once after reconnecting the affected server.
|
|
1726
1716
|
*
|
|
1727
1717
|
* @example
|
|
1728
1718
|
* ```typescript
|
|
@@ -1738,8 +1728,7 @@ To fix this you have three different options:
|
|
|
1738
1728
|
const errors = {};
|
|
1739
1729
|
for (const serverName of Object.keys(this.serverConfigs)) {
|
|
1740
1730
|
try {
|
|
1741
|
-
const
|
|
1742
|
-
const tools = await client.tools();
|
|
1731
|
+
const tools = await this.getToolsForServer(serverName);
|
|
1743
1732
|
if (tools) {
|
|
1744
1733
|
connectedToolsets[serverName] = tools;
|
|
1745
1734
|
}
|
|
@@ -1852,6 +1841,26 @@ To fix this you have three different options:
|
|
|
1852
1841
|
}
|
|
1853
1842
|
return this.getConnectedClient(serverName, serverConfig);
|
|
1854
1843
|
}
|
|
1844
|
+
async getToolsForServer(serverName) {
|
|
1845
|
+
for (let attempt = 1; attempt <= TOOL_DISCOVERY_MAX_ATTEMPTS; attempt++) {
|
|
1846
|
+
try {
|
|
1847
|
+
const client = await this.getConnectedClientForServer(serverName);
|
|
1848
|
+
return await client.tools();
|
|
1849
|
+
} catch (error) {
|
|
1850
|
+
if (attempt === TOOL_DISCOVERY_MAX_ATTEMPTS || !isReconnectableMCPError(error)) {
|
|
1851
|
+
throw error;
|
|
1852
|
+
}
|
|
1853
|
+
this.logger.debug("Retrying MCP tool discovery after reconnect", {
|
|
1854
|
+
serverName,
|
|
1855
|
+
attempt,
|
|
1856
|
+
maxAttempts: TOOL_DISCOVERY_MAX_ATTEMPTS,
|
|
1857
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1858
|
+
});
|
|
1859
|
+
await this.reconnectServer(serverName);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
return {};
|
|
1863
|
+
}
|
|
1855
1864
|
};
|
|
1856
1865
|
|
|
1857
1866
|
// src/client/oauth-provider.ts
|
|
@@ -3607,8 +3616,21 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
|
|
|
3607
3616
|
}
|
|
3608
3617
|
const body = req.method === "POST" ? await this.readJsonBody(req) : void 0;
|
|
3609
3618
|
await transport.handleRequest(req, res, body);
|
|
3619
|
+
} else if (sessionId) {
|
|
3620
|
+
this.logger.warn("Session ID not found, returning 404", { sessionId, method: req.method });
|
|
3621
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
3622
|
+
res.end(
|
|
3623
|
+
JSON.stringify({
|
|
3624
|
+
jsonrpc: "2.0",
|
|
3625
|
+
error: {
|
|
3626
|
+
code: -32e3,
|
|
3627
|
+
message: "Session not found"
|
|
3628
|
+
},
|
|
3629
|
+
id: null
|
|
3630
|
+
})
|
|
3631
|
+
);
|
|
3610
3632
|
} else {
|
|
3611
|
-
this.logger.debug("No
|
|
3633
|
+
this.logger.debug("No session ID provided", { method: req.method });
|
|
3612
3634
|
if (req.method === "POST") {
|
|
3613
3635
|
const body = await this.readJsonBody(req);
|
|
3614
3636
|
const { isInitializeRequest } = await import('@modelcontextprotocol/sdk/types.js');
|