feat(mcp): add OAuth redirect URI configuration for MCP servers #7379
+154
−18
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
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
redirectUriconfig parameter to MCP OAuth settingsparseRedirectUri()helper function to extract port and pathhttp://127.0.0.1:19876/mcp/oauth/callbackwhen not specifiedUser 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- AddedredirectUrito OAuth config schemapackages/opencode/src/mcp/oauth-provider.ts- ImplementparseRedirectUri()and use configured URIpackages/opencode/src/mcp/oauth-callback.ts- Dynamic server configuration with port/path parsingpackages/opencode/src/mcp/index.ts- PassredirectUrithrough OAuth flowpackages/opencode/src/cli/cmd/mcp.ts- PassredirectUrito OAuth provider in debug commandpackages/opencode/test/mcp/oauth-callback.test.ts- Comprehensive test suiteTesting
Related
Closes #7377 - [FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers
Design Rationale
OpenCode already supports overriding
clientIdfor flexible OAuth client configuration. Since OAuth servers validate both client ID and redirect URI, supporting customredirectUriis 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:

Keycloak:
