Hmbown/CodeWhale · error

MCP SSE POST rejected

Error message

MCP SSE POST rejected (transport=sse endpoint={} status={}): {}

What it means

The MCP SSE transport's POST to the session endpoint returned a non-success HTTP status that was not recognized as an expired session. The error includes the masked endpoint URL, status code, and a bounded preview of the response body (with auth-server-specific redaction applied).

Solutions

  1. Read the status and body excerpt in the message to identify the server's complaint.
  2. For 401/403, refresh or reconfigure credentials for the MCP server.
  3. For 400, check that the MCP server version matches the client's expected protocol.
  4. For 5xx, check server health/logs and retry after the outage.
  5. For 404, verify the endpoint URL/path configuration.
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = transport.send(msg).await {
    let msg = e.to_string();
    if msg.contains("status=401") || msg.contains("status=403") {
        refresh_credentials()?; // auth problem
    } else if msg.contains("status=50") {
        schedule_retry_with_backoff(); // server-side outage
    } else {
        return Err(e); // client-side request problem, do not blind-retry
    }
}

Prevention

When it happens

Trigger: Any non-2xx response from the SSE session POST that isn't a stale-session body: 400 malformed JSON-RPC payload, 401/403 auth rejected, 404 unknown endpoint, 5xx server error.

Common situations: Expired or revoked auth token (401/403); MCP server API changed so the request shape is rejected (400); server outage (502/503); misconfigured endpoint path returning 404 HTML.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/mcp/sse.rs:304

            format!(
                "MCP SSE POST send failed (transport=sse endpoint={})",
                mask_url_secrets(&endpoint)
            )
        })?;
        let status = response.status();
        if !status.is_success() {
            let body_excerpt = bounded_body_excerpt(response, ERROR_BODY_PREVIEW_BYTES).await;
            let stale_session = is_mcp_stale_session_body(&body_excerpt);
            let body_excerpt = self.auth.server_error_preview(&body_excerpt);
            if stale_session {
                anyhow::bail!(
                    "MCP session expired (transport=sse endpoint={} status={}): {}",
                    mask_url_secrets(&endpoint),
                    status,
                    body_excerpt
                );
            }
            anyhow::bail!(
                "MCP SSE POST rejected (transport=sse endpoint={} status={}): {}",
                mask_url_secrets(&endpoint),
                status,
                body_excerpt
            );
        }
        Ok(())
    }

    async fn recv(&mut self) -> Result<Vec<u8>> {
        loop {
            match self.receiver.recv().await.context("SSE transport closed")? {
                SseInbound::Endpoint(endpoint) => {
                    self.store_endpoint(&endpoint)?;
                }
                SseInbound::Message(msg) => return Ok(msg),
            }
        }

View on GitHub (pinned to 73e0f67d83)