{"record":{"id":"b1a98fa04d37c686","repo":"koala73/worldmonitor","slug":"tools-call-failed-http-callresp-status","errorCode":null,"errorMessage":"tools/call failed: HTTP ${callResp.status}","messagePattern":"tools/call failed: HTTP (.+?)","errorType":"exception","errorClass":"McpProxyUpstreamError","httpStatus":null,"severity":"error","filePath":"api/mcp-proxy.ts","lineNumber":606,"sourceCode":"  const listData = await parseJsonRpcResponse(listResp);\n  if (listData.error) throw new McpProxyUpstreamError('tools/list error: MCP server rejected request');\n  return listData.result?.tools || [];\n}\n\nasync function mcpCallTool(serverUrl, toolName, toolArgs, customHeaders) {\n  const { response: initResp, url: sessionUrl, headers } = await postJson(\n    serverUrl, buildInitPayload(), buildHeaders(customHeaders), null,\n  );\n  if (!initResp.ok) throw new McpProxyUpstreamError(`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 McpProxyUpstreamError('Initialize error: MCP server rejected request');\n  await sendInitialized(sessionUrl, headers, sessionId);\n  const { response: callResp } = await postJson(sessionUrl, {\n    jsonrpc: '2.0', id: 3, method: 'tools/call',\n    params: { name: toolName, arguments: toolArgs || {} },\n  }, headers, sessionId);\n  if (!callResp.ok) throw new McpProxyUpstreamError(`tools/call failed: HTTP ${callResp.status}`);\n  const callData = await parseJsonRpcResponse(callResp);\n  if (callData.error) throw new McpProxyUpstreamError('tools/call error: MCP server rejected request');\n  return callData.result;\n}\n\n// --- SSE transport (HTTP+SSE, older MCP spec) ---\n// Servers whose URL path ends with /sse use this protocol:\n//   1. Client GETs the SSE URL — server opens a stream and emits an `endpoint` event\n//      containing the URL where the client should POST JSON-RPC messages.\n//   2. Client POSTs JSON-RPC to that endpoint URL.\n//   3. Server sends responses on the same SSE stream as `data:` lines.\n\nfunction isSseTransport(url) {\n  const p = url.pathname;\n  return p === '/sse' || p.endsWith('/sse');\n}\n\nfunction makeDeferred() {","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/api/mcp-proxy.ts#L588-L624","documentation":"Thrown by mcpCallTool when any request in the tools/call flow — initialize, the call itself, or session setup — received a non-2xx HTTP status from the MCP server. The remote endpoint answered but refused the request at the HTTP layer, so the tool call could not complete.","triggerScenarios":"Thrown at api/mcp-proxy.ts:338 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the HTTP status in the message to distinguish auth (401/403), routing (404), and upstream (5xx) causes","Verify serverUrl and any required custom headers for the MCP server","Retry transient 5xx statuses once; restart the session for 404 caused by an expired session id"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e586b8b4b80f595aa7ece295eec10d76f2921240","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}