fix: coerce redirect_uris AnyUrl subtypes to plain AnyUrl for correct equality#2942
Open
kaXianc2-gom wants to merge 1 commit into
Open
Conversation
… equality pydantic v2 strict-type equality means AnyUrl(x) != AnyHttpUrl(x) even when the URLs are identical. This breaks validate_redirect_uri membership checks when callers pass AnyHttpUrl instances in redirect_uris. Add a field_validator to OAuthClientMetadata.redirect_uris that converts each element to AnyUrl(str(...)), stripping the subtype while preserving the URL value. Closes modelcontextprotocol#2687 Co-Authored-By: Claude <noreply@anthropic.com>
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.
AI Assistance Disclosure
This contribution was developed with AI assistance (Claude / Anthropic Claude Code).
Summary
Fix #2687: pydantic v2 strict-type equality means
AnyUrl(x) != AnyHttpUrl(x)even when the URLs are identical. This breaksvalidate_redirect_urimembership checks when callers passAnyHttpUrlinstances inredirect_uris.Changes
Add a
@field_validator(redirect_uris)toOAuthClientMetadatathat converts each element toAnyUrl(str(...)), stripping the subtype while preserving the URL value.****: +13 lines (validator + docstring) in
OAuthClientMetadata****: +62 lines (5 new test cases)
Verification Process
redirect_urisTest Results
Cross-Validation
AnyHttpUrlin redirect_uris, matchingAnyUrllookupAnyHttpUrlin redirect_uris, different URL lookupredirect_uris=NoneAnyUrlsubtype preserved in fieldCloses #2687