[PR #9034] feat(mcp): add OAuth redirect URI configuration for MCP servers #12956

Open
opened 2026-02-16 18:17:50 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9034

State: open
Merged: No


Summary

Re-implements the redirectUri option for MCP OAuth configuration, allowing users to specify a custom callback URL for OAuth flows.

  • Adds redirectUri config option to McpOAuth schema
  • Updates McpOAuthProvider to use custom redirect URI when provided
  • Updates McpOAuthCallback.ensureRunning() to support custom port/path
  • Adds parseRedirectUri() utility function

Key difference from original PR #7379: The OAuth callback server is now started lazily in startAuth() only when authentication is actually needed, rather than preemptively in create() for all remote servers. This fixes the regression where non-OAuth MCP servers would fail to connect.

Closes #7377

Test plan

  • Existing MCP tests pass (6 tests)
  • New parseRedirectUri tests pass (3 tests)
  • New ensureRunning with custom redirectUri test passes (1 test)
  • Manual test: Context7 remote MCP server connects without OAuth callback server
  • Manual test: Local filesystem MCP server connects normally

Manual test results

┌  MCP Servers
│
●  ✓ context7 connected
│      https://mcp.context7.com/mcp
│
●  ✓ filesystem connected
│      npx -y @modelcontextprotocol/server-filesystem /tmp
│
└  2 server(s)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9034 **State:** open **Merged:** No --- ## Summary Re-implements the `redirectUri` option for MCP OAuth configuration, allowing users to specify a custom callback URL for OAuth flows. - Adds `redirectUri` config option to `McpOAuth` schema - Updates `McpOAuthProvider` to use custom redirect URI when provided - Updates `McpOAuthCallback.ensureRunning()` to support custom port/path - Adds `parseRedirectUri()` utility function **Key difference from original PR #7379:** The OAuth callback server is now started lazily in `startAuth()` only when authentication is actually needed, rather than preemptively in `create()` for all remote servers. This fixes the regression where non-OAuth MCP servers would fail to connect. Closes #7377 ## Test plan - [x] Existing MCP tests pass (6 tests) - [x] New `parseRedirectUri` tests pass (3 tests) - [x] New `ensureRunning` with custom redirectUri test passes (1 test) - [x] Manual test: Context7 remote MCP server connects without OAuth callback server - [x] Manual test: Local filesystem MCP server connects normally ### Manual test results ``` ┌ MCP Servers │ ● ✓ context7 connected │ https://mcp.context7.com/mcp │ ● ✓ filesystem connected │ npx -y @modelcontextprotocol/server-filesystem /tmp │ └ 2 server(s) ```
yindo added the pull-request label 2026-02-16 18:17:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12956