{"record":{"id":"cf4cf169eaf45a68","repo":"vercel/ai","slug":"mcp-sse-transport-error-not-connected","errorCode":null,"errorMessage":"MCP SSE Transport Error: Not connected","messagePattern":"MCP SSE Transport Error: Not connected","errorType":"exception","errorClass":"MCPClientError","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/tool/mcp-sse-transport.ts","lineNumber":250,"sourceCode":"    });\n  }\n\n  async close(): Promise<void> {\n    this.connected = false;\n    this.endpoint = undefined;\n    this.sseConnection?.close();\n    this.abortController?.abort();\n    this.onclose?.();\n  }\n\n  async send(\n    message: JSONRPCMessage,\n    options?: { signal?: AbortSignal },\n  ): Promise<void> {\n    options?.signal?.throwIfAborted();\n\n    if (!this.endpoint || !this.connected) {\n      throw new MCPClientError({\n        message: 'MCP SSE Transport Error: Not connected',\n      });\n    }\n\n    const endpoint = this.endpoint as URL;\n    const transportSignal = this.abortController?.signal;\n    const requestSignal =\n      options?.signal == null\n        ? transportSignal\n        : transportSignal == null\n          ? options.signal\n          : AbortSignal.any([transportSignal, options.signal]);\n\n    const attempt = async (triedAuth: boolean = false): Promise<void> => {\n      try {\n        const headers = await this.commonHeaders({\n          'Content-Type': 'application/json',\n        });","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mcp/src/tool/mcp-sse-transport.ts#L232-L268","documentation":"SseMCPTransport.send() posts JSON-RPC messages to the endpoint URL discovered during connection. If no endpoint was captured or the connection flag is false, the transport is not in a usable session state and send() throws MCPClientError immediately.","triggerScenarios":"Calling send() before start()/connect() finished establishing the SSE endpoint; calling send() after the connection dropped (e.g. after error 724) or after close(); using a transport whose establishConnection failed silently.","commonSituations":"Application-level retries reusing a stale transport after a disconnect; sending a request concurrently with connect() before the endpoint event arrives; forgetting that close() was called on shutdown.","solutions":["Recreate the client/transport (or restart the transport) and wait for connection to be established before sending","Serialize your send calls after the connect promise resolves; don't fire requests during connection setup","After any connection error, treat the transport as dead: build a fresh one instead of retrying send() on the same instance"],"exampleFix":"// before\ntransport.close();\nawait transport.send(message); // throws\n// after\ntransport.close();\nconst transport2 = new SseMCPTransport({ url });\nawait client2 = createMCPClient({ transport: transport2 });\nawait transport2.send(message);","handlingStrategy":"try-catch","validationCode":"// expose/track connection state and check before sending\nasync function ensureConnected(client, makeTransport) {\n  if (!isConnected()) { client = await createMCPClient({ transport: makeTransport() }); }\n}","typeGuard":"function isNotConnectedError(e: unknown): boolean {\n  return MCPClientError.isInstance(e) && e.message.includes('Not connected');\n}","tryCatchPattern":"try {\n  await transport.send(message);\n} catch (error) {\n  if (isNotConnectedError(error)) {\n    transport = await reconnect(); // recreate transport and await connection\n    await transport.send(message);\n  } else throw error;\n}","preventionTips":["Only send after the connect promise resolves; queue messages issued during setup","Treat any prior connection error as fatal for the transport; rebuild instead of reusing","Check isConnected() (or equivalent state) before each send in long-running apps"],"tags":["sse","lifecycle","not-connected"],"backgroundTag":"not-connected","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}