{"record":{"id":"ad3e197b3e14d869","repo":"Hmbown/CodeWhale","slug":"mcp-error-in","errorCode":null,"errorMessage":"MCP error in '{}': {}","messagePattern":"MCP error in '(.+?)': (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/mcp.rs","lineNumber":2297,"sourceCode":"                .await\n                .with_context(|| {\n                    format!(\n                        \"MCP method '{}' on server '{}' timed out after {}s\",\n                        method, self.name, timeout_secs\n                    )\n                }) {\n                Ok(Ok(response)) => response,\n                Ok(Err(error)) => return self.finish_guarded_error(error).await,\n                Err(error) => return self.finish_guarded_error(error).await,\n            };\n\n        if let Some(error) = response.get(\"error\") {\n            if self.config.reviewed_plugin.is_some() {\n                anyhow::bail!(\n                    \"Reviewed plugin MCP server returned an error in '{method}' (server details suppressed to protect environment-backed credentials)\"\n                );\n            }\n            return Err(anyhow::anyhow!(\n                \"MCP error in '{}': {}\",\n                method,\n                serde_json::to_string_pretty(error)?\n            ));\n        }\n\n        // JSON-RPC requires exactly one of `result` / `error`. Treating a\n        // response carrying neither as an empty success handed the model a\n        // `null` tool result that is indistinguishable from a tool that\n        // genuinely returned nothing. An explicit `\"result\": null` is still a\n        // valid empty success and passes through unchanged.\n        response.get(\"result\").cloned().with_context(|| {\n            format!(\n                \"MCP response from server '{}' for '{method}' contained neither a result nor an error\",\n                self.name\n            )\n        })\n    }","sourceCodeStart":2279,"sourceCodeEnd":2315,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/mcp.rs#L2279-L2315","documentation":"The MCP client sent a JSON-RPC request (e.g. tools/list or tools/call) to the MCP server and the server replied with a JSON-RPC error object instead of a result. The library surfaces the server's error payload verbatim (pretty-printed JSON) as an anyhow error so the caller can see what the server rejected. For servers marked as reviewed plugins, details are deliberately suppressed to avoid leaking environment-backed credentials.","triggerScenarios":"Any request/response round trip through the MCP connection where response.get(\"error\") is Some: calling a tool the server does not have, malformed params to initialize/tools/call, or the server rejecting the request for auth/protocol reasons.","commonSituations":"MCP server version mismatch with the protocol the client speaks; tool invoked with wrong input schema; server-side auth token expired; server crashed mid-request and returned an error frame.","solutions":["Read the embedded JSON-RPC error object (code/message/data) in the message to identify the server-side cause.","Verify the MCP server is running the protocol version the client negotiates and supports the requested method.","Check tool input against the server-published inputSchema before calling tools/call.","If the server requires credentials, confirm they are valid in the environment where the server runs."],"exampleFix":"// before: calling a tool with ad-hoc args\nconn.call_tool(\"search\", json!({\"q\": term}))?\n// after: validate against the tool's declared inputSchema first\nlet schema = conn.tool_schema(\"search\")?;\nvalidate_json(&args, &schema)?;\nconn.call_tool(\"search\", args)?","handlingStrategy":"try-catch","validationCode":"// Pre-check: only call methods/tools the server advertises\nlet tools = conn.list_tools()?;\nif !tools.iter().any(|t| t.name == \"search\") { bail!(\"tool not offered by server\"); }","typeGuard":"fn has_rpc_error(resp: &serde_json::Value) -> Option<&serde_json::Value> {\n    resp.get(\"error\").filter(|e| e.is_object())\n}","tryCatchPattern":"match conn.call_tool(name, &args) {\n    Err(e) if e.to_string().contains(\"MCP error in\") => {\n        log::warn!(\"server rejected {name}: {e}\");\n        // surface the JSON-RPC code/message to the user, do not retry blindly\n    }\n    other => other?,\n}","preventionTips":["Validate tool inputs against the server-published inputSchema before calling.","Pin and verify the MCP server's protocol version at startup.","Keep server credentials valid and rotated where the server runs.","Log the embedded JSON-RPC error code to distinguish client vs server faults."],"tags":["mcp","json-rpc","server-error"],"backgroundTag":"api-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}