Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Darshak03 · Pull Request #3892 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Darshak03 · Pull Request #3892 · modelcontextprotocol/python-sdk
X Title: [v1.x] Resolve a failed SSE message POST instead of hanging the caller by Darshak03 · Pull Request #3892 · modelcontextprotocol/python-sdk
Description: Fixes #2110 (the SSE half, on v1.x). This brings the SSE fix from #3278 (on main) to v1.x. Problem When the SSE transport's message POST fails, with a non-2xx status or an exception, post_writer logs Error in post_writer and stops. The request that was sent never gets a response, so the caller waits out the full session read timeout, and every later message in that session is dropped because the writer is gone. This matters most where response time is critical. A phone-call voice agent connects to its MCP server when a call is answered, and every second of silence counts. Today a failed POST turns into a long wait, and by the time the timeout fires the caller has often hung up. If the request failed at once, the agent could hand the call to a human agent while the caller is still on the line. Fix post_writer now resolves the failed request instead of stopping: a non-2xx status: INTERNAL_ERROR "Server returned an error response"; a 404 on an endpoint that carries a session id: INVALID_REQUEST "Session terminated", as the streamable HTTP transport does; an exception raised by the POST (network error, auth flow, event hook): CONNECTION_CLOSED; a failed notification has no caller waiting, so it is only logged. The writer keeps running, so the session stays usable after a failed POST. The error is sent to the read stream from its own task. On v1.x the client session answers server requests (for example roots/list) inside its receive loop. If the writer delivered the error itself, it could block while that loop is blocked sending a reply to the writer, and both would hang. A test covers this interleaving. Tests New tests in tests/shared/test_sse.py use an in-process SSE server that fails chosen POSTs: initialize answered with 302, 401, 429, 500 or 503 fails at once with McpError, with a 20 s session read timeout; a later tools/call answered with 500 fails at once, and the next ping and tool call succeed; a POST that raises fails its request with CONNECTION_CLOSED, and the session keeps working; the 404 mapping with and without a session id; a failed notification leaves the session usable; a failed POST while a server request is being answered does not deadlock; an error that can no longer be delivered, because the read stream closed, does not stop the writer. All of them fail on unpatched v1.x. uv run pytest passes (1342 passed) with 100% coverage, and ruff check, ruff format --check and pyright are clean.
Open Graph Description: Fixes #2110 (the SSE half, on v1.x). This brings the SSE fix from #3278 (on main) to v1.x. Problem When the SSE transport's message POST fails, with a non-2xx status or an exception, post_write...
X Description: Fixes #2110 (the SSE half, on v1.x). This brings the SSE fix from #3278 (on main) to v1.x. Problem When the SSE transport's message POST fails, with a non-2xx status or an exception, post_w...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3892
X: @github
Domain: redirect.github.com
IPv4 address: 140.82.114.3
| 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:744913dd-ae8c-1cd6-b99f-3d19ab981517 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B9D4:4AA2A:1EE6D2C:28D9532:6B056EA9 |
| html-safe-nonce | 32babbbf01a4eeac9e4ccbfe77c433aa549362c81024687b20972f8b2727f6bd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUQ0OjRBQTJBOjFFRTZEMkM6MjhEOTUzMjo2QjA1NkVBOSIsInZpc2l0b3JfaWQiOiIyMDUzNjA1Mzc1NjI2MDE0Mzc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 574648fb4bd2ee084d18c274e75dffe72afca2213d442568a1b73c7eb02f445a |
| hovercard-subject-tag | pull_request:5438660798 |
| 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/3892/files |
| twitter:image | https://avatars.githubusercontent.com/u/115038906?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/115038906?s=400&v=4 |
| og:image:alt | Fixes #2110 (the SSE half, on v1.x). This brings the SSE fix from #3278 (on main) to v1.x. Problem When the SSE transport's message POST fails, with a non-2xx status or an exception, post_write... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9b4256ac5f3e310e7945ef5b71c9cb9e264357b1eb20e91d369ed6502a4c486c |
| 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 | f089e689ad324655ac44bf6cdbc04d976105b374 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width