feat: add subject and claims fields to AccessToken#2125
Open
aptsalt wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
feat: add subject and claims fields to AccessToken#2125aptsalt wants to merge 1 commit intomodelcontextprotocol:mainfrom
aptsalt wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add optional `subject` and `claims` fields to `AccessToken` to support JWT claim access without requiring token re-decoding. - `subject: str | None` stores the JWT "sub" claim (user/resource owner ID) - `claims: dict[str, Any] | None` stores additional decoded token claims Both fields are optional with None defaults, maintaining full backward compatibility. Resolves modelcontextprotocol#1038
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional
subjectandclaimsfields toAccessToken, allowing token verifiers to expose decoded JWT claims without requiring consumers to re-decode the token.Problem: After token verification, there's no way to access the JWT
subclaim (user ID) or custom claims throughAccessToken. Consumers must decode the token a second time or add custom middleware, as described in #1038.Solution:
Usage in a token verifier:
Then in tool handlers:
Changes
src/mcp/server/auth/provider.py: Addsubjectandclaimsoptional fields toAccessTokentests/server/auth/test_provider.py: Add 7 tests covering new fields, backward compatibility, and serialization roundtripBreaking Changes
None. Both fields default to
None. Existing code is unaffected.Test Plan
Resolves #1038