Repository navigation
Closed
Labels
Description
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 handlingpkg/auth/discovery/discovery.go- Integration with OAuth flow
The current flow:
- When no
client_idis provided, ToolHive attempts DCR - POSTs registration request to
registration_endpointfrom discovery document - Receives
client_idandclient_secretfrom AS - Uses these credentials for OAuth flow
Specification Changes
According to the new spec:
- CIMD is now the default - Every client has its own metadata available at a pre-defined URL
- DCR is now MAY (not SHOULD) - Maintained for backwards compatibility only
- Priority order for client registration:
- Pre-registration (if available)
- CIMD-based approach
- DCR-based approach (fallback)
- 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,
localhostredirect 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
localhostredirect 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.gowith 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.goto support CIMD - Implement priority order for registration methods
- Update
PerformOAuthFlowto 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 implementationpkg/auth/discovery/discovery.go- OAuth flow orchestrationpkg/auth/oauth/oidc.go- OIDC discoverydocs/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
Activity
gastoncan commentedon Apr 9, 2026
Hi team,
This looks like being the next generation of authentication flow.
Is there any intention to schedule this improvement in the roadmap?
Address jhrozek review comments
Support CIMD as preferred OAuth client registration for thv run (#5085)
Add follow-up CIMD E2E and unit tests (#5130)
RFC: Client ID Metadata Document (CIMD) support (stacklok#71)