| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
The one red check is an unrelated, pre-existing stdio flake (test_tool_call_and_notification_round_trip_over_a_stdio_subprocess) that this PR does not touch; it should be fixed by #2773. |
Sorry, something went wrong.
SEP-837 requires an MCP client to specify an application_type during OIDC Dynamic Client Registration [1]. When it is omitted, OIDC servers default the client to "web", which conflicts with the loopback redirect URIs that CLI and desktop clients use, so the registration can be rejected. OAuthClientMetadata had no such field and the registration request never sent one, so the SDK hit exactly that default. I add an optional application_type to OAuthClientMetadata and infer it from the redirect URIs when the caller does not set one: loopback and private-use scheme URIs register as "native", a remote https host as "web", and a mix is left unset for the server to decide. An explicit value is always sent as-is. Non-OIDC servers ignore the parameter. Implements [2]. [1]: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/7df71535a0c9b2057d73966bb6b123e684a940cd/docs/specification/draft/basic/authorization/client-registration.mdx#L152-L179 [2]: modelcontextprotocol#2783 Signed-off-by: Stefano Amorelli <stefano@amorelli.tech>
| Back | FazBrowse Home | New Git URL |
Adds an application_type field to OAuthClientMetadata and sends it during OAuth Dynamic Client Registration, inferring the value from the client's redirect URIs when the caller does not set one.
Closes #2783.
Motivation and Context
SEP-837 requires MCP clients to send an application_type during OIDC Dynamic Client Registration. Omitting it defaults the client to "web", which conflicts with the loopback redirect URIs (localhost, 127.0.0.1, ::1) that native clients (CLI and desktop apps) use, so the server can reject the registration.
Currently OAuthClientMetadata has no such field and create_client_registration_request never sends one, so the client hits that default. This PR adds the field and infers a value from the redirect URIs at registration time: loopback and private-use schemes register as "native", a remote https host as "web", and a mix is left unset for the authorization server to decide. An explicit value is always sent as-is, and non-OIDC servers ignore the parameter. This follows the spec's guidance 1 and mirrors the approach already merged in the Go SDK (modelcontextprotocol/go-sdk#904) and Rust SDK (modelcontextprotocol/rust-sdk#883).
How Has This Been Tested?
The full suite passes locally with 100% coverage (./scripts/test); ruff, ruff format, and pyright are clean.
New unit tests cover the application_type model field, the redirect-URI inference (loopback, IPv4/IPv6 loopback, private-use scheme, remote host, and ambiguous mixes), and that create_client_registration_request sends the inferred type, preserves an explicit one, and omits an ambiguous one. The auth interaction suite's registration snapshot was updated to include application_type: "native" for its loopback redirect. The conformance suite already covers SEP-837 (src/seps/sep-837.yaml), so conformance.yml exercises this against the SDK.
Breaking Changes
None. application_type is optional and defaults to None; existing callers are unaffected, and registration requests only gain a parameter that OIDC servers expect and non-OIDC servers ignore.
Types of changes
Checklist
Additional context
The registration failure SEP-837 describes is already surfaced by handle_registration_response as an OAuthRegistrationError, so no new error handling was needed; this PR only ensures the client declares the correct type up front.