GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@Tarquinen Tarquinen commented Nov 11, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions
opencodejr[bot]
opencodejr Bot reviewed Nov 11, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@Tarquinen
fix(core): use the localhost redirect when an MCP OAuth server rewrit…
28f241a
…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 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
@Tarquinen
Tarquinen force-pushed the mcp-localhost-redirect branch from c52f7ed to 28f241a Compare November 11, 2026 22:54
opencodejr[bot]
opencodejr Bot reviewed Nov 11, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
@Tarquinen
Tarquinen merged commit 6b8c796 into dev Nov 11, 2026
16 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@Tarquinen
Tarquinen deleted the mcp-localhost-redirect branch November 11, 2026 23:04
@Skeptomenos Skeptomenos mentioned this pull request Nov 17, 2026
fix(mcp): re-register DCR client when loopback callback port changes #62341
Open
3 of 6 tasks
@devin-ai-integration devin-ai-integration Bot mentioned this pull request Nov 25, 2026
upstream: provider/security fixes not yet ported AltimateAI/altimate-code#1478
Open
29 of 90 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

MCP OAuth sign-in fails on Clerk-backed servers: redirect_uri does not match pre-registered redirect urls

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Tarquinen
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.