René's URL Explorer Experiment


Title: [v1.x] Expire idle Streamable HTTP sessions by default and cap concurrent sessions by maxisbey · Pull Request #3426 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: [v1.x] Expire idle Streamable HTTP sessions by default and cap concurrent sessions by maxisbey · Pull Request #3426 · modelcontextprotocol/python-sdk

X Title: [v1.x] Expire idle Streamable HTTP sessions by default and cap concurrent sessions by maxisbey · Pull Request #3426 · modelcontextprotocol/python-sdk

Description: v1.x backport of #3395. Stateful Streamable HTTP sessions get a lifecycle the server owns on 1.x too: a session is forgotten and its transport terminated as soon as it ends, sessions with nothing in flight expire after session_idle_timeout (default 30 minutes), and a manager admits at most max_sessions (default 10 000) and answers 503 beyond that. Both are FastMCP(...) keyword arguments and Settings fields. Motivation and Context Same as #3395: session_idle_timeout existed on StreamableHTTPSessionManager but defaulted to None and could not be set from FastMCP, so at stock settings a session whose client never sent DELETE stayed registered until the process exited. This brings the 1.x line to the same defaults and the same bookkeeping (a DELETE really frees the session, a refused or failed opening request leaves nothing behind, a cancelled stateless request still terminates its transport). Differences from #3395: The per-session task drives Server.run() rather than serve_loop. Idle expiry ends a session by discarding it, which closes the transport's streams the way a client DELETE does, rather than by cancelling Server.run(). On 1.x Server.run() enters the server's lifespan per session, so this keeps the lifespan teardown of an expired session identical to that of a deleted one instead of running it under cancellation. The settings are FastMCP constructor arguments and Settings fields rather than run() / app-factory keywords, and FastMCP.streamable_http_app() takes no options. The manager's JSON-RPC error bodies keep this branch's "id": "server-error" envelope. The transport also closes its per-request SSE streams when a response ends (the 1.x share of an earlier change on main), which the in-process tests rely on. Tests drive the manager through raw ASGI callables. Documentation lives in docs/server.md ("Session lifetime and limits"). How Has This Been Tested? The tests from #3395 ported to this branch's helpers, plus one 1.x-specific case: an expired session's lifespan teardown runs to completion. Full suite, pyright and ruff pass locally. Also exercised end to end against FastMCP(...).streamable_http_app() under uvicorn with the SDK client and raw HTTP. Breaking Changes As in #3395: no signature loses anything and every new parameter has a default, but two defaults are now active where previously there was no limit. session_idle_timeout defaults to 1800: a session with no request in flight for 30 minutes is closed and its next request gets 404. Pass None for the previous behaviour. max_sessions defaults to 10_000. Pass None to remove the limit. Constructing a stateless manager with a timeout no longer raises, and session_idle_timeout must be finite. 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) 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 Thanks to @raphaelOhana for #3059, which covered part of this on 1.x and is superseded here. AI Disclaimer

Open Graph Description: v1.x backport of #3395. Stateful Streamable HTTP sessions get a lifecycle the server owns on 1.x too: a session is forgotten and its transport terminated as soon as it ends, sessions with nothing i...

X Description: v1.x backport of #3395. Stateful Streamable HTTP sessions get a lifecycle the server owns on 1.x too: a session is forgotten and its transport terminated as soon as it ends, sessions with nothing i...

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

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:1de7985b-c8b6-c28b-aa97-0356d6d905bd
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC0CE:C2718:103952:15BD14:6B00BB40
html-safe-nonce2b3ac1836ca23ad0d251b7af679a2ca2a438d22e9b7a9b2ed1f4d330366bd824
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMENFOkMyNzE4OjEwMzk1MjoxNUJEMTQ6NkIwMEJCNDAiLCJ2aXNpdG9yX2lkIjoiNjY5MjgzNDE0NzQ0Mzk4MTEyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacffe7edbcb5c9cf30a567b162b73c739191808ff9a380ea7740670856f32f3ce6
hovercard-subject-tagpull_request:4414657307
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/3426/files
twitter:imagehttps://avatars.githubusercontent.com/u/224885523?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/224885523?s=400&v=4
og:image:altv1.x backport of #3395. Stateful Streamable HTTP sessions get a lifecycle the server owns on 1.x too: a session is forgotten and its transport terminated as soon as it ends, sessions with nothing i...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2
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
release5429cbfc6aca8c7b9a086a3c8f47400346f38cc9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3426%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%2F3426%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/3426/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3426/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
maxisbeyhttps://github.com/maxisbey
v1.xhttps://github.com/modelcontextprotocol/python-sdk/tree/v1.x
session-retention-defaults-v1xhttps://github.com/modelcontextprotocol/python-sdk/tree/session-retention-defaults-v1x
Conversation 5 https://github.com/modelcontextprotocol/python-sdk/pull/3426
Commits 2 https://github.com/modelcontextprotocol/python-sdk/pull/3426/commits
Checks 33 https://github.com/modelcontextprotocol/python-sdk/pull/3426/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/3426/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files
[v1.x] Expire idle Streamable HTTP sessions by default and cap concurrent sessions https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#top
Show all changes 2 commits https://github.com/modelcontextprotocol/python-sdk/pull/3426/files
2f502bc [v1.x] Expire idle Streamable HTTP sessions by default and cap concur… maxisbey Aug 28, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3426/commits/2f502bccf98c10c5ce80b78c8d4d4a10728bbf46
d469302 Reset sse-starlette's cached exit event around every test maxisbey Sep 1, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3426/commits/d4693026a97d01655a91989f93834f875e072db7
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3426/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files
server.md https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
server.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
streamable_http_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-1071ee05567116cb77322c376307b9071c6212871068ccf41911fc337ed473af
conftest.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128
test_server.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-2c82340ecf6b6a4c0adbc7f94f272d810dca759a8bba8c3066b4110afc2fd586
test_sse_security.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-c4352f0bf263a51087a1f9dbd97e778a2fa4bf3fc0eced12e4bb84af262b7d8e
test_streamable_http_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-ee0bac8ccf39135f1347002539cc4af38ee7e89b85595884e94fb4ab304a111d
test_streamable_http.py https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-57d1f3c64af36960aa61b1d77387fb6201b90fbc2f3d606bf2761315ce618cc5
docs/server.mdhttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
View file https://github.com/modelcontextprotocol/python-sdk/blob/d4693026a97d01655a91989f93834f875e072db7/docs/server.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3426/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-307dce2103600fbe7bdad557e2576f7c0a7f658e9600357c81ba7c4b642d49b6
src/mcp/server/fastmcp/server.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
View file https://github.com/modelcontextprotocol/python-sdk/blob/d4693026a97d01655a91989f93834f875e072db7/src/mcp/server/fastmcp/server.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3426/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-14a2991a8f2be5b9e60dab5fae92d2230dc23e57937ad5e5641b832d9c662738
src/mcp/server/streamable_http.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
View file https://github.com/modelcontextprotocol/python-sdk/blob/d4693026a97d01655a91989f93834f875e072db7/src/mcp/server/streamable_http.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3426/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
https://github.com/modelcontextprotocol/python-sdk/pull/3426/files#diff-0119e4c1bbf2fde7ba89b9c9f5bc472ccc2332f84e96e47cf9e45cebef801da3
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3426/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3426/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.