Skip to content

Commit 5b41567

Browse files
author
Mrutunjay Kinagi
committed
fix(auth): normalize empty optional client metadata URIs
1 parent be5bb7c commit 5b41567

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/mcp/shared/auth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class OAuthClientMetadata(BaseModel):
6868
software_id: str | None = None
6969
software_version: str | None = None
7070

71+
@field_validator("client_uri", "logo_uri", "tos_uri", "policy_uri", "jwks_uri", mode="before")
72+
@classmethod
73+
def normalize_empty_optional_uris(cls, v: Any) -> Any:
74+
if v == "":
75+
return None
76+
return v
77+
7178
def validate_scope(self, requested_scope: str | None) -> list[str] | None:
7279
if requested_scope is None:
7380
return None

tests/client/test_auth.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ def valid_tokens():
8383
)
8484

8585

86+
def test_oauth_client_metadata_treats_empty_optional_uris_as_none():
87+
metadata = OAuthClientMetadata(
88+
redirect_uris=[AnyUrl("http://localhost:3030/callback")],
89+
client_uri="",
90+
logo_uri="",
91+
tos_uri="",
92+
policy_uri="",
93+
jwks_uri="",
94+
)
95+
96+
assert metadata.client_uri is None
97+
assert metadata.logo_uri is None
98+
assert metadata.tos_uri is None
99+
assert metadata.policy_uri is None
100+
assert metadata.jwks_uri is None
101+
102+
86103
@pytest.fixture
87104
def oauth_provider(client_metadata: OAuthClientMetadata, mock_storage: MockTokenStorage):
88105
async def redirect_handler(url: str) -> None:

0 commit comments

Comments
 (0)