Title: Fix/log unknown session by dpdanpittman · Pull Request #2223 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Fix/log unknown session by dpdanpittman · Pull Request #2223 · modelcontextprotocol/python-sdk
X Title: Fix/log unknown session by dpdanpittman · Pull Request #2223 · modelcontextprotocol/python-sdk
Description: Add logger.warning() call in _handle_stateful_request() when a request is rejected due to an unknown or expired session ID. The other two branches (existing session, new session) both log, but this error path was silent. Motivation and Context As described in #2204, the else branch in StreamableHTTPSessionManager._handle_stateful_request() returns a 404 response without any logging. In production, when a client sends a stale mcp-session-id after a server restart, there is no way to observe these rejections without wrapping the ASGI app in custom middleware. A logger.warning here makes the error immediately visible in server logs. How Has This Been Tested? Extended the existing test_unknown_session_id_returns_404 test to capture log output via caplog and assert the warning message contains the rejected session ID. All 11 tests in tests/server/test_streamable_http_manager.py pass. Lint passes. Breaking Changes None. This only adds a log message at WARNING level. Existing code is unaffected. 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 Single-line fix — adds logger.warning("Rejected request with unknown or expired session ID: %s", request_mcp_session_id) before the existing error response. Consistent with the logging pattern used throughout the rest of the method.
Open Graph Description: Add logger.warning() call in _handle_stateful_request() when a request is rejected due to an unknown or expired session ID. The other two branches (existing session, new session) both log, but this...
X Description: Add logger.warning() call in _handle_stateful_request() when a request is rejected due to an unknown or expired session ID. The other two branches (existing session, new session) both log, but this...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2223
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:38ada570-f39a-4661-a71b-4b2db98ac96b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E928:35D20C:121EA0:1875DE:6A57F4EA |
| html-safe-nonce | c06ba782ebfe14dfa827e0888bc815b65b9620e3fd62d3f473d6debef6fca85e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTI4OjM1RDIwQzoxMjFFQTA6MTg3NURFOjZBNTdGNEVBIiwidmlzaXRvcl9pZCI6IjY3MDc1OTU5MDcwNzk1OTkzMzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1b8e21dc9226c6b360ef93f46a0e70c960a207e1229bddf68fe79277a517c912 |
| hovercard-subject-tag | pull_request:3361409522 |
| 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/2223/files |
| twitter:image | https://avatars.githubusercontent.com/u/8554058?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8554058?s=400&v=4 |
| og:image:alt | Add logger.warning() call in _handle_stateful_request() when a request is rejected due to an unknown or expired session ID. The other two branches (existing session, new session) both log, but this... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 49c8c15fabcbf356d607a90ca115c13b273e42ff8b74155de050fd229a9b0121 |
| 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 | 3fb1f684e7a833eb1b2d01d39875a2b52cb4fe9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width