Hmbown/CodeWhale · warning

SSE transport cancelled before endpoint was discovered

Error message

SSE transport cancelled before endpoint was discovered

What it means

After a successful connect, the transport waits for the server's mandatory endpoint event. If the CancellationToken fires during that wait, this bail aborts cleanly — the connection was torn down (shutdown, reconnect, disable) before the SSE handshake finished.

Source

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

                        return Ok(());
                    }
                }
            }
        }
        Ok(())
    }

    async fn wait_for_endpoint(
        &mut self,
        cancel_token: &tokio_util::sync::CancellationToken,
        endpoint_timeout: Duration,
    ) -> Result<()> {
        let timeout = tokio::time::sleep(endpoint_timeout);
        tokio::pin!(timeout);

        let msg = tokio::select! {
            _ = cancel_token.cancelled() => {
                anyhow::bail!("SSE transport cancelled before endpoint was discovered");
            }
            _ = &mut timeout => {
                anyhow::bail!(
                    "SSE endpoint not received within {}ms",
                    endpoint_timeout.as_millis()
                );
            }
            msg = self.receiver.recv() => {
                msg.context("SSE transport closed before endpoint was discovered")?
            }
        };

        match msg {
            SseInbound::Endpoint(endpoint) => self.store_endpoint(&endpoint),
            SseInbound::Message(_) => {
                anyhow::bail!("MCP SSE server sent a message before declaring its endpoint");
            }
        }

View on GitHub (pinned to 8880682c63)

Solutions

  1. Treat as cancellation noise during teardown; confirm the cancel() was intended
  2. If it recurs outside shutdown, inspect reconnect logic for premature cancellation of healthy connects
Defensive patterns

Strategy: try-catch

Type guard

```rust
fn is_endpoint_wait_cancelled(err: &anyhow::Error) -> bool {
    format!("{err:#}").contains("SSE transport cancelled before endpoint was discovered")
}
```

Try / catch

```rust
match transport.wait_for_endpoint(&cancel, timeout).await {
    Err(e) if is_endpoint_wait_cancelled(&e) => return Ok(()), // teardown, not failure
    other => other?,
}
```

Prevention

When it happens

Trigger: Session close or MCP server disable in the window between HTTP connect success and receipt of the first endpoint event.

Common situations: User quits while a slow server is still emitting its first event; retry logic cancelling the previous attempt too early.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/2af8b50ea45a57a8. Report an issue: GitHub.