{"record":{"id":"f5afe4f61cf40a6b","repo":"mastra-ai/mastra","slug":"could-not-connect-to-server-with-any-available-htt","errorCode":null,"errorMessage":"Could not connect to server with any available HTTP transport","messagePattern":"Could not connect to server with any available HTTP transport","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/mcp/src/client/client.ts","lineNumber":676,"sourceCode":"      });\n      try {\n        await this.client.connect(sseTransport, { timeout: this.serverConfig.timeout ?? this.timeout });\n        this.transport = sseTransport;\n        this.log('debug', 'Successfully connected using deprecated HTTP+SSE transport.');\n      } catch (sseError) {\n        if (authProvider && sseError instanceof UnauthorizedError) {\n          this.markNeedsAuth(sseTransport);\n          throw sseError;\n        }\n        // Surface policy violations directly instead of the generic connect error.\n        if (isUrlPolicyError(sseError)) {\n          throw sseError;\n        }\n        this.log(\n          'error',\n          `Failed to connect with SSE transport after failing to connect to Streamable HTTP transport first. SSE error: ${sseError}`,\n        );\n        throw new Error('Could not connect to server with any available HTTP transport');\n      }\n    }\n\n    // Reaching here means a transport connected; any earlier authorization requirement is satisfied.\n    // Close, don't just drop, any transport left pending from an earlier 401 so its event stream\n    // and session resources are released rather than abandoned.\n    this.closePendingAuthTransport();\n    if (authProvider) {\n      this._authState = 'authorized';\n    }\n  }\n\n  /**\n   * Detaches whatever transport is still attached to the underlying SDK Client.\n   *\n   * The SDK assigns its internal `_transport` before `transport.start()` and never\n   * clears it when `start()` throws, and its cleanup after a failed initialize is a\n   * fire-and-forget `void this.close()`. Either way a stale transport can remain","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/client/client.ts#L658-L694","documentation":"When connecting to a remote MCP server over HTTP, connectHttp first tries the Streamable HTTP transport; if that fails it falls back to the legacy SSE transport. If the SSE fallback also fails, it logs the SSE error and throws this aggregate error, since no HTTP transport could establish a session with the server.","triggerScenarios":"Calling connect()/connectHttp(url) where the streamable-HTTP handshake fails (4xx/5xx, wrong endpoint, non-MCP HTTP server) AND the SSE fallback also fails (endpoint rejects EventSource, 404, CORS, auth rejection).","commonSituations":"Pointing the client at a URL that is not an MCP endpoint; server only supports one transport and it is misconfigured; reverse proxy stripping EventSource headers; expired OAuth tokens rejected by both transports; server down entirely.","solutions":["Verify the url points to the MCP server's HTTP endpoint (correct path and port)","Test the endpoint manually (curl the MCP endpoint) to see the HTTP status returned","Check auth: complete any OAuth flow (finishAuth) if the server returned 401","Confirm which transports the server supports and configure the client accordingly","Check server logs and any intermediate proxy/CORS configuration"],"exampleFix":"// before\nconst client = new InternalMastraMCPClient({ name: 'x', url: 'https://api.example.com' });\n// after\nconst client = new InternalMastraMCPClient({ name: 'x', url: 'https://api.example.com/mcp' });\nawait client.connect(); // ensure /mcp is the real MCP endpoint","handlingStrategy":"try-catch","validationCode":"const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', method: 'initialize', id: 1, params: {} }) });\nif (!res.ok) throw new Error(`MCP endpoint ${url} returned HTTP ${res.status}`);","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('any available HTTP transport')) {\n    // endpoint unreachable/unsupported: check url, auth, server uptime\n  }\n  throw e;\n}","preventionTips":["Confirm the url is the actual MCP HTTP endpoint with curl before configuring","Complete OAuth (finishAuth) when the server returns 401","Verify server uptime and which transports it supports (streamable HTTP vs SSE)","Check proxy/CORS settings that block EventSource or POST requests"],"tags":["mcp","network","http","sse","transport","connection"],"backgroundTag":"connection-refused","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}