Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mcp/server/auth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AccessToken(BaseModel):
scopes: list[str]
expires_at: int | None = None
resource: str | None = None # RFC 8707 resource indicator
subject: str | None = None # Subject identifier (typically the "sub" JWT claim / user ID)


RegistrationErrorCode = Literal[
Expand Down
20 changes: 20 additions & 0 deletions tests/server/auth/middleware/test_auth_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,23 @@ async def send(message: Message) -> None: # pragma: no cover
# Verify context is still empty after middleware
assert auth_context_var.get() is None
assert get_access_token() is None


def test_access_token_subject_field():
"""Test that AccessToken supports the optional subject field."""
# Without subject (backward compatible)
token_no_sub = AccessToken(
token="token1",
client_id="client1",
scopes=["read"],
)
assert token_no_sub.subject is None

# With subject
token_with_sub = AccessToken(
token="token2",
client_id="client2",
scopes=["read", "write"],
subject="user-123",
)
assert token_with_sub.subject == "user-123"
Loading