opencode
opencode copied to clipboard
feat(mcp): add OAuth redirect URI configuration for MCP servers
Summary
Re-implements the redirectUri option for MCP OAuth configuration, allowing users to specify a custom callback URL for OAuth flows.
- Adds
redirectUriconfig option toMcpOAuthschema - Updates
McpOAuthProviderto 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
parseRedirectUritests pass (3 tests) - [x] New
ensureRunningwith 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)