{"record":{"id":"5de71b2e209c8c52","repo":"musistudio/claude-code-router","slug":"mcp-request-failed-this-server-name-string","errorCode":null,"errorMessage":"MCP request failed (${this.server.name}): ${String(response.error.message ?? \"Unknown error\")}","messagePattern":"MCP request failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/mcp/toolhub-mcp.ts","lineNumber":1175,"sourceCode":"    this.initialized = true;\n  }\n\n  private async notification(method: string, params: Record<string, unknown>): Promise<void> {\n    await this.frame({ jsonrpc: \"2.0\", method, params }, this.server.requestTimeoutMs, true);\n  }\n\n  private async request(method: string, params: Record<string, unknown>, timeoutMs = this.server.requestTimeoutMs): Promise<unknown> {\n    const response = await this.frame({\n      id: randomUUID(),\n      jsonrpc: \"2.0\",\n      method,\n      params\n    }, timeoutMs, false);\n    if (!isRecord(response)) {\n      throw new Error(`Invalid MCP response from ${this.server.name}.`);\n    }\n    if (isRecord(response.error)) {\n      throw new Error(`MCP request failed (${this.server.name}): ${String(response.error.message ?? \"Unknown error\")}`);\n    }\n    return response.result;\n  }\n\n  private async frame(request: Record<string, unknown>, timeoutMs = defaultRequestTimeoutMs, notification: boolean): Promise<unknown> {\n    const controller = new AbortController();\n    const timer = setTimeout(() => controller.abort(), timeoutMs);\n    try {\n      const headers = new Headers({\n        accept: \"application/json, text/event-stream\",\n        \"content-type\": \"application/json\",\n        ...(this.server.headers ?? {})\n      });\n      const apiKey = this.server.apiKey || (this.server.apiKeyEnv ? process.env[this.server.apiKeyEnv] : \"\");\n      if (apiKey && !headers.has(\"authorization\")) {\n        headers.set(\"authorization\", `Bearer ${apiKey}`);\n      }\n      if (this.sessionId) {","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/mcp/toolhub-mcp.ts#L1157-L1193","documentation":"Thrown when a JSON-RPC request to an MCP server returns a response object containing an `error` field. The message embeds the server name and the error message returned by the remote MCP server (or \"Unknown error\" if the error object lacks a message). This is the library's wrapper for protocol-level MCP failures (tool call failures, invalid params, method not found) as opposed to transport failures.","triggerScenarios":"Calling any MCP tool/method through ToolHubMcpClient (request/tools/call, initialize, etc.) where the remote server replies with a JSON-RPC error object, e.g. unknown tool name, invalid tool arguments, or a server-side execution failure.","commonSituations":"Passing arguments that don't match the tool's input schema; calling a tool name that was renamed or removed on the server; server-side version mismatches after upgrading an MCP server; expired MCP sessions causing the server to reject subsequent requests.","solutions":["Inspect the embedded server message — it is the remote server's own error text and usually names the real cause (e.g. schema violation)","Validate your tool arguments against the tool's inputSchema returned by tools/list before calling","Verify the tool name still exists on the server (re-fetch tools/list after server upgrades)","If sessions expire, reconnect/re-initialize the MCP client and retry once"],"exampleFix":"// before\nconst result = await client.callTool(\"search\", { q: 123 });\n\n// after\nconst tools = await client.listTools();\nconst tool = tools.find(t => t.name === \"search\");\n// validate args against tool.inputSchema (e.g. with ajv) before calling\nconst result = await client.callTool(\"search\", { q: \"hello\" });","handlingStrategy":"try-catch","validationCode":"const tools = await client.listTools();\nconst tool = tools.find(t => t.name === toolName);\nif (!tool) throw new Error(`Unknown tool: ${toolName}`);\nconst valid = ajv.validate(tool.inputSchema, args);\nif (!valid) throw new Error(`Invalid args: ${JSON.stringify(ajv.errors)}`);","typeGuard":"const isRpcError = (e: unknown): boolean =>\n  e instanceof Error && e.message.startsWith(\"MCP request failed\");","tryCatchPattern":"try {\n  const result = await client.callTool(toolName, args);\n} catch (e) {\n  if (isRpcError(e)) {\n    // server-returned error message is embedded; log and surface to user\n    logger.warn(e.message);\n    return { error: e.message };\n  }\n  throw e;\n}","preventionTips":["Validate args against tool.inputSchema from tools/list before every call","Re-fetch the tool list after upgrading the remote MCP server","Re-initialize the client when session errors appear"],"tags":["mcp","json-rpc","remote-error","tool-call"],"backgroundTag":"json-rpc-server-error","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}