René's URL Explorer Experiment


Title: Fix infinite reconnection loop in StreamableHTTP client by Dharit13 · Pull Request #2395 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Fix infinite reconnection loop in StreamableHTTP client by Dharit13 · Pull Request #2395 · modelcontextprotocol/python-sdk

X Title: Fix infinite reconnection loop in StreamableHTTP client by Dharit13 · Pull Request #2395 · modelcontextprotocol/python-sdk

Description: Summary Fixes #2393. _handle_reconnection() reset the attempt counter to 0 when the SSE stream ended without delivering a complete response (only priming events). This made MAX_RECONNECTION_ATTEMPTS ineffective — a server that accepts connections but always drops streams caused the client to retry forever, hanging the caller indefinitely. Root cause: Line 426 in streamable_http.py recursed with attempt=0 whenever the stream ended without a JSONRPCResponse/JSONRPCError, regardless of whether any useful data was received. Fix: Distinguish productive reconnections (ones that delivered actual message data like notifications) from unproductive ones (only priming events). Productive reconnections reset the counter so legitimate multi-close patterns (e.g., SSE polling with server-side disconnect) continue working. Unproductive reconnections increment the counter. When MAX_RECONNECTION_ATTEMPTS is reached, the client now sends a JSONRPCError back through the read stream so the caller gets unblocked instead of hanging forever. Changes src/mcp/client/streamable_http.py: Track whether actual message data (not just priming events) was received during a reconnection. Only reset the attempt counter when data was delivered. Send an error response to the caller when max attempts are exceeded. tests/shared/test_streamable_http.py: Add tool_with_perpetual_stream_close (server tool that always closes the stream without responding) and test_reconnection_gives_up_after_max_attempts (regression test proving the client gives up and raises MCPError instead of looping forever). How Has This Been Tested New regression test test_reconnection_gives_up_after_max_attempts — verifies the client raises MCPError after max attempts with a fail-after timeout of 30s (completes in ~2s) All 62 existing test_streamable_http.py tests pass, including the multi-reconnection tests (test_streamable_http_multiple_reconnections, test_streamable_http_client_auto_reconnects, test_standalone_get_stream_reconnection) pyright — 0 errors ruff check + ruff format — clean strict-no-cover — clean Breaking Changes None. Productive reconnections (where actual data is delivered before the stream drops) continue to reset the counter, preserving existing behavior. Only unproductive reconnections (no message data, just priming events) now correctly increment toward the limit. Made with Cursor

Open Graph Description: Summary Fixes #2393. _handle_reconnection() reset the attempt counter to 0 when the SSE stream ended without delivering a complete response (only priming events). This made MAX_RECONNECTION_ATTEMPT...

X Description: Summary Fixes #2393. _handle_reconnection() reset the attempt counter to 0 when the SSE stream ended without delivering a complete response (only priming events). This made MAX_RECONNECTION_ATTEMPT...

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

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:8884464f-334d-8069-1158-a68058434194
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8022:11EACE:49CCB7:64C48F:6B00CD85
html-safe-noncedeccc8baad018334080c4c8d8df7a79f4bd0b66ea55b78846151a87b43437e03
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDIyOjExRUFDRTo0OUNDQjc6NjRDNDhGOjZCMDBDRDg1IiwidmlzaXRvcl9pZCI6IjI3OTA3MTg0MDQ2Nzg0MzgyNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8c244d27c81ebc635095a2a572c57a5679bb280f1afdddf85d34d55c61e99133
hovercard-subject-tagpull_request:3490818905
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/2395/files
twitter:imagehttps://avatars.githubusercontent.com/u/23332982?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/23332982?s=400&v=4
og:image:altSummary Fixes #2393. _handle_reconnection() reset the attempt counter to 0 when the SSE stream ended without delivering a complete response (only priming events). This made MAX_RECONNECTION_ATTEMPT...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5
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
release4943239a6d2c591325dad6e5c313e1cafda877f6
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2395%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%2F2395%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/2395/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)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
Dharit13https://github.com/Dharit13
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
Dharit13:fix/reconnection-attempt-counter-resethttps://github.com/Dharit13/python-sdk/tree/fix/reconnection-attempt-counter-reset
Conversation 1 https://github.com/modelcontextprotocol/python-sdk/pull/2395
Commits 1 https://github.com/modelcontextprotocol/python-sdk/pull/2395/commits
Checks 25 https://github.com/modelcontextprotocol/python-sdk/pull/2395/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2395/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files
Fix infinite reconnection loop in StreamableHTTP client https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#top
Show all changes 1 commit https://github.com/modelcontextprotocol/python-sdk/pull/2395/files
35eff18 Fix infinite reconnection loop in StreamableHTTP client dhshah13 Apr 5, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2395/commits/35eff18cf4bbcd063dfc08de7c7a06404b0cd46b
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2395/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
test_streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
src/mcp/client/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
View file https://github.com/modelcontextprotocol/python-sdk/blob/35eff18cf4bbcd063dfc08de7c7a06404b0cd46b/src/mcp/client/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2395/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-e8c18a3067a9b157c5c39a947f53d395afeb00e7026dad2d5a279011da943b5e
tests/shared/test_streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
View file https://github.com/modelcontextprotocol/python-sdk/blob/35eff18cf4bbcd063dfc08de7c7a06404b0cd46b/tests/shared/test_streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2395/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
https://github.com/modelcontextprotocol/python-sdk/pull/2395/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2395/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.