{"record":{"id":"2c43e420979732ce","repo":"koala73/worldmonitor","slug":"initialize-failed-http-initresp-status","errorCode":null,"errorMessage":"Initialize failed: HTTP ${initResp.status}","messagePattern":"Initialize failed: HTTP (.+?)","errorType":"exception","errorClass":null,"httpStatus":422,"severity":"error","filePath":"api/mcp-proxy.ts","lineNumber":314,"sourceCode":"}\n\nasync function sendInitialized(serverUrl, headers, sessionId) {\n  try {\n    await postJson(serverUrl, {\n      jsonrpc: '2.0',\n      method: 'notifications/initialized',\n      params: {},\n    }, headers, sessionId);\n  } catch (error) {\n    if (error instanceof McpProxySsrfError) throw error;\n    /* non-fatal */\n  }\n}\n\nasync function mcpListTools(serverUrl, customHeaders) {\n  const headers = buildHeaders(customHeaders);\n  const initResp = await postJson(serverUrl, buildInitPayload(), headers, null);\n  if (!initResp.ok) throw new Error(`Initialize failed: HTTP ${initResp.status}`);\n  const sessionId = initResp.headers.get('Mcp-Session-Id') || initResp.headers.get('mcp-session-id');\n  const initData = await parseJsonRpcResponse(initResp);\n  if (initData.error) throw new Error(`Initialize error: ${initData.error.message}`);\n  await sendInitialized(serverUrl, headers, sessionId);\n  const listResp = await postJson(serverUrl, {\n    jsonrpc: '2.0', id: 2, method: 'tools/list', params: {},\n  }, headers, sessionId);\n  if (!listResp.ok) throw new Error(`tools/list failed: HTTP ${listResp.status}`);\n  const listData = await parseJsonRpcResponse(listResp);\n  if (listData.error) throw new Error(`tools/list error: ${listData.error.message}`);\n  return listData.result?.tools || [];\n}\n\nasync function mcpCallTool(serverUrl, toolName, toolArgs, customHeaders) {\n  const headers = buildHeaders(customHeaders);\n  const initResp = await postJson(serverUrl, buildInitPayload(), headers, null);\n  if (!initResp.ok) throw new Error(`Initialize failed: HTTP ${initResp.status}`);\n  const sessionId = initResp.headers.get('Mcp-Session-Id') || initResp.headers.get('mcp-session-id');","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/koala73/worldmonitor/blob/9361220cc013571781071f0206e4d80fd14b2f7f/api/mcp-proxy.ts#L296-L332","documentation":"Thrown by mcpListTools/mcpCallTool when the JSON-RPC initialize request to the MCP server returned a non-2xx HTTP status. The endpoint was reached and answered, but rejected the initialize call (auth failure, wrong URL, gateway error), so no MCP session could be established for the tools/call or tools/list flow.","triggerScenarios":"Thrown at api/mcp-proxy.ts:312 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the HTTP status code in the message: 401/403 means missing or invalid credentials/headers, 404 a wrong endpoint URL","Verify custom headers and the serverUrl configuration for the MCP server","Retry transient 5xx responses once with backoff before reporting failure"],"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"}