Title: fix(auth): get_access_token reflects current request in stateful sessions by Epochex · Pull Request #2675 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(auth): get_access_token reflects current request in stateful sessions by Epochex · Pull Request #2675 · modelcontextprotocol/python-sdk
X Title: fix(auth): get_access_token reflects current request in stateful sessions by Epochex · Pull Request #2675 · modelcontextprotocol/python-sdk
Description: Fixes #2208. Stateful Streamable HTTP sessions start the server task group on the first request. Anyio copies the request contextvars into that long-lived task, so get_access_token() could keep returning the token from the session-creating request even when later requests send a different Authorization header. This change pushes the authenticated user into the auth contextvar at request-dispatch time (using the ServerMessageMetadata.request_context threaded through the transport), and resets it after the handler returns. Tests: uv run python -m pytest tests/server/auth/middleware/test_auth_context.py tests/server/auth/test_get_access_token_streamable_http.py
Open Graph Description: Fixes #2208. Stateful Streamable HTTP sessions start the server task group on the first request. Anyio copies the request contextvars into that long-lived task, so get_access_token() could keep ret...
X Description: Fixes #2208. Stateful Streamable HTTP sessions start the server task group on the first request. Anyio copies the request contextvars into that long-lived task, so get_access_token() could keep ret...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2675
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:579f7b62-07a7-6e13-e9e6-8012d129a015 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A9B8:81538:DC157:DFBCB:6A60FA7B |
| html-safe-nonce | 8ce1c5cbeb3009b2713c300c007c53dd32d6fec4f00fd1797786231f52d89e94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUI4OjgxNTM4OkRDMTU3OkRGQkNCOjZBNjBGQTdCIiwidmlzaXRvcl9pZCI6IjcxNTY3NzgzNjkwNTYwOTg1MSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 97f824dbcc198558c8fccaaf8d63aecef57a97bbf821c72582ba1b70dd91ce45 |
| hovercard-subject-tag | pull_request:3738530139 |
| 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/2675/files |
| twitter:image | https://avatars.githubusercontent.com/u/68621077?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/68621077?s=400&v=4 |
| og:image:alt | Fixes #2208. Stateful Streamable HTTP sessions start the server task group on the first request. Anyio copies the request contextvars into that long-lived task, so get_access_token() could keep ret... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 40a35f8d38abec207dcde39ffae0c0d14012c6d27b769f13fdac3ab78dc77ebe |
| 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 | ef41e0ca8cf502957b8d49077bbe7c8dcdcbb037 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width