Uh oh!
There was an error while loading. Please reload this page.
feat: add subject and claims fields to AccessToken - #2209
Conversation
c76d6d5 to
cf4bce5CompareAdd two optional fields to AccessToken: - subject: str | None — stores the JWT sub claim (user ID) - claims: dict[str, Any] | None — stores arbitrary custom JWT claims Also add Context.subject property so tool handlers can read the authenticated user's subject via ctx.subject without importing get_access_token directly. Both fields default to None, preserving full backward compatibility. Closesmodelcontextprotocol#1038
cf4bce5 to
f57edfaCompareshivama205
commented
Mar 8, 2026
Friendly bump — this adds the subject and claims fields requested in this issue. All tests passing, would love a review! |
maxisbey
commented
May 26, 2026
Thanks for this — it shaped what landed. #2686 (now merged on The one piece that didn't carry over is Closing in favour of #2686. |
Closes#1038
Summary
subject: str | None = NonetoAccessToken— stores the JWTsubclaim (user ID) so token verifiers can populate it and callers can read it viaget_access_token().subjectclaims: dict[str, Any] | None = NonetoAccessToken— stores arbitrary custom JWT claims beyond the reserved set (as suggested by @robertofalk)Context.subjectproperty — lets tool handlers read the authenticated user's subject directly viactx.subjectwithout needing to importget_access_token(as suggested by @lukebuehler)Both new fields are optional with
Nonedefaults, so this is fully backward compatible.Test plan
TestAccessTokenFieldsintest_bearer_auth.py— backward compat,subjectfield,claimsfield, both together, propagation throughAuthenticatedUserTestContextSubjectintest_context.py— unauthenticated returnsNone, token without subject returnsNone, token with subject returns value, reflects live contextvar stateruff checkandruff formatcleanpyrightclean (0 errors, 0 warnings)