opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(mcp): add OAuth redirect URI configuration for MCP servers

Open christso opened this issue 18 hours ago • 2 comments

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)

christso avatar Jan 17 '26 06:01 christso