[BUG] MCP OAuth redirect_uri hardcodes the `localhost` hostname — breaks IdPs that allowlist only `127.0.0.1`
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The redirect_uri Claude Code sends for MCP server OAuth is hardcoded to the localhost hostname. Only the port is configurable (MCP_OAUTH_CALLBACK_PORT) — there is no way to make it use 127.0.0.1.
This makes remote MCP servers unusable behind an IdP that allowlists loopback by IP. In my case the Atlassian MCP server (https://mcp.atlassian.com/v1/mcp/authv2): my org's Atlassian admin has domain restrictions enabled, localhost is not on the allowlist, and the browser is stopped with "Access to this domain is restricted — Your admin has blocked this domain http://localhost:3118/callback in your organization's settings" before the authorization code is ever handed back. The exact same Atlassian MCP server authenticates fine from GitHub Copilot, which uses http://127.0.0.1:<port>/callback.
Digging into the shipped bundle (v2.1.220), the MCP callback URL builder is:
function sBe(e = oTs) { return `http://localhost:${e}/callback` } // oTs = 3118 (default port)
function ES_() { let e = Bd(process.env.MCP_OAUTH_CALLBACK_PORT); return e > 0 && e <= 65535 ? e : void 0 }
Notably the local callback listener already binds to the IP, not to the hostname:
n.listen(e, "127.0.0.1", () => { ... })
So only the string advertised as redirect_uri says localhost; the receiving socket is already 127.0.0.1. Switching the emitted URL to 127.0.0.1 should be a one-token change with no behavioral impact on the listener.
This is also what RFC 8252 §8.3 recommends — it explicitly says native apps should use the loopback IP literal rather than localhost, since localhost may resolve to a non-loopback interface and requires the host to be configured correctly.
Related prior reports, both auto-closed by the stale bot with "please open a new issue if this is still relevant": #56557 (same request, for the CIMD redirect_uris) and #63030 (same class of failure against Entra/Azure, where the app registration only has http://127.0.0.1/callback).
What Should Happen?
Claude Code should emit http://127.0.0.1:<port>/callback as the MCP OAuth redirect_uri — or, at minimum, expose an override (e.g. MCP_OAUTH_CALLBACK_HOST, mirroring the existing MCP_OAUTH_CALLBACK_PORT) so users behind an IdP that only allows the IP literal can authenticate.
Error Messages/Logs
# Shown by Atlassian in the browser, instead of redirecting back to Claude Code:
Access to this domain is restricted
Your admin has blocked this domain "http://localhost:3118/callback" in your organization's settings.
To request access, contact your organization admin or find out about domain restrictions.
Steps to Reproduce
- Have an Atlassian (or Entra/Okta) org where the admin's domain allowlist does not include
localhostbut does include127.0.0.1. - Add the remote MCP server:
````
claude mcp add --transport http atlassian-mcp https://mcp.atlassian.com/v1/mcp/authv2
- Run
/mcpand start authentication foratlassian-mcp. - Complete the Atlassian login in the browser.
- Instead of redirecting back to the local callback listener, the browser lands on the "Access to this domain is restricted" page naming
http://localhost:3118/callback, and the OAuth flow never completes.
Confirmation that the hostname is the only difference: the identical MCP server authenticates successfully from GitHub Copilot in the same browser/org, and its redirect_uri uses 127.0.0.1.
Workaround I'm currently using: byte-patching http://localhost:${e}/callback → http://127.0.0.1:${e}/callback in the installed binary (same byte length, single occurrence, does not touch the Anthropic account login flow which uses separate literals) and re-signing it ad-hoc. That obviously does not survive an auto-update.
Claude Model
Opus
Is this a regression?
No, this never worked
Claude Code Version
2.1.220 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
macOS 15 (Darwin 24.6.0), arm64, installed via npm (@anthropic-ai/claude-code).
The suggested fix touches one string literal. The MCP account-login flow for the Anthropic account itself (MANUAL_REDIRECT_URL / the console flow) uses different literals and would be unaffected.
Showing cached comments. Read the full discussion on GitHub ↗
3 Comments
Attaching the screenshot of what the browser shows instead of redirecting back to the
local callback listener. This is Atlassian's domain-restriction interstitial, and it
names the exact URL that got blocked:
Worth stressing that the flow dies here — the browser never reaches the loopback
listener, so there is no authorization code to recover and no manual-paste fallback
that could rescue it. The allowlist check happens on the IdP side, before the redirect.
The only difference between this failing and working is the hostname: the same MCP
server, same browser, same org policy authenticates fine from GitHub Copilot, which
advertises
http://127.0.0.1:<port>/callback.<img width="1272" height="658" alt="Image" src="https://github.com/user-attachments/assets/b0f39d6f-feee-4308-8f40-6f9b6524953a" />
I've been running a locally patched bundle with this change
(
redirect_uri→http://127.0.0.1:<port>/callback) since filing this.The OAuth flow completes normally against the Atlassian MCP server, and I
haven't seen any regression in callback handling — the listener already
binds to
127.0.0.1, so nothing else needed to change.Two things worth adding:
Claude Code auto-update, so it isn't something affected users can rely on
in the meantime.
IP literal, which I imagine is awkward to stand up internally. I have that
environment and I'm happy to test a pre-release or canary build against it
and report back — just point me at a build.
Could this get triaged or labelled? #56557 and #63030 describe the same
failure and were both auto-closed without a response.
This also breaks authentication for remote or containerized claude code sessions. The workaround "If the redirect page shows a connection error, paste the URL from your browser's address bar:" doesn't actually work; the atlassian page just spins forever.