{"record":{"id":"cd496bfb9aaba2b3","repo":"Hmbown/CodeWhale","slug":"mcp-server-server-method-failed-error","errorCode":null,"errorMessage":"MCP server '{server}': {method} failed: {error}","messagePattern":"MCP server '(.+?)': (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mcp/src/stdio_client.rs","lineNumber":924,"sourceCode":"            };\n\n            // Servers occasionally emit banners or log lines on stdout. They\n            // are skipped; only the matching response ends the wait. Valid\n            // requests and notifications are handled by the reader before\n            // they reach this rendezvous.\n            let Ok(message) = serde_json::from_str::<Value>(&line) else {\n                continue;\n            };\n            if message.get(\"jsonrpc\").and_then(Value::as_str) != Some(\"2.0\") {\n                bail!(\n                    \"MCP server '{server}': {method} received a child message without jsonrpc \\\"2.0\\\"\"\n                );\n            }\n            if message.get(\"id\").and_then(Value::as_u64) != Some(id) {\n                continue;\n            }\n            if let Some(error) = message.get(\"error\") {\n                bail!(\"MCP server '{server}': {method} failed: {error}\");\n            }\n            return message.get(\"result\").cloned().with_context(|| {\n                format!(\n                    \"MCP server '{server}': {method} response contained neither result nor error\"\n                )\n            });\n        }\n    }\n\n    /// The child's exit status, when it has one, for appending to a failure\n    /// message. Polls briefly because both callers run at the moment the child\n    /// is dying: the write can return EPIPE, or stdout can hit EOF, before the\n    /// kernel has finished reaping the process. Bounded and error-path-only,\n    /// so the cost buys a real diagnostic (\"exited with status 127\" is the\n    /// difference between a crashed server and a missing one).\n    fn exit_note(&mut self) -> String {\n        let Some(child) = self.child.as_mut() else {\n            return String::new();","sourceCodeStart":906,"sourceCodeEnd":942,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/mcp/src/stdio_client.rs#L906-L942","documentation":"When sending a JSON-RPC request to an MCP server over stdio, the client waits for a response with a matching id. If the server replies with a JSON-RPC error object instead of a result, the client bails with this message embedding the server name, method, and the server's error payload. It surfaces server-side failures (unknown method, bad params, server crash) as a client-side anyhow error.","triggerScenarios":"Calling an MCP tool/resource method via request() when the server responds with a JSON-RPC error object (e.g. method not found, invalid params, internal server error) for the matching request id.","commonSituations":"MCP server binary doesn't implement the requested method or version mismatch; tool arguments fail server-side validation; server process partially crashed mid-request; tools/list called against a server that only supports a subset of the protocol.","solutions":["Read the embedded {error} payload — it is the server's own JSON-RPC error message; fix the request (method name, params) accordingly.","Verify the server binary/version supports the method being called (check tools/list output).","Check the MCP server's stderr logs for the underlying server-side panic or error.","Reconnect/restart the server (spawn_with_timeouts) and retry if the failure was transient.","Pin a compatible MCP protocol version between client and server."],"exampleFix":"// before: calling a method the server may not implement\nlet result = client.request(\"tools/call\", params).await?;\n// after: verify capability first\nlet tools = client.request(\"tools/list\", json!({})).await?;\nif !supports(&tools, \"my_tool\") {\n    anyhow::bail!(\"server does not expose my_tool\");\n}\nlet result = client.request(\"tools/call\", params).await?;","handlingStrategy":"try-catch","validationCode":"// Before sending, confirm the server exposes the method\ncapabilities = client.request(\"tools/list\", json!({})).await?;\nanyhow::ensure!(capabilities[\"tools\"].as_array().map_or(false, |t| !t.is_empty()), \"server exposes no tools\");","typeGuard":"fn is_jsonrpc_error(msg: &Value) -> bool { msg.get(\"error\").is_some() }","tryCatchPattern":"match client.request(method, params).await {\n    Ok(result) => use(result),\n    Err(e) if e.to_string().contains(\"failed:\") => {\n        log::warn!(\"MCP server rejected {method}: {e}\");\n        // degrade gracefully or restart the server\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Discover capabilities with tools/list before calling methods","Keep client and server MCP protocol versions in sync","Capture and review MCP server stderr logs","Retry transient server errors with backoff after a reconnect"],"tags":["mcp","json-rpc","ipc"],"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"}