Hmbown/CodeWhale · warning
MCP SSE connect cancelled before the request completed
Error message
MCP SSE connect cancelled before the request completed
What it means
The same cancellation race, but the token fired while the initial HTTP GET to the SSE URL was awaiting a response. The bail stops the connect future from continuing after the caller already abandoned this transport instance.
Source
Thrown at crates/tui/src/mcp/sse.rs:111
auth: McpHttpAuth,
tx: tokio::sync::mpsc::Sender<SseInbound>,
cancel_token: tokio_util::sync::CancellationToken,
) -> Result<()> {
let headers = tokio::select! {
biased;
_ = cancel_token.cancelled() => {
anyhow::bail!("MCP SSE connect cancelled before authentication completed")
}
headers = auth.resolved_headers() => headers?,
};
let request = apply_safe_custom_headers(
with_default_mcp_http_headers(client.get(&url), false),
&headers,
);
let response = tokio::select! {
biased;
_ = cancel_token.cancelled() => {
anyhow::bail!("MCP SSE connect cancelled before the request completed")
}
response = request.send() => 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,
);View on GitHub (pinned to 8880682c63)
Solutions
- No action needed if it occurs during shutdown — this is the designed abort path
- If it appears in steady-state logs, find the premature cancel() call site, usually a dropped or duplicated transport handle
- Give connects a bounded budget or let them finish before cancelling to keep logs clean
Defensive patterns
Strategy: try-catch
Type guard
```rust
fn is_request_cancelled(err: &anyhow::Error) -> bool {
format!("{err:#}").contains("MCP SSE connect cancelled before the request completed")
}
``` Try / catch
```rust
match sse_transport.connect().await {
Err(e) if is_request_cancelled(&e) => return Ok(()), // caller gave up: don't retry
other => other?,
}
``` Prevention
- Avoid spawning a transport and cancelling it in the same breath; sequence connect/teardown deliberately
- Watch for duplicated transport handles causing premature cancel() calls
When it happens
Trigger: CancellationToken cancelled while the GET to the SSE URL is in flight — the user aborted the connect attempt, the session is shutting down, or a supervisor restarted the MCP client mid-request.
Common situations: Slow MCP endpoints combined with quick shutdowns; flaky networks where the user cancels before the first response; automated test teardown cancelling freshly spawned transports.
Related errors
- MCP SSE connect cancelled before authentication completed
- SSE transport cancelled before endpoint was discovered
- Runtime API request failed (${status}): ${message}
- Runtime API request failed (${status}): ${message}
- Stream read error: {e}
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/91be4bd11573aa8d.
Report an issue: GitHub.