GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||
GeezerVison is showing github.com — feat: implement MCP OAuth remote authorization flow by vincenthcui · Pull Request #21704 · anomalyco/opencode Conversation
|
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The OAuth callback is now handled by the main server's /oauth/callback route. No longer need to start a separate callback server on 127.0.0.1:19876.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Looks really nice |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR implements MCP OAuth remote authorization flow by moving the callback handling from a separate local server (127.0.0.1:19876) to the main OpenCode server. This addresses authentication issues in constrained environments like WSL2, devcontainers, and agent sandboxes.
This looks good overall. @egze since you've been actively working on OAuth-related fixes recently, can you take a look? Also @adamdotdevin who is already requested.
Would also appreciate a review from anyone familiar with the MCP auth flow to verify the state management approach.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hey team, this PR moves OAuth auth from server-side to client-side to fix authentication issues in WSL2/devcontainer/sandbox environments.
@egze @adamdotdevin I have seen your work on OAuth-related fixes and would really appreciate your review on this. The main changes are:
This solves real issues for users in constrained environments. Would mean a lot to get your feedback!'
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Great work on this PR! The approach of routing OAuth callbacks through the main server is exactly what's needed for constrained environments. I want to highlight an important use case and a blocker I found that affects both this PR and #21385 (already merged). The architecture: Consider a deployment where a frontend web app runs in one pod (public-facing), and OpenCode runs in another pod (opencode serve) that is only reachable from the The intended OAuth flow:
The endpoints for this flow already exist on dev. The redirectUri config from #21385 tells the OAuth provider where to redirect. The blocker: startAuth unconditionally calls McpOAuthCallback.ensureRunning(oauthConfig?.redirectUri) (index.ts:727), which tries to start a local HTTP server on the port parsed Neither #21385 nor this PR modifies ensureRunning to handle external redirect URIs. The fix is small — skip the local callback server when the redirect host isn't localhost: export async function ensureRunning(redirectUri?: string): Promise<void> { if (redirectUri) { try { const url = new URL(redirectUri) if (url.hostname !== "127.0.0.1" && url.hostname !== "localhost") { log.info("redirect URI is external, skipping local callback server", { redirectUri }) return } } catch {} } const { port, path } = parseRedirectUri(redirectUri) // ... rest unchanged } @lumincui would you be able to include this fix in this PR? It should be a small addition to ensureRunning in oauth-callback.ts. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Handle external redirect URIs in ensureRunning by checking if the hostname is not localhost/127.0.0.1. This fixes EACCES errors when redirectUri points to an external server (e.g., https://frontend.example.com/oauth/callback).
There was an error while loading. Please reload this page.
|
Thanks for the suggestion and feedback! I've updated the ensureRunning function to skip the local callback server when the redirectUri points to an external server. In our architecture, the callback is handled by the frontend server, so no local callback server is needed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hey @rekram1-node, we noticed you have experience with MCP and OAuth flows. This PR implements MCP OAuth remote authorization flow by moving callback handling from a separate local server to the main OpenCode server — this fixes real issues users face in WSL2, devcontainers, and agent sandbox environments where binding to additional ports isn't feasible. This is an important architectural change that would benefit greatly from your expertise. We would really appreciate your review on this. Thank you! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[FEATURE]: Allow custom OAuth redirect URI configuration for MCP servers
There was an error while loading. Please reload this page.