Title: fix(server): expose session_idle_timeout via streamable_http_app() and pause reaping during active requests by Bartok9 · Pull Request #2874 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(server): expose session_idle_timeout via streamable_http_app() and pause reaping during active requests by Bartok9 · Pull Request #2874 · modelcontextprotocol/python-sdk
X Title: fix(server): expose session_idle_timeout via streamable_http_app() and pause reaping during active requests by Bartok9 · Pull Request #2874 · modelcontextprotocol/python-sdk
Description: Summary Expose session_idle_timeout through the high-level Server.streamable_http_app() / MCPServer.streamable_http_app() API so users no longer have to wire up StreamableHTTPSessionManager by hand to configure idle reaping. Stop counting a request that is actively being processed as an idle session — idle reaping is suspended for the lifetime of every in-flight request. Motivation Closes #2455. The session_idle_timeout feature (from #1994 / #2022) had two linked problems: Not exposed by streamable_http_app() — the parameter existed on StreamableHTTPSessionManager but not on the canonical app-builder API, forcing users to drop down to manual session-manager wiring. Could cancel active requests — the idle deadline was only pushed forward when a request arrived. A request still being processed when the deadline elapsed could have its session reaped mid-flight, since "in-flight" was never distinguished from "idle." Fix Thread session_idle_timeout through both streamable_http_app() methods into the session manager. Add mark_request_started() / mark_request_finished() to StreamableHTTPServerTransport: started increments an active-request counter and pushes the idle deadline to +inf (suspends reaping). finished decrements the counter and re-arms the deadline only when the last concurrent request completes; it is a no-op when no timeout is configured, and the counter never underflows. Wrap both stateful handle_request() call sites in try/finally start/finished pairs, so an active request is never counted as idle. Move task_status.started() to after idle_scope is attached, so the very first request can't race ahead of the scope it needs to suspend. Verification uv run pytest tests/server/test_streamable_http_manager.py tests/server/test_streamable_http_security.py -q — 32 passed uv run pytest tests/ -q -k "streamable or idle or session_manager" — 249 passed Existing test_idle_session_is_reaped still green (reaping of genuinely idle sessions unchanged). 7 new tests: app forwarding + default None; transport suspend/resume across overlapping requests; no-timeout no-op; counter-underflow guard. ruff format + ruff check + pyright clean on all changed files. Notes Rebuilds the intent of the stale, now-conflicting #2457 by @shaun0927 (same root cause and approach) cleanly against current main after the server modules were refactored. Crediting the original approach on that PR.
Open Graph Description: Summary Expose session_idle_timeout through the high-level Server.streamable_http_app() / MCPServer.streamable_http_app() API so users no longer have to wire up StreamableHTTPSessionManager by han...
X Description: Summary Expose session_idle_timeout through the high-level Server.streamable_http_app() / MCPServer.streamable_http_app() API so users no longer have to wire up StreamableHTTPSessionManager by han...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2874
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:59a98e08-a4e2-5a58-0c38-ec0fc0f739d6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A9D8:12A6A4:A2274D:D9226A:6A5B8B0A |
| html-safe-nonce | 3d28e82bc0be852b49168af16ee71474e71605fc567cc41cbb8f0261c245d027 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUQ4OjEyQTZBNDpBMjI3NEQ6RDkyMjZBOjZBNUI4QjBBIiwidmlzaXRvcl9pZCI6IjI4OTc4NjEzMDczNzM2ODU1MTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 22197a2e7a0ca153313594c53a5427e25ca264cf0b79f79b198fc56086db18a7 |
| hovercard-subject-tag | pull_request:3865514143 |
| 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/2874/files |
| twitter:image | https://avatars.githubusercontent.com/u/259807879?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/259807879?s=400&v=4 |
| og:image:alt | Summary Expose session_idle_timeout through the high-level Server.streamable_http_app() / MCPServer.streamable_http_app() API so users no longer have to wire up StreamableHTTPSessionManager by han... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width