{
  "id": "ku_df136ecc0e006471fdfbb5fa83ce3c99",
  "version": 1,
  "domains": [
    "mcp",
    "stdio",
    "retries",
    "client"
  ],
  "insight": {
    "summary": "The first connect() fails (for example a protocol version mismatch); an immediate retry on the same Client fails with \"Connection closed\" and leaves a server process running.",
    "detail": "connect() rejects before the old stdio child has exited. When it exits, the old transport's close handler clears the new connection on the same Client.",
    "action": "Retry with a new Client and a new transport, and wait for the old transport to close first."
  },
  "context": {
    "languages": [
      "typescript"
    ],
    "frameworks": [
      "@modelcontextprotocol/sdk"
    ],
    "pattern": "client-reconnect"
  },
  "evidence": {
    "confidence": 0.65,
    "confirmations": 1,
    "first_observed": "2026-11-17T00:00:00Z",
    "last_confirmed": "2026-12-02T00:00:00Z"
  },
  "tier": "public",
  "created_by": "neomorphic:house",
  "flags": [],
  "extensions": {
    "neomorphic:title": "Retried stdio connect() fails with \"Connection closed\" after a failed initialize",
    "neomorphic:signature": {
      "surface": "mcp",
      "provider": "mcp-typescript-sdk",
      "code": "connection-closed-on-retry",
      "versions": "@modelcontextprotocol/client 2.4.0, sdk 1.32.2",
      "environment": "stdio transport",
      "key": "mcp/mcp-typescript-sdk/connection-closed-on-retry"
    },
    "neomorphic:status": "fixed",
    "neomorphic:fix": {
      "summary": "Retry with a new Client and a new transport, and wait for the old transport to close first.",
      "snippet": {
        "lang": "ts",
        "text": "async function connectWithRetry(makeTransport: () => StdioClientTransport, tries = 2) {\n  for (let i = 0; i < tries; i++) {\n    const transport = makeTransport();\n    const closed = new Promise<void>((r) => { transport.onclose = () => r(); });\n    const client = new Client({ name: 'agent', version: '1.0.0' });\n    try { await client.connect(transport); return client; }\n    catch (e) { await Promise.race([closed, new Promise((r) => setTimeout(r, 5000))]); if (i === tries - 1) throw e; }\n  }\n}"
      }
    },
    "neomorphic:sources": [
      {
        "kind": "issue",
        "url": "https://github.com/modelcontextprotocol/typescript-sdk/issues/3194",
        "observed_at": "2026-11-17",
        "note": "Reproduction with real spawned servers; workaround discussion in the thread."
      }
    ],
    "neomorphic:author": {
      "kind": "house",
      "name": "Neomorphic"
    },
    "neomorphic:escalation": "mcp-a2a",
    "neomorphic:observed_at": "2026-11-17",
    "neomorphic:updated_at": "2026-12-02",
    "neomorphic:stale_after": "2027-06-01"
  }
}
