Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Mart22052006 · Pull Request #3785 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Mart22052006 · Pull Request #3785 · modelcontextprotocol/python-sdk
X Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Mart22052006 · Pull Request #3785 · modelcontextprotocol/python-sdk
Description: Fixes #2110 (the SSE part, on v1.x; #3278 covers main) Backports the SSE half of #3278 to v1.x: a failed message POST now resolves its request with a JSON-RPC error instead of leaving the caller hanging. Motivation and Context sse_client's post_writer called raise_for_status() on every message POST and swallowed the error in a catch-all. A request whose POST failed (a 429 from a rate limiter, a 401, a refused connection) was never resolved: its caller waited for its own timeout, or forever without one. The write loop died with it, so every later message was dropped. We hit this in production: a 429 from a rate limiter in front of an MCP server left an agent's tool call waiting 90 minutes for an unrelated outer timeout. How Has This Been Tested? 10 new tests in tests/shared/test_sse.py, all of which fail on unpatched v1.x (7 hang, 3 end with a closed stream or the wrong error): non-2xx answers (302, 401, 429, 500) and a refused connection reach the caller, and the session keeps working; a 404 maps to "Session terminated" only while the endpoint carries a session id; a failed notification is only logged; a server request answered while a request's POST is failing (the test times out if the error is delivered inline); a failure whose error can no longer be delivered, after the SSE stream ended, is contained. The full suite passes with 100% coverage, along with pyright and ruff. The SSE tests also pass on 3.10 with lowest-direct deps and on 3.14. Breaking Changes None. A caller that used to hang now gets an McpError, and later messages keep flowing. 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 am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer): asked on #2110 I have disclosed any AI assistance and can explain the change in my own words 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 The outcomes match #3278 on main: a non-2xx status gives INTERNAL_ERROR "Server returned an error response", or INVALID_REQUEST "Session terminated" for a 404 while the endpoint carries a session id; an error before any response gives CONNECTION_CLOSED "Failed to send message: …". One v1.x-specific difference: the error is delivered from a task of its own. v1.x ClientSession answers server requests inline in its receive loop, so a reply can be waiting on the write stream just as the error needs the receive loop, and delivering it from the write loop deadlocks. AI assistance: written with Claude Code, as the commit's Co-Authored-By trailer notes.
Open Graph Description: Fixes #2110 (the SSE part, on v1.x; #3278 covers main) Backports the SSE half of #3278 to v1.x: a failed message POST now resolves its request with a JSON-RPC error instead of leaving the caller ha...
X Description: Fixes #2110 (the SSE part, on v1.x; #3278 covers main) Backports the SSE half of #3278 to v1.x: a failed message POST now resolves its request with a JSON-RPC error instead of leaving the caller ha...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3785
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ad837a1c-e50b-707e-d274-6e2f03b3a284 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D4C8:96DDF:146DF0A:19E1EE7:6B01268D |
| html-safe-nonce | dc87f333856de5dd340778cdc172f8815e018488e2988df99f63faf896ecaef5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEM4Ojk2RERGOjE0NkRGMEE6MTlFMUVFNzo2QjAxMjY4RCIsInZpc2l0b3JfaWQiOiI2NTY2MjEwOTEzNzYwNzgxOTY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0b8f5b18ef864704819763ec4cb0218eb6ff55f7656aeb38fa485469c4cf4f63 |
| hovercard-subject-tag | pull_request:5059293748 |
| 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/3785/files |
| twitter:image | https://avatars.githubusercontent.com/u/157504417?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/157504417?s=400&v=4 |
| og:image:alt | Fixes #2110 (the SSE part, on v1.x; #3278 covers main) Backports the SSE half of #3278 to v1.x: a failed message POST now resolves its request with a JSON-RPC error instead of leaving the caller ha... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width