Hmbown/CodeWhale · error
MCP SSE rejected (transport=http url= status= )
Error message
MCP SSE rejected (transport=http url={} status={}): {} What it means
The MCP SSE endpoint answered the initial HTTP request with a non-success status. The error includes the masked URL, HTTP status, and a bounded body excerpt (filtered through the auth layer to strip secrets), then aborts the connect.
Solutions
- Read the status and body excerpt: 401/403 → re-run OAuth or fix bearer token; 404 → fix the URL path in the server config; 5xx → retry later or check server health
- Verify the configured URL is the SSE endpoint the server actually exposes
- Check proxy/auth middleware in front of the MCP server allows the SSE route and Accept header
Example fix
// before
{"mcpServers": {"x": {"url": "https://host/api/mcp/stream"}}}
// after
{"mcpServers": {"x": {"url": "https://host/sse"}}} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight
let resp = reqwest::Client::new().get(&url).send().await?;
if !resp.status().is_success() {
return Err(anyhow!("MCP endpoint unhealthy: {}", resp.status()));
} Try / catch
match run_sse_loop(...).await {
Err(e) if e.to_string().contains("status=") => {
if e.to_string().contains("status=401") || e.to_string().contains("status=403") {
// re-run OAuth then retry once
} else { return Err(e); }
}
other => other?,
} Prevention
- Pre-flight check the SSE URL returns a success status
- Re-authenticate before the token expires
- Confirm the URL path is the server's actual SSE endpoint
When it happens
Trigger: Server returns 401/403 (missing or expired auth), 404 (wrong path), 5xx (server error) on the SSE endpoint URL; calling the SSE URL behind a reverse proxy that rejects the request.
Common situations: Expired OAuth token or revoked access; wrong SSE path in the MCP server config (e.g. `/mcp` vs `/sse`); server down or behind an authenticating proxy returning 403.
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
- MCP session expired (transport=sse endpoint= status= )
- Antigravity cloud-code SSE is not JSON
- ${compactRuntimeError(response.status, body)}
- ${compactRuntimeError(response.status, body)}
- ${compactRuntimeError(response.status, body)}
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/53484eaec5fe2a15.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/mcp/sse.rs:124
&headers,
);
let response = tokio::select! {
biased;
_ = cancel_token.cancelled() => {
anyhow::bail!("MCP SSE connect cancelled before the request completed")
}
response = client.send(request) => response.with_context(|| {
format!(
"MCP SSE connect failed (transport=http url={})",
mask_url_secrets(&url),
)
})?,
};
let status = response.status();
if !status.is_success() {
let body_excerpt = bounded_body_excerpt(response, ERROR_BODY_PREVIEW_BYTES).await;
let body_excerpt = auth.server_error_preview(&body_excerpt);
anyhow::bail!(
"MCP SSE rejected (transport=http url={} status={}): {}",
mask_url_secrets(&url),
status,
body_excerpt,
);
}
let mut stream = response.bytes_stream();
use futures_util::StreamExt;
// Raw byte buffer so a multi-byte UTF-8 char split across reads is not
// corrupted, and bounded so a separator-less server cannot OOM us.
let mut buffer: Vec<u8> = Vec::new();
loop {
if cancel_token.is_cancelled() {
tracing::debug!("SSE loop cancelled");
break;
}View on GitHub (pinned to 73e0f67d83)