Title: fix: send error to client when SSE stream disconnects without response by skyvanguard · Pull Request #1949 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: send error to client when SSE stream disconnects without response by skyvanguard · Pull Request #1949 · modelcontextprotocol/python-sdk
X Title: fix: send error to client when SSE stream disconnects without response by skyvanguard · Pull Request #1949 · modelcontextprotocol/python-sdk
Description: Summary Fixes #1811 When the SSE stream disconnects before the server sends a response (e.g., due to a read timeout on long-running tool calls), and no event ID has been received (making reconnection impossible), the client was left hanging indefinitely on read_stream.receive(). The post_writer task had already returned from _handle_sse_response() without sending anything to read_stream_writer, leaving the session layer permanently blocked. Changes Added _send_disconnect_error() method to StreamableHTTPTransport that sends a JSONRPCError (code -32000) to the read_stream_writer, unblocking the client. This is called in two scenarios: _handle_sse_response(): When the SSE stream ends without receiving a response and last_event_id is None (no event ID to reconnect with) _handle_reconnection(): When maximum reconnection attempts are exhausted without receiving a response The error surfaces as an McpError at the session layer, allowing the caller to handle the failure gracefully instead of hanging forever. Root Cause The issue was introduced when reconnection support was added. The reconnection logic correctly handles the case where last_event_id is not None (reconnect using Last-Event-ID), but the else branch (no event ID available) was missing, causing a silent return that left the client blocked. Test plan Added 2 regression tests in tests/issues/test_1811_sse_disconnect_hang.py: test_client_receives_error_on_sse_disconnect: Server has a 30s tool, client has 0.5s read timeout. Verifies the client receives McpError with "SSE stream disconnected" message instead of hanging. test_fast_tool_still_works_normally: Ensures fast tool calls continue to work correctly with the fix in place.
Open Graph Description: Summary Fixes #1811 When the SSE stream disconnects before the server sends a response (e.g., due to a read timeout on long-running tool calls), and no event ID has been received (making reconnecti...
X Description: Summary Fixes #1811 When the SSE stream disconnects before the server sends a response (e.g., due to a read timeout on long-running tool calls), and no event ID has been received (making reconnecti...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/1949
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:75bb6a48-ed1d-c308-4d06-b3e9c421199a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E840:3A432B:275913B:375BEAA:6A5F5FE4 |
| html-safe-nonce | dae786beb6e4de3a22d9873aa54c70133d5d7f71d1380489c53a0050ace54f14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODQwOjNBNDMyQjoyNzU5MTNCOjM3NUJFQUE6NkE1RjVGRTQiLCJ2aXNpdG9yX2lkIjoiMzg5MjU5MjY0MjQxMzc4MDk2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4a22b9bfb2721ef81786be625a854436f1418a6a2f6883f349983d894bc1add9 |
| hovercard-subject-tag | pull_request:3206486185 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/1949/files |
| twitter:image | https://avatars.githubusercontent.com/u/237478962?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/237478962?s=400&v=4 |
| og:image:alt | Summary Fixes #1811 When the SSE stream disconnects before the server sends a response (e.g., due to a read timeout on long-running tool calls), and no event ID has been received (making reconnecti... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9a0797c11799dbfd7df57fa3de31c7ea3a4c4bd055eb1a0427a5cde1d4d7ba3f |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b099d96da147aea31036cd16b2fba0083a6defe4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width