feat(core): identify to MCP authorization servers with a client metadata document - #47743
Merged
Conversation
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Client ID Metadata Document (CIMD) support to MCP OAuth. When an MCP server's authorization server advertises support, opencode now presents
https://opencode.ai/oauth/opencode/client.jsonas itsclient_idinstead of dynamically registering a new client on every server. The document itself was published in #47737.Why: Dynamic Client Registration creates a new client record per install per server, lets anything call itself "opencode", and is disabled on many authorization servers (Auth0, Okta, most corporate ones), which made MCP login fail outright. CIMD ties opencode's identity to a domain we control and needs nothing stored server-side. This is the preferred registration method in the MCP 2025-11-25 authorization spec and what Codex, Claude Code, and VS Code ship today.
Behavior
Registration is chosen per login in
McpOAuth.authorize, same rules as Codex:oauth.client_idin config always wins (unchanged).client_id_metadata_document_supported: trueand lists"none"intoken_endpoint_auth_methods_supported(our document declares a public client with no secret), and the user has not set a customoauth.redirect_uri(it would not be in the published document).No new config. Servers that advertise CIMD but exact-match the loopback redirect port (some FastMCP / Auth0 setups) are handled the same way Codex and Claude Code handle them: pin
oauth.callback_portand pre-register that redirect URI withoauth.client_id.The SDK already implemented the CIMD branch; we now set
clientMetadataUrlon the provider when eligible and hand it the discovery we already performed viadiscoveryStateso it does not repeat it. Stored credentials carry{ client_id: <url> }inmetadata.client, so token refresh on reconnect works without changes.No data goes to opencode.ai from the user's machine: the authorization server fetches the public document.
Changes
packages/core/src/mcp/oauth.ts—CLIENT_METADATA_URL, discovery + eligibility check,clientMetadataUrl/discoveryprovider optionspackages/core/test/mcp-oauth.test.ts— CIMD selected (and the stored credential carries the URL asclient_id), DCR fallback whennoneis not accepted, DCR fallback whenredirect_uriis configuredTest plan
bun test test/mcp-oauth.test.tsinpackages/core(9 pass)bun typecheckinpackages/coreopencode mcp authagainst a CIMD-capable server showsclient_id=https://opencode.ai/oauth/opencode/client.jsonin the authorization URL and completes