Skip to content

Conversation

@pcarleton
Copy link
Member

Summary

Implements support for Client ID Metadata Documents (CIMD) as defined in SEP-991. When a server advertises client_id_metadata_document_supported=true in its OAuth metadata and the client provides a valid client_metadata_url, the URL is used as the client_id instead of performing dynamic client registration (DCR).

This allows clients to use HTTPS URLs as client identifiers where the URL points to a JSON document containing client metadata, enabling servers to implement flexible trust policies for URL-based client registration without requiring pre-coordination.

Changes

  • Add client_metadata_url parameter to OAuthClientProvider
  • Add helper functions in utils.py:
    • is_valid_client_metadata_url() - validates CIMD URLs (must be HTTPS with non-root pathname)
    • should_use_client_metadata_url() - determines if CIMD should be used based on server support
    • create_client_info_from_metadata_url() - creates client info with URL as client_id
  • Update auth flow to use CIMD when server supports it, falling back to DCR otherwise
  • Validate client_metadata_url at initialization time
  • Update simple-auth-client example to demonstrate CIMD usage

Test plan

  • Tested against MCP conformance test suite (auth/basic-cimd scenario)
  • Verified client uses URL-based client_id when server advertises CIMD support
  • Verified client skips DCR registration endpoint when using CIMD
  • Verified auth flow completes successfully with CIMD
  • Unit tests for new helper functions

Closes #1538

Add support for Client ID Metadata Documents (CIMD) as defined in SEP-991.
When a server advertises client_id_metadata_document_supported=true and the
client provides a valid client_metadata_url, the URL is used as the client_id
instead of performing dynamic client registration.

Changes:
- Add client_metadata_url parameter to OAuthClientProvider
- Add helper functions in utils.py: is_valid_client_metadata_url,
  should_use_client_metadata_url, create_client_info_from_metadata_url
- Update auth flow to use CIMD when conditions are met
- Validate client_metadata_url at initialization time (must be HTTPS with
  non-root pathname)

Github-Issue:#1538
Update simple-auth-client to demonstrate using client_metadata_url
parameter for SEP-991 CIMD support.
Add comprehensive unit tests for the Client ID Metadata Document (CIMD)
functionality including:
- URL validation tests for is_valid_client_metadata_url
- Tests for should_use_client_metadata_url logic
- Tests for create_client_info_from_metadata_url
- OAuthClientProvider initialization tests with client_metadata_url
- Auth flow tests verifying CIMD is used when server supports it
- Auth flow tests verifying fallback to DCR when CIMD not supported
@pcarleton pcarleton force-pushed the pcarleton/sep-991-cimd branch from c56ff46 to f32cdad Compare November 23, 2025 18:03
Add tests to cover the fallback path in create_client_registration_request
when auth_server_metadata is None or lacks a registration_endpoint.

Mark the exception handler in is_valid_client_metadata_url as pragma: no cover
since urlparse rarely throws exceptions and this is purely defensive code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
raise OAuthRegistrationError(f"Invalid registration response: {e}")


def is_valid_client_metadata_url(url: str | None) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open to a different break down of helper functions here, this seemed like a reasonably flexible combo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems appropriate to me

Add MCP_CLIENT_METADATA_URL environment variable support to the
simple-auth-client example, allowing users to specify their own
client metadata URL for CIMD (SEP-991) instead of using a hardcoded value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@pcarleton pcarleton marked this pull request as ready for review November 24, 2025 11:27
@pcarleton pcarleton requested a review from maxisbey November 24, 2025 11:27
redirect_handler: Callable[[str], Awaitable[None]] | None
callback_handler: Callable[[], Awaitable[tuple[str, str | None]]] | None
timeout: float = 300.0
client_metadata_url: str | None = None # SEP-991: URL-based client ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: personally think we shouldn't litter comments with references to SEP numbers, hard to keep up-to-date.

raise OAuthRegistrationError(f"Invalid registration response: {e}")


def is_valid_client_metadata_url(url: str | None) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems appropriate to me

Remove temporary SEP number references from code comments since these
are difficult to maintain and can become outdated. The CIMD (Client ID
Metadata Document) terminology is kept as it's a meaningful acronym.
try:
parsed = urlparse(url)
return parsed.scheme == "https" and parsed.path not in ("", "/")
except Exception: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no cover?

@pcarleton pcarleton requested a review from maxisbey November 24, 2025 16:51
Add test case with malformed IPv6 URL to cover the exception branch,
removing the pragma: no cover comment.
@pcarleton pcarleton force-pushed the pcarleton/sep-991-cimd branch from a96218d to efd73df Compare November 24, 2025 17:06
@pcarleton pcarleton merged commit f225013 into main Nov 24, 2025
21 checks passed
@pcarleton pcarleton deleted the pcarleton/sep-991-cimd branch November 24, 2025 17:21
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.

Implement SEP-991: URL-based Client Registration (OAuth Client ID Metadata)

4 participants