Skip to content

Conversation

@christso
Copy link
Contributor

@christso christso commented Jan 8, 2026

Summary

This PR implements custom OAuth redirect URI configuration for MCP servers, allowing users to override the default callback URL to match their OAuth server's requirements.

Changes

  • ✅ Added optional redirectUri config parameter to MCP OAuth settings
  • ✅ Implemented parseRedirectUri() helper function to extract port and path
  • ✅ Dynamic callback server configuration based on custom redirect URI
  • ✅ Full test coverage for custom URI parsing and edge cases
  • ✅ Backward compatible - defaults to http://127.0.0.1:19876/mcp/oauth/callback when not specified

User Configuration

{
  "mcp": {
    "my-server": {
      "type": "remote",
      "url": "https://api.example.com",
      "oauth": {
        "clientId": "my-client-id",
        "redirectUri": "https://custom.example.com/callback"  // NEW
      }
    }
  }
}

Files Changed

  • packages/opencode/src/config/config.ts - Added redirectUri to OAuth config schema
  • packages/opencode/src/mcp/oauth-provider.ts - Implement parseRedirectUri() and use configured URI
  • packages/opencode/src/mcp/oauth-callback.ts - Dynamic server configuration with port/path parsing
  • packages/opencode/src/mcp/index.ts - Pass redirectUri through OAuth flow
  • packages/opencode/src/cli/cmd/mcp.ts - Pass redirectUri to OAuth provider in debug command
  • packages/opencode/test/mcp/oauth-callback.test.ts - Comprehensive test suite

Testing

  • Tests cover default behavior (no redirectUri specified)
  • Tests cover custom redirectUri with different ports/paths
  • Tests cover server reconfiguration when redirectUri changes
  • Tests cover invalid URI handling with fallback to defaults
  • All tests passing

Related

Closes #7377 - [FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers

Design Rationale

OpenCode already supports overriding clientId for flexible OAuth client configuration. Since OAuth servers validate both client ID and redirect URI, supporting custom redirectUri is essential for feature completeness. This removes the asymmetry where users could point to any OAuth server/client but were constrained to a hardcoded callback URL.

GitHub OAuth:
image

Keycloak:
Image

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

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

No duplicate PRs found

@christso christso changed the title feat: add OAuth redirect URI configuration for MCP servers feat(mcp): add OAuth redirect URI configuration for MCP servers Jan 8, 2026
@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

lgtm

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.

[FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers

2 participants