Hmbown/CodeWhale · error · anyhow::Error

MCP error in '{}': {}

Error message

MCP error in '{}': {}

What it means

The non-reviewed path of call_method error handling: the MCP server answered tools/call, resources/read or prompts/get with a JSON-RPC `error` object and Codewhale forwards it pretty-printed, tagged with the method (crates/tui/src/mcp.rs:2109-2113). Unlike the reviewed-plugin variant, the full code/message object is visible to the caller.

Source

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

                .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)?
            ));
        }

        Ok(response
            .get("result")
            .cloned()
            .unwrap_or(serde_json::json!(null)))
    }

    /// Get discovered tools
    pub fn tools(&self) -> &[McpTool] {
        &self.tools
    }

    /// Get discovered resources

View on GitHub (pinned to 8880682c63)

Solutions

  1. Read the code/message in the pretty-printed object - it is the server's diagnosis; correct the arguments or the server-side condition accordingly.
  2. Validate arguments against the tool's input_schema (available from the discovered McpTool) before calling.
  3. For transient upstream errors, retry the individual call after backoff.
Defensive patterns

Strategy: try-catch

Try / catch

match conn.call_tool(tool, args, timeout).await {
    Ok(value) => value,
    Err(err) => {
        let msg = err.to_string();
        if let Some(rest) = msg.strip_prefix("MCP error in ") {
            // rest contains 'method': {pretty-printed JSON-RPC error}; parse
            // code/message to decide between fix-args, retry, or fail.
            tracing::warn!(error = %rest, "MCP tool call error");
        }
        return Err(err);
    }
}

Prevention

When it happens

Trigger: Invalid tool arguments (-32602), unknown tool name, server-side execution failures, or auth/limit errors returned as JSON-RPC errors on a per-call basis.

Common situations: Schema drift between discovered input schemas and actual server validation; transient upstream failures; tools that error on edge-case arguments.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/ad3e197b3e14d869. Report an issue: GitHub.