Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

streamable-http client: an error response to `initialize` is lost or ignored (SSE, session re-init)

Chiusa
#1,360 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@bolinfest ci sta già lavorando.

Dal 14/10/2026.

  • #1361 di @gocamille — integrata

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug P1 ready for work T-transport

Describe the bug

This is about the 2025-11-25 initialize handshake and Mcp-Session-Id sessions. There are two places where the streamable-http client doesn't handle a JSON-RPC error that comes back for initialize.

  1. The server answers the initialize POST with text/event-stream, and the event is an error. StreamableHttpPostResponse::expect_initialized only stops draining on ServerJsonRpcMessage::Response(_), so it logs the error at debug and moves on. If the stream then ends, serve() returns ConnectionClosed("initialize response") and the worker logs unexpected server response: empty sse stream, when process initialize response. If the server keeps the stream open, serve() never returns. The same error sent as application/json comes back as ClientInitializeError::JsonRpcError.

  2. With reinit_on_expired_session(true), a 404 makes the client send a new initialize, but perform_reinitialization doesn't check whether the reply is an error. With an application/json error, it still sends notifications/initialized and then retries the original request, both without a session id, even though no new session was set up. An SSE error here currently fails with "empty sse stream" like case 1, and would go down the same path as JSON once case 1 is fixed.

To Reproduce (main at 8d226f4)

Case 1: a mock server answers POST /mcp with 200, Content-Type: text/event-stream and one event:

data: {"jsonrpc":"2.0","id":0,"error":{"code":-32602,"message":"Unsupported protocol version","data":{"supported":["2024-11-05"],"requested":"1.0.0"}}}

This is the example error from the spec's lifecycle page, but any error response to initialize does the same thing.

let res = tokio::time::timeout(
    Duration::from_secs(3),
    ().serve(StreamableHttpClientTransport::from_uri(uri)),
)
.await;
server response result
SSE error event (no event id), then the stream ends Err(ConnectionClosed("initialize response"))
SSE error event, stream held open still pending after 3s
same error as application/json Err(JsonRpcError(-32602 ...))

Case 2: a mock server accepts the first initialize (session s1), returns 404 for the next request on s1, and answers the second initialize with the same error as application/json. These are the POSTs it gets:

initialize                 session=None
notifications/initialized  session=Some("s1")
tools/list                 session=Some("s1")   <- 404
initialize                 session=None         <- error response
notifications/initialized  session=None
tools/list                 session=None

Expected behavior

  1. serve() returns ClientInitializeError::JsonRpcError with the server's code, message and data, whether the error comes over SSE or JSON.
  2. Recovery fails and the pending request gets an error, without sending notifications/initialized or retrying.

Additional context

The drain loop came in with #467 so that notifications sent before the initialize response don't break the handshake. #569 (for #563) made the service layer report an initialize error, but the SSE branch here never hands the error to it. Letting Error(_) end the loop at streamable_http_client.rs:317 fixes case 1. Case 2 needs its own check in perform_reinitialization, otherwise fixing case 1 just moves SSE errors during recovery onto the JSON path.

I can open a PR for both.

Lingua principale
Rust
Stelle
4k
Fork
662
Merge medio
3g 20h
PR unite (30g)
30

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/rust-sdk

Tutte le issue di modelcontextprotocol/rust-sdk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.