streamable-http client: an error response to `initialize` is lost or ignored (SSE, session re-init)
メンテナーはふだん 3 日以内に返信
評価
この issue はまだ評価されていません。
説明
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.
-
The server answers the
initializePOST withtext/event-stream, and the event is an error.StreamableHttpPostResponse::expect_initializedonly stops draining onServerJsonRpcMessage::Response(_), so it logs the error at debug and moves on. If the stream then ends,serve()returnsConnectionClosed("initialize response")and the worker logsunexpected server response: empty sse stream, when process initialize response. If the server keeps the stream open,serve()never returns. The same error sent asapplication/jsoncomes back asClientInitializeError::JsonRpcError. -
With
reinit_on_expired_session(true), a 404 makes the client send a newinitialize, butperform_reinitializationdoesn't check whether the reply is an error. With anapplication/jsonerror, it still sendsnotifications/initializedand 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
serve()returnsClientInitializeError::JsonRpcErrorwith the server's code, message anddata, whether the error comes over SSE or JSON.- Recovery fails and the pending request gets an error, without sending
notifications/initializedor 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.
- 主要言語
- Rust
- スター
- 4k
- フォーク
- 662
- 平均マージ
- 3日 23時間
- マージ済み PR(30日)
- 34
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/rust-sdk のほかの issue
-
Streamable HTTP client: a 401 or 403 with a JSON-RPC error body and no WWW-Authenticate loses its HTTP status対応中かも @aton-of-data が 4 日前に担当しました。 オープンbug P2 ready for work T-security T-transport
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/rust-sdk#1339 ·
メンテナーはふだん 3 日以内に返信
-
auth: refresh_token() requests offline_access that was never granted, so refreshes fail with invalid_scope対応中かも @jstar0 が 7 日前に担当しました。 オープンbug P1 ready for work T-security T-transport
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
modelcontextprotocol/rust-sdk#1330 ·
メンテナーはふだん 3 日以内に返信
-
P3 question Stale T-documentation T-enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
modelcontextprotocol/rust-sdk#1155 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Two rmcp tests fail on Windows: connection-refused text check and `npm` spawn in test_with_js対応中かも @bolinfest が 1 日前に担当しました。 オープンbug P2 ready for work T-test
modelcontextprotocol/rust-sdk#1364 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
Client never answers a server `ping` sent during the `initialize` handshake対応中かも @bolinfest が 1 日前に担当しました。 オープンbug P1 ready for work T-service
modelcontextprotocol/rust-sdk#1362 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
modelcontextprotocol/rust-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
nannou-org/egui_graph#92 ·
メンテナーはふだん 1 日以内に返信
-
documentation good first issue
難易度 2/5 半日 初心者へのやさしさ 72/100
sujithputta02/Esapay#13 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
tursodatabase/turso#10002 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
topgrade-rs/topgrade#2419 ·
メンテナーはふだん 1 日以内に返信
-
review-bot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
midagedev/bloomery#318 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信