Skip to content

fix(auth): normalize redirect URI URL subclasses#2808

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/redirect-uri-anyurl-subtypes
Open

fix(auth): normalize redirect URI URL subclasses#2808
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/redirect-uri-anyurl-subtypes

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

Fixes #2687.

OAuthClientInformationFull.redirect_uris is declared as list[AnyUrl], but Pydantic v2 preserves already-validated URL subclasses such as AnyHttpUrl. That makes a stored AnyHttpUrl("https://...") fail membership checks against an incoming AnyUrl("https://..."), even when the URL text is identical.

This normalizes URL subclass instances back through strings at the model boundary, so redirect URI validation compares the declared AnyUrl values rather than the wrapper subclass type.

Validation

uv run pytest tests/shared/test_auth.py -q
uv run ruff check src/mcp/shared/auth.py tests/shared/test_auth.py
uv run ruff format --check src/mcp/shared/auth.py tests/shared/test_auth.py
python -m py_compile src/mcp/shared/auth.py tests/shared/test_auth.py
git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuthClientInformationFull.redirect_uris: pydantic strict-type-equality breaks AnyUrl(x) != AnyHttpUrl(x) round-trip

1 participant