pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/pull/2675

/assets/actions-9111c292f95f2fb0.css" /> fix(auth): get_access_token reflects current request in stateful sessions by Epochex · Pull Request #2675 · modelcontextprotocol/python-sdk · GitHub
Skip to content

fix(auth): get_access_token reflects current request in stateful sessions#2675

Open
Epochex wants to merge 4 commits into
modelcontextprotocol:mainfrom
Epochex:fix/streamable-http-auth-context-current-request
Open

fix(auth): get_access_token reflects current request in stateful sessions#2675
Epochex wants to merge 4 commits into
modelcontextprotocol:mainfrom
Epochex:fix/streamable-http-auth-context-current-request

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented May 24, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_access_token() returns stale token in stateful streamable-HTTP sessions

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy