-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersfeature requestRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedgood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on
Description
Description
I'm proposing to add subject to AccessToken in mcp/server/auth/provider.py, which can be used to store the sub JWT claim that usually corresponds to the user ID:
class AccessToken(BaseModel):
token: str
client_id: str
scopes: list[str]
expires_at: int | None = None
resource: str | None = None # RFC 8707 resource indicator
# Proposed:
subject: str | None = None # Subject (user ID)
Then we can implement a token verifier as follows:
class MyTokenVerifier:
async def verify_token(self, token: str) -> AccessToken | None:
try:
token_claims = decode_and_validate_jwt(token)
except ...:
return None
return AccessToken(
token=token,
...
subject=token_claims["sub"],
)
and directly retrieve the user ID from the auth token in the context:
from mcp.server.auth.middleware.auth_context import get_access_token
user_id = get_access_token().subject
References
No response
lukebuehler and JoseIbanez
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersfeature requestRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedgood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on