{"record":{"id":"3ee7632f7f62e3f1","repo":"koala73/worldmonitor","slug":"sse-connect-http-resp-status","errorCode":null,"errorMessage":"SSE connect HTTP ${resp.status}","messagePattern":"SSE connect HTTP (.+?)","errorType":"exception","errorClass":null,"httpStatus":422,"severity":"error","filePath":"api/mcp-proxy.ts","lineNumber":383,"sourceCode":"  constructor(sseUrl, headers) {\n    this._sseUrl = sseUrl;\n    this._originHost = new URL(sseUrl).host;\n    this._originProtocol = new URL(sseUrl).protocol;\n    this._headers = headers;\n    this._endpointUrl = null;\n    this._endpointDeferred = makeDeferred();\n    this._pending = new Map(); // rpc id -> deferred\n    this._reader = null;\n  }\n\n  async connect() {\n    await revalidateBeforeFetch(new URL(this._sseUrl));\n    const resp = await fetch(this._sseUrl, {\n      headers: { ...this._headers, Accept: 'text/event-stream', 'Cache-Control': 'no-cache' },\n      redirect: 'manual',\n      signal: AbortSignal.timeout(SSE_CONNECT_TIMEOUT_MS),\n    });\n    if (!resp.ok) throw new Error(`SSE connect HTTP ${resp.status}`);\n    this._reader = resp.body.getReader();\n    this._startReadLoop();\n    await this._endpointDeferred.promise;\n  }\n\n  _startReadLoop() {\n    const dec = new TextDecoder();\n    let buf = '';\n    let eventType = '';\n    const reader = this._reader;\n\n    (async () => {\n      try {\n        while (true) {\n          const { done, value } = await reader.read();\n          if (done) {\n            // Stream closed — if endpoint never arrived, reject so connect() throws\n            if (!this._endpointUrl) {","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/koala73/worldmonitor/blob/9361220cc013571781071f0206e4d80fd14b2f7f/api/mcp-proxy.ts#L365-L401","documentation":"Thrown by SseSession.connect when the initial SSE GET to the MCP server's streamable-HTTP endpoint returned a non-2xx status. The SSRF revalidation passed but the server refused the event-stream connection (auth, wrong URL, or transient upstream failure), so no SSE transport could be established.","triggerScenarios":"Thrown at api/mcp-proxy.ts:381 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the status code: 401/403 indicates missing auth headers on the SSE connection, 404 a wrong SSE endpoint URL","Confirm the server supports the legacy SSE transport, not only streamable HTTP POST","Retry transient 5xx statuses; SSE endpoints behind load balancers can fail intermittently"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9361220cc013571781071f0206e4d80fd14b2f7f","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}