@mastra/mcp 1.4.2-alpha.0 → 1.4.2

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/dist/index.js CHANGED
@@ -387,7 +387,7 @@ function isReconnectableMCPError(error) {
387
387
  return false;
388
388
  }
389
389
  const errorMessage = error.message.toLowerCase();
390
- 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("connection closed") || errorMessage.includes("sse stream disconnected") || errorMessage.includes("typeerror: terminated");
390
+ 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");
391
391
  }
392
392
 
393
393
  // src/client/client.ts
@@ -3609,8 +3609,21 @@ Provided arguments: ${JSON.stringify(request.params.arguments, null, 2)}`
3609
3609
  }
3610
3610
  const body = req.method === "POST" ? await this.readJsonBody(req) : void 0;
3611
3611
  await transport.handleRequest(req, res, body);
3612
+ } else if (sessionId) {
3613
+ this.logger.warn("Session ID not found, returning 404", { sessionId, method: req.method });
3614
+ res.writeHead(404, { "Content-Type": "application/json" });
3615
+ res.end(
3616
+ JSON.stringify({
3617
+ jsonrpc: "2.0",
3618
+ error: {
3619
+ code: -32e3,
3620
+ message: "Session not found"
3621
+ },
3622
+ id: null
3623
+ })
3624
+ );
3612
3625
  } else {
3613
- this.logger.debug("No existing session found", { method: req.method });
3626
+ this.logger.debug("No session ID provided", { method: req.method });
3614
3627
  if (req.method === "POST") {
3615
3628
  const body = await this.readJsonBody(req);
3616
3629
  const { isInitializeRequest } = await import('@modelcontextprotocol/sdk/types.js');