Skip to content

Implement Client ID Metadata Documents (CIMD) for OAuth Client Registration #2728

Closed

Description

@amirejaz

Background

The MCP Authorization Specification (2025-11-25) introduces Client ID Metadata Documents (CIMD) as the default method for OAuth client registration, replacing Dynamic Client Registration (DCR) as the primary approach. This change addresses several security and operational concerns with DCR:

  • Security: DCR can be vulnerable to Denial of Service (DoS) attacks and requires complex security logic
  • Operational: Most Authorization Servers (AS) don't support DCR, forcing developers to implement workarounds
  • Policy: CIMD enables AS to make policy decisions based on client metadata URLs (e.g., domain-based allow/deny lists)

Reference: What's New In The 2025-11-25 MCP Authorization Spec

Current State

ToolHive currently uses Dynamic Client Registration (RFC 7591) as implemented in:

  • pkg/auth/oauth/dynamic_registration.go - DCR request/response handling
  • pkg/auth/discovery/discovery.go - Integration with OAuth flow

The current flow:

  1. When no client_id is provided, ToolHive attempts DCR
  2. POSTs registration request to registration_endpoint from discovery document
  3. Receives client_id and client_secret from AS
  4. Uses these credentials for OAuth flow

Specification Changes

According to the new spec:

  1. CIMD is now the default - Every client has its own metadata available at a pre-defined URL
  2. DCR is now MAY (not SHOULD) - Maintained for backwards compatibility only
  3. Priority order for client registration:
    1. Pre-registration (if available)
    2. CIMD-based approach
    3. DCR-based approach (fallback)
    4. User-provided client details (manual entry)

Implementation Requirements

1. CIMD Support

Implement Client ID Metadata Document support:

  • CIMD Document Structure: Each client must host a metadata document at a well-known URL
  • Document Fetching: Fetch and parse CIMD from client's metadata URL
  • Validation: Validate CIMD document structure and required fields
  • Security: Implement security checks for SSRF risks, localhost redirect URI risks, and trust policies

Key Components:

  • CIMD document parser/validator
  • HTTP client for fetching CIMD documents
  • Security validation (SSRF protection, domain-based policies)
  • Integration with existing OAuth flow

2. Update Registration Priority

Modify pkg/auth/discovery/discovery.go to implement the priority order:

// Priority order:
// 1. Pre-registration (if client_id/client_secret provided)
// 2. CIMD-based registration
// 3. DCR-based registration (fallback)
// 4. User-provided client details (manual entry)

3. Maintain Backwards Compatibility

  • Keep DCR implementation as fallback option
  • Support both CIMD and DCR during transition period
  • Ensure existing flows continue to work

4. Security Considerations

As per spec, implement security measures for CIMD:

  • SSRF Protection: Validate and sanitize metadata URLs
  • Localhost Redirect URI Risks: Handle localhost redirect URIs securely
  • Trust Policies: Support domain-based allow/deny policies
  • URL Validation: Ensure metadata URLs are valid and secure

Implementation Plan

Phase 1: CIMD Core Implementation

  • Create pkg/auth/oauth/cimd.go with CIMD document structures
  • Implement CIMD document fetching and parsing
  • Add CIMD document validation
  • Write unit tests for CIMD parsing and validation

Phase 2: Security Implementation

  • Implement SSRF protection for metadata URL fetching
  • Add localhost redirect URI validation
  • Implement trust policy support (domain-based allow/deny)
  • Add security tests

Phase 3: Integration

  • Update pkg/auth/discovery/discovery.go to support CIMD
  • Implement priority order for registration methods
  • Update PerformOAuthFlow to try CIMD before DCR
  • Maintain DCR as fallback

Phase 4: Documentation & Testing

  • Update documentation (docs/remote-mcp-authentication.md)
  • Add integration tests for CIMD flow
  • Update CLI help text and examples
  • Add E2E tests

Acceptance Criteria

  • ToolHive can register OAuth clients using CIMD as the primary method
  • CIMD registration works with standard MCP authorization servers
  • DCR remains available as a fallback option
  • Security measures (SSRF protection, trust policies) are implemented
  • Priority order is correctly implemented (pre-registration → CIMD → DCR → manual)
  • All existing tests pass
  • New tests cover CIMD scenarios
  • Documentation is updated

Related Files

  • pkg/auth/oauth/dynamic_registration.go - Current DCR implementation
  • pkg/auth/discovery/discovery.go - OAuth flow orchestration
  • pkg/auth/oauth/oidc.go - OIDC discovery
  • docs/remote-mcp-authentication.md - Authentication documentation

Additional Notes

  • The spec change makes CIMD the default, but DCR should remain supported for backwards compatibility
  • Consider adding configuration options to allow users to prefer DCR if needed
  • The CIMD approach is similar to how Visual Studio Code handles client registration
  • This change aligns ToolHive with the latest MCP authorization specification

References

Activity

  1. added
    enhancement
    go
    on Nov 25, 2025
  2. gastoncan commented on Apr 9, 2026

    @gastoncan

    Hi team,
    This looks like being the next generation of authentication flow.
    Is there any intention to schedule this improvement in the roadmap?

  3. self-assigned this
    on Apr 22, 2026
  4. added a commit that references this issue on Jun 16, 2026
    2a1664a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

authenticationenhancementgo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions