{"record":{"id":"f3c36082aba08d8c","repo":"koala73/worldmonitor","slug":"tools-list-failed-http-listresp-status","errorCode":null,"errorMessage":"tools/list failed: HTTP ${listResp.status}","messagePattern":"tools/list failed: HTTP (.+?)","errorType":"exception","errorClass":"McpProxyUpstreamError","httpStatus":null,"severity":"error","filePath":"api/mcp-proxy.ts","lineNumber":587,"sourceCode":"  } catch (error) {\n    if (error instanceof McpProxySsrfError) throw error;\n    /* non-fatal */\n  }\n}\n\nasync function mcpListTools(serverUrl, 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: listResp } = await postJson(sessionUrl, {\n    jsonrpc: '2.0', id: 2, method: 'tools/list', params: {},\n  }, headers, sessionId);\n  if (!listResp.ok) throw new McpProxyUpstreamError(`tools/list failed: HTTP ${listResp.status}`);\n  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);","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/api/mcp-proxy.ts#L569-L605","documentation":"Thrown by mcpListTools after a successful initialize when the follow-up tools/list request to the MCP server returned a non-2xx HTTP status. The session was established but the tools enumeration call was rejected (expired/missing Mcp-Session-Id, auth, or upstream failure).","triggerScenarios":"Thrown at api/mcp-proxy.ts:320 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the returned status: a 404 often means the Mcp-Session-Id expired or was not forwarded","Ensure custom headers required by the server are applied to every request, not just initialize","Retry the whole connect-and-list flow to obtain a fresh session"],"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"}