Skip to content

Commit 1343c18

Browse files
committed
Updating token validator return type to comply with MCP sdk.
Signed-off-by: Eric Evans <[email protected]>
1 parent a86c8ad commit 1343c18

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/nat/data_models/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class TokenValidationResult(BaseModel):
184184
"""
185185
model_config = ConfigDict(extra="forbid")
186186

187-
client_id: str = Field(description="OAuth2 client identifier")
187+
client_id: str | None = Field(description="OAuth2 client identifier")
188188
scopes: list[str] | None = Field(default=None, description="List of granted scopes (introspection only)")
189189
expires_at: int | None = Field(default=None, description="Token expiration time (Unix timestamp)")
190190
audience: list[str] | None = Field(default=None, description="Token audiences (aud claim)")

src/nat/front_ends/mcp/introspection_token_verifier.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
"""OAuth 2.0 Token Introspection verifier implementation for MCP servers."""
1616

1717
import logging
18-
from typing import Any
19-
from typing import overload
2018

2119
from mcp.server.auth.provider import AccessToken
2220
from mcp.server.auth.provider import TokenVerifier
2321

2422
from nat.authentication.credential_validator.bearer_token_validator import BearerTokenValidator
2523
from nat.authentication.oauth2.oauth2_resource_server_config import OAuth2ResourceServerConfig
26-
from nat.data_models.authentication import TokenValidationResult
2724

2825
logger = logging.getLogger(__name__)
2926

@@ -67,21 +64,20 @@ def __init__(self, config: OAuth2ResourceServerConfig):
6764
client_secret=client_secret,
6865
)
6966

70-
@overload
71-
async def verify_token(self, token: str) -> TokenValidationResult | None:
72-
...
73-
74-
@overload
7567
async def verify_token(self, token: str) -> AccessToken | None:
76-
...
77-
78-
async def verify_token(self, token: str) -> Any:
7968
"""Verify token by delegating to BearerTokenValidator.
8069
8170
Args:
8271
token: The Bearer token to verify
8372
8473
Returns:
85-
TokenValidationResult | AccessToken | None
74+
AccessToken | None: AccessToken if valid, None if invalid
8675
"""
87-
return await self._bearer_token_validator.verify(token)
76+
validation_result = await self._bearer_token_validator.verify(token)
77+
78+
if validation_result.active:
79+
return AccessToken(token=token,
80+
expires_at=validation_result.expires_at,
81+
scopes=validation_result.scopes or [],
82+
client_id=validation_result.client_id or "")
83+
return None

src/nat/front_ends/mcp/mcp_front_end_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ class MCPFrontEndConfig(FrontEndBaseConfig, name="mcp"):
4242
default=None, description="Custom worker class for handling MCP routes (default: built-in worker)")
4343

4444
server_auth: OAuth2ResourceServerConfig | None = Field(
45-
description=("OAuth 2.0 Resource Server configuration for token verification."))
45+
default=None, description=("OAuth 2.0 Resource Server configuration for token verification."))

0 commit comments

Comments
 (0)