Title: fix(streamable-http): expose session_idle_timeout and pause idle reaping during active requests by shaun0927 · Pull Request #2457 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(streamable-http): expose session_idle_timeout and pause idle reaping during active requests by shaun0927 · Pull Request #2457 · modelcontextprotocol/python-sdk
X Title: fix(streamable-http): expose session_idle_timeout and pause idle reaping during active requests by shaun0927 · Pull Request #2457 · modelcontextprotocol/python-sdk
Description: Fixes #2455 Summary This PR fixes two linked session_idle_timeout problems in the StreamableHTTP stack: expose session_idle_timeout through the public streamable_http_app() entrypoints suspend idle reaping while one or more requests are actively in flight Motivation and Context PR #1994 / #2022 describe session_idle_timeout as a way to reap sessions that receive no HTTP requests for the configured duration. Current main has two mismatches with that contract: StreamableHTTPSessionManager(...) accepts session_idle_timeout, but Server.streamable_http_app(...) and MCPServer.streamable_http_app(...) do not, so the canonical high-level API cannot configure the feature the idle deadline can fire while a request is still being processed, terminating the session mid-handler even though the session is not idle in any practical sense Changes add session_idle_timeout passthrough to: mcp.server.lowlevel.server.Server.streamable_http_app() mcp.server.mcpserver.server.MCPServer.streamable_http_app() track active request count on StreamableHTTPServerTransport suspend idle reaping while requests are active restore the idle deadline only after the last active request finishes initialize the idle scope before the first request can complete How Has This Been Tested? Added focused regression coverage in tests/server/test_streamable_http_manager.py: test_streamable_http_app_exposes_session_idle_timeout test_session_idle_timeout_does_not_cancel_in_flight_request The second test uses a handler that runs longer than the configured idle timeout and verifies that the request still completes successfully. Existing idle reaping coverage (test_idle_session_is_reaped) continues to pass, so finished sessions are still cleaned up normally. Local verification: uv run --frozen pytest tests/server/test_streamable_http_manager.py uv run --frozen ruff check src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py src/mcp/server/streamable_http.py src/mcp/server/streamable_http_manager.py tests/server/test_streamable_http_manager.py uv run --frozen pyright src/mcp/server/lowlevel/server.py src/mcp/server/mcpserver/server.py src/mcp/server/streamable_http.py src/mcp/server/streamable_http_manager.py Breaking Changes None. 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
Open Graph Description: Fixes #2455 Summary This PR fixes two linked session_idle_timeout problems in the StreamableHTTP stack: expose session_idle_timeout through the public streamable_http_app() entrypoints suspend idl...
X Description: Fixes #2455 Summary This PR fixes two linked session_idle_timeout problems in the StreamableHTTP stack: expose session_idle_timeout through the public streamable_http_app() entrypoints suspend idl...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2457
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:027ebbed-b877-6cf7-eea1-ba4e7d36f6f7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8296:238CA7:F5F6B2:13BCC48:6A5C32C4 |
| html-safe-nonce | c4a5c3ee92e9968977114bdca298b8f5779bb3257c840f0a2c59817ebdea5f77 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Mjk2OjIzOENBNzpGNUY2QjI6MTNCQ0M0ODo2QTVDMzJDNCIsInZpc2l0b3JfaWQiOiIyMTk2ODE5MzEyMDQ4MzUzOTg4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d9cb4a37591ca5721db7019f56298a7e3c9a8d8bb6c987e04408ae2cdb306ff4 |
| hovercard-subject-tag | pull_request:3540326366 |
| 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/2457/files |
| twitter:image | https://avatars.githubusercontent.com/u/70629228?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/70629228?s=400&v=4 |
| og:image:alt | Fixes #2455 Summary This PR fixes two linked session_idle_timeout problems in the StreamableHTTP stack: expose session_idle_timeout through the public streamable_http_app() entrypoints suspend idl... |
| 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