Fixes#2687 by normalizing OAuthClientMetadata.redirect_uris entries at the model boundary. If callers pass a Pydantic URL subtype such as AnyHttpUrl, the value is revalidated through the declared AnyUrl field type instead of being stored as the stricter subtype.
Root cause
Pydantic v2 URL equality is type-strict. A stored AnyHttpUrl("https://example.com/callback") and an incoming AnyUrl("https://example.com/callback") serialize to the same string, but compare non-equal. That makes validate_redirect_uri() reject a registered redirect URI during OAuth flows.
Changes
Added a redirect_uris field validator that stringifies existing AnyUrl instances before Pydantic validates the field.
Added regression coverage for OAuthClientInformationFull(redirect_uris=[AnyHttpUrl(...)]) validating an incoming equivalent AnyUrl(...).
Kept JSON serialization unchanged and still reject unrelated redirect URIs.
Validation
uv run pytest tests/shared/test_auth.py::test_redirect_uri_subtypes_normalized_for_validation -q failed before the fix with InvalidRedirectUriError.
uv run ruff format --check src/mcp/shared/auth.py tests/shared/test_auth.py
uv run ruff check src/mcp/shared/auth.py tests/shared/test_auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2687 by normalizing OAuthClientMetadata.redirect_uris entries at the model boundary. If callers pass a Pydantic URL subtype such as AnyHttpUrl, the value is revalidated through the declared AnyUrl field type instead of being stored as the stricter subtype.
Root cause
Pydantic v2 URL equality is type-strict. A stored AnyHttpUrl("https://example.com/callback") and an incoming AnyUrl("https://example.com/callback") serialize to the same string, but compare non-equal. That makes validate_redirect_uri() reject a registered redirect URI during OAuth flows.
Changes
Validation