fix: normalize OAuth redirect URI URL subtypes#2744
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
062b5b4 to
ffea4ae
Compare
StantonMatt
reviewed
Jun 3, 2026
StantonMatt
left a comment
There was a problem hiding this comment.
I think this still misses one input shape Pydantic accepts for this field. redirect_uris is typed as list[AnyUrl], but Pydantic also accepts tuples/sets and coerces them to a list. Because the before validator only normalizes list, a tuple of URL subtypes still stores the element as AnyHttpUrl, so the existing comparison against an incoming AnyUrl can fail:
info = OAuthClientInformationFull(
client_id="abc123",
redirect_uris=(AnyHttpUrl("https://example.com/callback"),),
)
info.validate_redirect_uri(AnyUrl("https://example.com/callback"))
# InvalidRedirectUriError: Redirect URI 'https://example.com/callback' not registered for clientI verified the list cases are fixed on ffea4ae; raw-string lists, AnyHttpUrl lists, mixed lists, and single-URI default selection all behave as expected. Local checks also pass:
uv run --frozen pytest tests/shared/test_auth.py -quv run --frozen ruff check src/mcp/shared/auth.py tests/shared/test_auth.pyuv run --frozen ruff format --check src/mcp/shared/auth.py tests/shared/test_auth.pyuv run --frozen pyright src/mcp/shared/auth.py tests/shared/test_auth.py
Could the normalizer cover the other collection inputs Pydantic accepts here too?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
redirect_urisvalues at the OAuth client metadata boundaryAnyUrl, and URL subtype inputs serializing the same wayAnyHttpUrlregistration followed byAnyUrlredirect validationTo verify
.\.venv\Scripts\python.exe -m pytest tests\shared\test_auth.py -q.\.venv\Scripts\python.exe -m ruff check src\mcp\shared\auth.py tests\shared\test_auth.py.\.venv\Scripts\python.exe -m ruff format --check src\mcp\shared\auth.py tests\shared\test_auth.pygit diff --checkRefs #2687