GeezerVison is showing github.com — fix(core): use the localhost redirect when an MCP OAuth server rewrites 127.0.0.1 by Tarquinen · Pull Request #63403 · anomalyco/opencode
Conversation
Tarquinen
commented
Nov 11, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #63408
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
McpOAuth.authorize registers one redirect, http://127.0.0.1:PORT/callback, through DCR. Clerk-backed servers such as Octolens accept it at /oauth/authorize. Their consent page then rewrites it to http://localhost:PORT/callback, so Allow fails with redirect_uri ... does not match any of the OAuth 2.0 Client's pre-registered redirect urls. Clerk also binds the code to the localhost URI: redeeming it with 127.0.0.1 returns invalid_grant.
Now DCR registers both the 127.0.0.1 and localhost callbacks. When the browser comes back with Host: localhost:PORT, the token exchange sends the localhost redirect.
- The authorize request still sends
127.0.0.1, so servers that don't rewrite see the same requests as before.
- The listener still binds only
127.0.0.1, which localhost reaches.
- A configured
oauth.redirect_uri is unchanged. The CIMD document already lists both hosts.
- The pasted-URL fallback still redeems with
127.0.0.1, so a pasted localhost URL from a rewriting server isn't handled yet.
How did you verify your code works?
- Before: reproduced against Octolens's Clerk server by registering a client with only
127.0.0.1. The consent page carried redirect_uri=http://localhost:PORT/callback, and with both hosts registered, a token exchange using 127.0.0.1 returned invalid_grant.
- After: ran
authorize against the real Octolens server with no oauth config. The callback arrived on localhost, and the token exchange returned access and refresh tokens.
- Added a test to
packages/core/test/mcp-oauth.test.ts that sends the callback with a localhost Host header. It checks that DCR registers both URIs and that the token request uses the localhost one. It fails when the fix is reverted.
bun test test/mcp-oauth.test.ts test/oauth and bun typecheck in packages/core; bun run check from the root.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #62331, #62742
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I reproduced the failure with the new test on the base (the code is redeemed with the 127.0.0.1 redirect after the browser came back on localhost), and it passes with this change. The MCP OAuth and test/oauth tests pass (41/41). The MCP SDK reads redirectUrl again for the token request, so the getter does reach the code exchange. A configured redirect_uri, CIMD, and servers that don't rewrite the host all keep their current behaviour.
Public API: unchanged. The new url argument to OauthRedirect.submit's received callback is internal to packages/core.
No blocking concerns.
Related: #62331, #62742
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…es 127.0.0.1
Clerk-backed servers rewrite a 127.0.0.1 redirect to localhost on their consent page and issue the code for it. Register both loopback callbacks with DCR and redeem the code with the host the browser came back on.
Tarquinen
changed the title
fix(core): accept MCP OAuth redirects rewritten to localhost
fix(core): use the localhost redirect when an MCP OAuth server rewrites 127.0.0.1
Nov 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commits drop the pasted-URL host handling, which the PR description now notes. The callback-server fix is unchanged. The MCP OAuth and test/oauth tests still pass (41/41), and type-checking the package with tsc -b shows no errors in the changed files.
Public API: unchanged. OauthRedirect.submit's signature is back to what it is on dev.
No blocking concerns.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|