feat: relax StrictOidcDiscoveryMetadataPolicy and add Dynamic Client Registration middleware (RFC 7591)#269
feat: relax StrictOidcDiscoveryMetadataPolicy and add Dynamic Client Registration middleware (RFC 7591)#269simonchrz wants to merge 4 commits intomodelcontextprotocol:mainfrom
Conversation
…allenge_methods_supported Some identity providers (e.g. FusionAuth, Microsoft Entra ID) omit code_challenge_methods_supported from their OIDC discovery response despite supporting PKCE with S256. This policy relaxes the validation to only require authorization_endpoint, token_endpoint, and jwks_uri.
PSR-15 middleware that handles POST /register by delegating to a ClientRegistrarInterface and enriches /.well-known/oauth-authorization-server responses with the registration_endpoint.
|
There is an examples for microsoft connection. There is a trouble not only with OIDC discovery. https://github.com/modelcontextprotocol/php-sdk/blob/main/examples/server/oauth-microsoft/MicrosoftOidcMetadataPolicy.php Examples should be also updated if alternative OIDC discovery is accepted. There is also alternative way - in case when code_challenge_methods_supported is missed we can set it's value to default S256 |
src/Server/Transport/Http/Middleware/ClientRegistrationMiddleware.php
Outdated
Show resolved
Hide resolved
- Use Mcp\Exception\InvalidArgumentException instead of global \InvalidArgumentException - Add interface documentation for ClientRegistrarInterface with RFC 7591 references
…tead - StrictOidcDiscoveryMetadataPolicy now accepts missing code_challenge_methods_supported (defaults to S256 downstream) - If the field is present, it is still validated strictly - Remove LenientOidcDiscoveryMetadataPolicy (no longer needed) - Update tests and CHANGELOG accordingly
Good point — I've removed LenientOidcDiscoveryMetadataPolicy and relaxed StrictOidcDiscoveryMetadataPolicy to accept missing code_challenge_methods_supported. If the field is present it's still validated strictly; if absent, the downstream OAuthProxyMiddleware already defaults to ['S256']. The interface stays for custom policies (like the Microsoft example). |
Add two features to the HTTP transport layer:
code_challenge_methods_supported
Motivation and Context
LenientOidcDiscoveryMetadataPolicy: Several identity providers (FusionAuth, Microsoft Entra ID) omit code_challenge_methods_supported from
their OIDC discovery response despite fully supporting PKCE with S256. The existing OidcDiscoveryMetadataPolicy rejects these responses,
making it impossible to use the SDK's OAuth transport with those providers without a custom policy. This provides a ready-made workaround.
ClientRegistrationMiddleware: The MCP specification requires servers to support OAuth 2.0 Dynamic Client Registration (RFC 7591) so that MCP
clients can register themselves automatically. This middleware handles POST /register by delegating to a ClientRegistrarInterface
implementation and enriches /.well-known/oauth-authorization-server responses with the registration_endpoint. The ClientRegistrarInterface
keeps the actual registration logic (e.g. calling FusionAuth, storing in a database) pluggable.
How Has This Been Tested?
required fields, empty strings, non-array input
enrichment with registration_endpoint, Cache-Control preservation, non-200 passthrough, non-matching route passthrough, empty localBaseUrl
rejection, trailing slash normalization
Breaking Changes
None. Both features are purely additive — new classes and interfaces only.
Types of changes
Checklist
Additional context
handler classes in tests)
advanced