zeroclaw-labs/zeroclaw · error · anyhow::Error

MCP response id mismatch: expected

Error message

MCP response id mismatch: expected {:?}, received {:?}

What it means

finish_response matched the JSON-RPC response id against the request id and they differ — the server replied to a different call (or the id was mangled by an intermediary). Correlating replies to the wrong request would corrupt call semantics, so the mismatch is rejected.

Solutions

  1. The MCP server answered out of order or the wrong request; restart the server connection and retry.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/zeroclaw-tools/src/mcp_transport.rs:1119 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/c4985665c2ce6627. Report an issue: GitHub.

Appendix: source

Thrown at crates/zeroclaw-tools/src/mcp_transport.rs:1119

    fn update_session_id_from_headers(&self, headers: &reqwest::header::HeaderMap) {
        if let Some(session_id) = headers
            .get(MCP_SESSION_ID_HEADER)
            .and_then(|v| v.to_str().ok())
            .map(str::trim)
            .filter(|v| !v.is_empty())
        {
            *self.session_id.lock() = Some(session_id.to_string());
        }
    }
}

fn finish_response(
    request: &JsonRpcRequest,
    lifecycle: &McpRequestLifecycle,
    response: JsonRpcResponse,
) -> Result<JsonRpcResponse> {
    if response.id != request.id {
        bail!(
            "MCP response id mismatch: expected {:?}, received {:?}",
            request.id,
            response.id
        );
    }
    lifecycle.mark_completed();
    Ok(response)
}

#[async_trait::async_trait]
impl SharedMcpTransportConn for HttpTransport {
    async fn send_and_recv(
        &self,
        request: &JsonRpcRequest,
        lifecycle: &McpRequestLifecycle,
    ) -> Result<JsonRpcResponse> {
        let body = serde_json::to_string(request)?;

View on GitHub (pinned to 88bb9c8533)