Title: Handle Abrupt Server Disconnect in Middle of Tool Call by EiffL · Pull Request #1321 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Handle Abrupt Server Disconnect in Middle of Tool Call by EiffL · Pull Request #1321 · modelcontextprotocol/python-sdk
X Title: Handle Abrupt Server Disconnect in Middle of Tool Call by EiffL · Pull Request #1321 · modelcontextprotocol/python-sdk
Description: Propagates transport disconnects (e.g. server killed mid tool call) as CONNECTION_CLOSED errors instead of hanging indefinitely. Adds regression test. Motivation and Context A call_tool over the StreamableHTTP transport would hang forever if the server closed the SSE/HTTP connection mid-response (e.g. process crash/kill). The underlying RemoteProtocolError was logged but in‑flight requests never completed. This change converts that low-level failure into a deterministic JSON-RPC error for every pending request, matching expected resilience semantics. How Has This Been Tested? Added integrated test test_streamable_http_mid_call_disconnect: Starts real server process. Invokes long-running tool (wait_for_lock_with_notification). Kills server mid-call. Asserts an McpError with code CONNECTION_CLOSED (previously would hang). All existing tests pass locally. Breaking Changes None. Behavior only changes for abnormal transport termination; normal flows unaffected. No public API changes. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Checklist I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context Implementation details: In _handle_sse_response (client transport) on exception: send the exception into the session read stream then close the writer to signal termination. In BaseSession._receive_loop: on receiving an Exception, broadcast a synthesized JSONRPCError (code CONNECTION_CLOSED) to all pending request streams and clear them. Integrated test placed alongside existing StreamableHTTP tests for consistency. Potential follow-up: introduce optional reconnection/resumption logic for recoverable disconnects.
Open Graph Description: Propagates transport disconnects (e.g. server killed mid tool call) as CONNECTION_CLOSED errors instead of hanging indefinitely. Adds regression test. Motivation and Context A call_tool over the St...
X Description: Propagates transport disconnects (e.g. server killed mid tool call) as CONNECTION_CLOSED errors instead of hanging indefinitely. Adds regression test. Motivation and Context A call_tool over the St...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/1321
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c185e099-8ed4-0c9e-7c54-a8b7cd50787e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 80AC:1184E2:1435A04:1CFBC87:6A634902 |
| html-safe-nonce | 51537cf27c9c4e0e6ac115d9a9eeba229368ae90f2f5b66b0cf4e2aad1588306 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEFDOjExODRFMjoxNDM1QTA0OjFDRkJDODc6NkE2MzQ5MDIiLCJ2aXNpdG9yX2lkIjoiNDY5MjM0NzMwMTMyNzQ4OTI4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3eb0afa781f0a56697c486b1c6297aff4c402a0d5553a1cb36cf508e22bce7c5 |
| hovercard-subject-tag | pull_request:2783256377 |
| 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/1321/files |
| twitter:image | https://avatars.githubusercontent.com/u/861591?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/861591?s=400&v=4 |
| og:image:alt | Propagates transport disconnects (e.g. server killed mid tool call) as CONNECTION_CLOSED errors instead of hanging indefinitely. Adds regression test. Motivation and Context A call_tool over the St... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| 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 | 990295d92a4cc7b63fbbd83a046217cd7d77d49c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width