Skip to content

fix(auth): accept empty optional OAuth client metadata URLs#2076

Closed
mrutunjay-kinagi wants to merge 3 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-1665-empty-uri-metadata
Closed

fix(auth): accept empty optional OAuth client metadata URLs#2076
mrutunjay-kinagi wants to merge 3 commits intomodelcontextprotocol:mainfrom
mrutunjay-kinagi:fix-1665-empty-uri-metadata

Conversation

@mrutunjay-kinagi
Copy link

@mrutunjay-kinagi mrutunjay-kinagi commented Feb 17, 2026

Summary

  • normalize empty-string optional URL fields in OAuthClientMetadata to None before URL validation
  • keep existing URL validation rules for non-empty values
  • add a regression test for empty client_uri/logo_uri/tos_uri/policy_uri/jwks_uri inputs

Why

Fixes validation failures when auth servers emit empty strings for optional client metadata URL fields.

Closes #1665

Validation

  • pytest -q tests/client/test_auth.py -k "empty_optional_uris"
  • ruff check src/mcp/shared/auth.py tests/client/test_auth.py
  • ruff format --check src/mcp/shared/auth.py tests/client/test_auth.py

@mrutunjay-kinagi
Copy link
Author

Follow-up pushed in e9a78ec to fix the pre-commit failure by validating the empty-URI fixture via (runtime path) instead of passing empty strings directly to typed constructor params.

@mrutunjay-kinagi
Copy link
Author

Follow-up pushed in e9a78ec to fix the pre-commit pyright failure.

Change made:

  • Updated the empty-URI regression test to use OAuthClientMetadata.model_validate({...}) so empty strings are exercised through runtime validation without violating static constructor type checks.

@mrutunjay-kinagi
Copy link
Author

All checks are now passing on the latest commit (e9a78ec).

Ready for maintainer review when you have bandwidth. Thanks!

@Kludex
Copy link
Member

Kludex commented Feb 18, 2026

Where in the RFC it says that empty is not valid?

@mrutunjay-kinagi
Copy link
Author

Good question.

The RFC language we based this on is RFC 7591 §2 for these fields (client_uri, logo_uri, tos_uri, policy_uri, jwks_uri):

  • they are optional metadata fields,
  • but if present they are "URL string" fields and "MUST point to a valid ..." target.

Examples from §2:

  • client_uri: "MUST point to a valid web page"
  • logo_uri: "MUST point to a valid image file"
  • tos_uri/policy_uri: "MUST point to a valid web page"
  • jwks_uri: "MUST point to a valid JWK Set document"

So this change is not treating "" as a valid URL. It normalizes empty-string placeholders to None (effectively omitted) before URL validation, which keeps the RFC "if present, must be valid" rule while improving interop with providers that emit empty strings for optional fields.

@Kludex
Copy link
Member

Kludex commented Feb 18, 2026

Link please.

@mrutunjay-kinagi
Copy link
Author

Absolutely — here are the direct references:

In that section, for these optional fields (client_uri, logo_uri, tos_uri, policy_uri, jwks_uri), the text says that if present they are URL strings and must point to valid targets (web page/image/JWK set).

@Kludex
Copy link
Member

Kludex commented Feb 18, 2026

I don't think this needs any fixing. The client side sending empty string in a field is the wrong behavior.

@Kludex Kludex closed this Feb 18, 2026
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.

URL Validation on Client Metadata is too strict

2 participants

Comments