tinyhumansai/openhuman · error · anyhow::Error

Failed to parse MCP JSON response: {e} — body: {text}

Error message

Failed to parse MCP JSON response: {e} — body: {text}

What it means

The MCP server's non-SSE HTTP response body was not valid JSON — serde_json::from_str failed on the raw text, which is included in the message. The endpoint may be returning an HTML error page, a proxy interstitial, or a truncated body.

Source

Thrown at src/openhuman/mcp/http_client/client.rs:809

            while let Some(chunk) = stream.next().await {
                raw.extend_from_slice(&chunk?);
                // Decode the whole buffer each pass so a multi-byte UTF-8
                // sequence split across chunk boundaries is never corrupted.
                if let Some(data) = first_complete_sse_data(&String::from_utf8_lossy(&raw))? {
                    frame = Some(data);
                    break;
                }
            }
            match frame {
                Some(data) => data,
                // Stream ended without a data frame — fall back to the whole-body
                // parser for a clear "no data frame" error that includes the body.
                None => parse_sse_message(&String::from_utf8_lossy(&raw))?,
            }
        } else {
            let text = response.text().await?;
            serde_json::from_str(&text).map_err(|e| {
                anyhow::anyhow!("Failed to parse MCP JSON response: {e} — body: {text}")
            })?
        };
        if let Some(err) = payload.get("error") {
            anyhow::bail!("MCP error: {err}");
        }
        let result = payload
            .get("result")
            .ok_or_else(|| anyhow::anyhow!("MCP response missing `result`: {payload}"))?
            .clone();
        Ok(ResponseEnvelope {
            result,
            session_id: header_to_string(&headers, HEADER_SESSION_ID),
        })
    }
}

#[cfg(test)]
#[path = "client_tests.rs"]

View on GitHub (pinned to 7491200858)

Solutions

  1. Read the logged body snippet to identify HTML error pages or proxy responses
  2. Confirm the URL points at the MCP endpoint, not a human-facing page
  3. Check for corporate TLS-inspection proxies rewriting the response
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/openhuman/mcp/http_client/client.rs:809 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/297b4492fc8a0336. Report an issue: GitHub.