René's URL Explorer Experiment


Title: fix(client): surface non-2xx HTTP responses to the waiting caller by himanshu-commits · Pull Request #3092 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix(client): surface non-2xx HTTP responses to the waiting caller by himanshu-commits · Pull Request #3092 · modelcontextprotocol/python-sdk

X Title: fix(client): surface non-2xx HTTP responses to the waiting caller by himanshu-commits · Pull Request #3092 · modelcontextprotocol/python-sdk

Description: Relates to #3091. A 4xx/5xx response to a message POST hit a bare response.raise_for_status() inside the POST's background task. Nothing caught the exception and nothing resolved the request, so the caller sat until its read timeout fired: a 401 was indistinguishable from a slow server, and the escaping error tore down the transport's task group with it. Non-2xx statuses are now answered rather than raised, generalising the handling 404 already had: a JSONRPCError stamped with the original request's id, sent as a SessionMessage over the read stream, so it resolves through the normal response-correlation path. A spec-compliant JSON-RPC error in the body is preferred over the status-derived stand-in. The connection stays usable — a 500 on one tools/list no longer kills the next call. Motivation and Context Reported in #3091: HTTP status errors never reached the caller, and were indistinguishable from a timeout. This is fixed on the 2.0 line already; per the discussion on the issue, this PR backports the equivalent behaviour to v1.x, where the bug still reproduces (1.25.0 / 1.28.1). One deliberate difference from 2.0 2.0 checks the response body before the 404 fallback; this PR checks 404 first. A terminated session 404s with a JSON-RPC error body, so preferring it would replace this line's Session terminated / code 32600 — which callers match on for session expiry — with the server's own wording. Two existing tests caught this. Behaviour is identical to 2.0 for every status this issue is actually about. Related: that 32600 is positive, where JSON-RPC codes are negative (2.0 corrected it to -32600). I've left it alone — changing it would break anyone checking error.code == 32600 on a stable release. Happy to change it if you'd rather. Note on 3xx raise_for_status() used to raise for any non-2xx; the new guard is >= 400, so a redirect falls through to the content-type dispatch rather than the correlated-error path. In practice create_mcp_http_client sets follow_redirects=True, so this only affects user-supplied clients with redirects disabled — and 2.0 carries the identical >= 400 guard, so it's parity, not a regression. Tracked separately rather than widened here. What this does not fix Callers still cannot tell a terminal 401 from a retryable 503: both arrive as -32603 Server returned an error response, exactly as on 2.0. The issue's stated impact (retry policy) therefore isn't fully addressed here. Carrying the originating status on error.data would close that, but belongs on the 2.0 line first — happy to follow up. How Has This Been Tested? Ten new tests in tests/shared/test_streamable_http.py, driven in-memory via httpx.MockTransport: 401 / 403 / 500 / 503 each reach the waiting caller. Each is wrapped in anyio.fail_after(5), so without the fix they hang rather than pass vacuously — that's the regression pin. 404 still reports Session terminated (guard on the unchanged behaviour) a JSON-RPC error body is preferred, re-stamped with the request's id a JSON body that isn't a JSON-RPC error (proxy/gateway JSON) falls back to the stand-in a non-2xx body that dies mid-read still resolves the caller a non-2xx to a notification resolves nobody and leaves the session alive a failed request leaves the session usable Full suite passes (1149), 100% branch coverage. Six # pragma: no cover markers removed from the 404 path, which was previously untested and is now exercised. Breaking Changes None. 404 handling is preserved byte-for-byte, including its code and message. Every other non-2xx previously raised an exception that escaped the transport; it now resolves the caller instead. 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 _handle_resumption_request still carries a bare raise_for_status() — the same bug class on the resumption GET path, unfixed on 2.0 as well. Out of scope here; noting it so it isn't lost.

Open Graph Description: Relates to #3091. A 4xx/5xx response to a message POST hit a bare response.raise_for_status() inside the POST's background task. Nothing caught the exception and nothing resolved the request, s...

X Description: Relates to #3091. A 4xx/5xx response to a message POST hit a bare response.raise_for_status() inside the POST's background task. Nothing caught the exception and nothing resolved the reques...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3092

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:bd764733-dbdc-d81f-34d3-f890ffc982e0
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC49E:6365:14FAAD8:1BFCC3B:6B0134E4
html-safe-nonce0380c6f7225333fc4bd7435476f1665343e7a8d08c196acea904603c25cbe460
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDlFOjYzNjU6MTRGQUFEODoxQkZDQzNCOjZCMDEzNEU0IiwidmlzaXRvcl9pZCI6IjkyMjA1ODY4Mjk2Njc5NzIzMjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5c174fe650ebcd417e4f6448c4f4ee35f3f3d08dd239f9fa0001af81022504e7
hovercard-subject-tagpull_request:4048513295
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3092/files
twitter:imagehttps://avatars.githubusercontent.com/u/82858309?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/82858309?s=400&v=4
og:image:altRelates to #3091. A 4xx/5xx response to a message POST hit a bare response.raise_for_status() inside the POST's background task. Nothing caught the exception and nothing resolved the request, s...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3092%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3092%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues315 (315)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
himanshu-commitshttps://github.com/himanshu-commits
modelcontextprotocol:v1.xhttps://github.com/modelcontextprotocol/python-sdk/tree/v1.x
himanshu-commits:fix/streamable-http-status-error-3091-v1xhttps://github.com/himanshu-commits/python-sdk/tree/fix/streamable-http-status-error-3091-v1x
Conversation 8 https://github.com/modelcontextprotocol/python-sdk/pull/3092
Commits 2 https://github.com/modelcontextprotocol/python-sdk/pull/3092/commits
Checks 26 https://github.com/modelcontextprotocol/python-sdk/pull/3092/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/3092/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
fix(client): surface non-2xx HTTP responses to the waiting caller https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#top
Show all changes 2 commits https://github.com/modelcontextprotocol/python-sdk/pull/3092/files
d53d47b fix(client): surface non-2xx HTTP responses to the waiting caller himanshu-commits Jul 13, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3092/commits/d53d47bf1c8de443179baa13597c9206df36e582
a674d2a fix(client): catch read failures on the non-2xx body himanshu-commits Jul 13, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3092/commits/a674d2ac2dbecb2aeff0837ed445fd0f2f99d865
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3092/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
test_streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
src/mcp/client/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
View file https://github.com/modelcontextprotocol/python-sdk/blob/a674d2ac2dbecb2aeff0837ed445fd0f2f99d865/src/mcp/client/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3092/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
tests/shared/test_streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
View file https://github.com/modelcontextprotocol/python-sdk/blob/a674d2ac2dbecb2aeff0837ed445fd0f2f99d865/tests/shared/test_streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3092/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/3092/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3092/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.