Title: fix: preserve HTTP status codes in streamable HTTP transport error responses by giulio-leone · Pull Request #2176 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: preserve HTTP status codes in streamable HTTP transport error responses by giulio-leone · Pull Request #2176 · modelcontextprotocol/python-sdk
X Title: fix: preserve HTTP status codes in streamable HTTP transport error responses by giulio-leone · Pull Request #2176 · modelcontextprotocol/python-sdk
Description: Problem The streamable HTTP transport has two error propagation issues that cause clients to hang or receive uninformative error messages: 1. HTTP status codes are discarded in error responses Non-2xx responses produce generic error messages that lose the original HTTP status: 404 → ErrorData(code=INVALID_REQUEST, message="Session terminated") 401/403/500/... → ErrorData(code=INTERNAL_ERROR, message="Server returned an error response") Callers cannot distinguish auth errors (401/403) from server errors (500) or other failures. 2. Transport errors cause caller to hang Connection-level errors (timeouts, DNS failures, refused connections) raised inside _handle_post_request are not caught. When called via tg.start_soon() for JSONRPCRequest messages, the exception propagates to the task group but no JSONRPCError is written to the read stream — the caller blocks indefinitely. Fix Status code preservation Consolidated the separate 404 and >= 400 handlers into a single block that: Reads the response body for error detail Includes HTTP {status}: {body} in the error message Transport error propagation Wrapped _handle_post_request in a try/except that: Catches any exception during the HTTP request Sends a JSONRPCError through the read_stream_writer so the caller gets an error instead of hanging Re-raises the exception so the task group can handle it Test 13 fast tests pass (validation, JSON response, content type, session), 2 consecutive clean runs. Integration tests not affected (verified test_streamable_http_client_json_response passes). Fixes #2110
Open Graph Description: Problem The streamable HTTP transport has two error propagation issues that cause clients to hang or receive uninformative error messages: 1. HTTP status codes are discarded in error responses Non-...
X Description: Problem The streamable HTTP transport has two error propagation issues that cause clients to hang or receive uninformative error messages: 1. HTTP status codes are discarded in error responses Non-...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2176
X: @github
Domain: 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:4c2ff99f-074e-60ae-9444-d89ca30c3ef7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BB36:2E654B:1B8D04E:249F055:6B0575F3 |
| html-safe-nonce | e916ac6a6231aff7763782949d321bdab349a51a638402aeacef225cf0a6568a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjM2OjJFNjU0QjoxQjhEMDRFOjI0OUYwNTU6NkIwNTc1RjMiLCJ2aXNpdG9yX2lkIjoiMjMxMTE0NDM4MjYxMTc1Nzk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e55706c5bf19e5d46549c4aa1ab33c61551605fee76965d141234e6dc08706e3 |
| hovercard-subject-tag | pull_request:3338597659 |
| 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/2176/files |
| twitter:image | https://avatars.githubusercontent.com/u/6887247?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/6887247?s=400&v=4 |
| og:image:alt | Problem The streamable HTTP transport has two error propagation issues that cause clients to hang or receive uninformative error messages: 1. HTTP status codes are discarded in error responses Non-... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 507b2d62524c0f595c35a2a2ee8a6ec54b119f245b3c59eaa070013b70ed1ada |
| 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 |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e7a883ae3b439b8952652eaa7803e2587f30e339 |
| 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