fix(mcp): support OAuth for servers without RFC 8414 discovery#27068
Open
yanniznik wants to merge 1 commit into
Open
fix(mcp): support OAuth for servers without RFC 8414 discovery#27068yanniznik wants to merge 1 commit into
yanniznik wants to merge 1 commit into
Conversation
Add authorizationEndpoint and tokenEndpoint fields to MCP OAuth config to support servers that don't implement RFC 8414 metadata discovery (e.g. Google Workspace MCP servers). Implements discoveryState()/saveDiscoveryState() on McpOAuthProvider to provide pre-cached OAuth metadata when explicit endpoints are configured. Adds auth() fallback in startAuth() for servers that accept unauthenticated connections but have explicit OAuth endpoints configured. Fixes anomalyco#26195
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR FoundPR #26236: fix: force OAuth flow when server accepts unauthenticated connections Why it's related: This PR appears to address a closely related concern mentioned in the current PR's description. PR #27068 includes a fallback mechanism in These two PRs likely overlap in scope and should be reviewed together to ensure they're compatible and not duplicating effort. |
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.
Issue for this PR
Closes #26195
Type of change
What does this PR do?
MCP servers like Google's Workspace endpoints don't implement RFC 8414 (
.well-known/oauth-authorization-server) discovery. The MCP SDK already supports adiscoveryState()hook onOAuthClientProviderto supply pre-cached authorization metadata, but OpenCode never implemented it.This adds
authorizationEndpointandtokenEndpointfields to the OAuth config schema. When set,McpOAuthProvider.discoveryState()returns a synthetic discovery state so the SDK skips its failing RFC 8414 fetch and uses the configured endpoints directly.There's also a fallback in
startAuth(): if a server accepts unauthenticated connections (noUnauthorizedError) but has explicit OAuth endpoints configured and no stored tokens, we proactively trigger the OAuth flow via the SDK'sauth()function. Without this,opencode mcp auth <name>would report success without ever opening the browser.Example config:
{ "mcp": { "google-calendar": { "type": "remote", "url": "https://calendar.googleapis.com/mcp", "oauth": { "clientId": "...", "clientSecret": "...", "authorizationEndpoint": "https://accounts.google.com/o/oauth2/v2/auth", "tokenEndpoint": "https://oauth2.googleapis.com/token" } } } }How did you verify your code works?
discoveryState()inoauth-auto-connect.test.ts(returns metadata when endpoints configured, returns undefined when not)npx tsc --noEmit)Screenshots / recordings
N/A — no UI changes.
Checklist