Skip to content

fix(mcp): support OAuth for servers without RFC 8414 discovery#26912

Closed
yanniznik wants to merge 1 commit into
anomalyco:devfrom
yanniznik:fix/oauth-no-discovery
Closed

fix(mcp): support OAuth for servers without RFC 8414 discovery#26912
yanniznik wants to merge 1 commit into
anomalyco:devfrom
yanniznik:fix/oauth-no-discovery

Conversation

@yanniznik
Copy link
Copy Markdown

Summary

Fixes #26195

MCP servers like Google's endpoints don't implement RFC 8414 (.well-known/oauth-authorization-server) discovery. The MCP SDK already supports a discoveryState() hook on OAuthClientProvider to supply pre-cached authorization metadata, but OpenCode never implemented it.

This PR:

  • Adds authorizationEndpoint and tokenEndpoint fields to MCP server config
  • Implements discoveryState() / saveDiscoveryState() on McpOAuthProvider to provide pre-cached OAuth metadata when configured
  • Adds an auth() fallback in startAuth() for servers that have explicit OAuth endpoints but no existing tokens (so the OAuth flow triggers correctly)

Example config

{
  "mcp": {
    "google-calendar": {
      "type": "remote",
      "url": "https://calendar.googleapis.com/mcp",
      "authorizationEndpoint": "https://accounts.google.com/o/oauth2/v2/auth",
      "tokenEndpoint": "https://oauth2.googleapis.com/token"
    }
  }
}

Then opencode mcp auth google-calendar triggers the standard OAuth browser flow.

Testing

  • Added tests for discoveryState() in oauth-auto-connect.test.ts (6 tests, all passing)
  • TypeScript build passes (npx tsc --noEmit)
  • Manually verified end-to-end with Google People, Gmail, Calendar, and Drive MCP servers

Servers like Google's MCP endpoints don't implement RFC 8414
(.well-known/oauth-authorization-server) discovery. The MCP SDK's
auth() function supports a discoveryState() hook on OAuthClientProvider
that lets providers supply pre-cached authorization metadata, bypassing
the discovery fetch entirely.

This change:
- Adds authorizationEndpoint and tokenEndpoint to MCP server config
- Implements discoveryState()/saveDiscoveryState() on McpOAuthProvider
- Adds auth() fallback in startAuth() for servers with explicit OAuth
  endpoints but no existing tokens

Closes anomalyco#26195
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my comprehensive search, I found one potentially related PR:

Related PR:

However, #26236 seems to be a separate fix and is not a true duplicate of the current PR (#26912), which specifically adds support for servers without RFC 8414 discovery through authorizationEndpoint and tokenEndpoint configuration fields.

No other duplicate or directly related open PRs addressing the same OAuth discovery issue were found.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 11, 2026
@github-actions github-actions Bot closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode mcp auth fails to open browser for OAuth flow (Google Drive MCP)

1 participant