Hmbown/CodeWhale · error · anyhow::Error

MCP error in

Error message

MCP error in '{}': {}

What it means

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.

Solutions

  1. Read the embedded JSON-RPC error object (code/message/data) in the message to identify the server-side cause.
  2. Verify the MCP server is running the protocol version the client negotiates and supports the requested method.
  3. Check tool input against the server-published inputSchema before calling tools/call.
  4. If the server requires credentials, confirm they are valid in the environment where the server runs.

Example fix

// before: calling a tool with ad-hoc args
conn.call_tool("search", json!({"q": term}))?
// after: validate against the tool's declared inputSchema first
let schema = conn.tool_schema("search")?;
validate_json(&args, &schema)?;
conn.call_tool("search", args)?
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check: only call methods/tools the server advertises
let tools = conn.list_tools()?;
if !tools.iter().any(|t| t.name == "search") { bail!("tool not offered by server"); }

Type guard

fn has_rpc_error(resp: &serde_json::Value) -> Option<&serde_json::Value> {
    resp.get("error").filter(|e| e.is_object())
}

Try / catch

match conn.call_tool(name, &args) {
    Err(e) if e.to_string().contains("MCP error in") => {
        log::warn!("server rejected {name}: {e}");
        // surface the JSON-RPC code/message to the user, do not retry blindly
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/ad3e197b3e14d869. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp.rs:2297

                .await
                .with_context(|| {
                    format!(
                        "MCP method '{}' on server '{}' timed out after {}s",
                        method, self.name, timeout_secs
                    )
                }) {
                Ok(Ok(response)) => response,
                Ok(Err(error)) => return self.finish_guarded_error(error).await,
                Err(error) => return self.finish_guarded_error(error).await,
            };

        if let Some(error) = response.get("error") {
            if self.config.reviewed_plugin.is_some() {
                anyhow::bail!(
                    "Reviewed plugin MCP server returned an error in '{method}' (server details suppressed to protect environment-backed credentials)"
                );
            }
            return Err(anyhow::anyhow!(
                "MCP error in '{}': {}",
                method,
                serde_json::to_string_pretty(error)?
            ));
        }

        // JSON-RPC requires exactly one of `result` / `error`. Treating a
        // response carrying neither as an empty success handed the model a
        // `null` tool result that is indistinguishable from a tool that
        // genuinely returned nothing. An explicit `"result": null` is still a
        // valid empty success and passes through unchanged.
        response.get("result").cloned().with_context(|| {
            format!(
                "MCP response from server '{}' for '{method}' contained neither a result nor an error",
                self.name
            )
        })
    }

View on GitHub (pinned to 73e0f67d83)