Unable to authenticate with MCP server when running in remote environment
What version of Codex is running?
0.79.0
What subscription do you have?
Own API key
Which model were you using?
gpt-5.1
What platform is your computer?
Linux 5.15.0-305.176.4.el8uek.x86_64 x86_64 x86_64
What issue are you seeing?
We are running the codex CLI tool in a remote codeserver/WebIDE environment. It is impossible to access OAuth protected MCP servers in this environment due to Codex using localhost as callback URI: the localhost will point to the machine that the user is on, not the machine that codex is running on.
What steps can reproduce the bug?
- Setup a codeserver/WebIDE environment.
- Define config for an OAuth protected MCP server in
config.toml - try to authenticate with codex mcp login [NAME]
- new tab opens in browser window
- but OH NO: "This site can’t be reached"
What is the expected behavior?
New tab in browser should indicate successful authentication and when going back to codeserver tab, the MCP server authentication process in the terminal should be completed.
Additional information
No response
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
- #8827
- #8576
- #6766
Powered by Codex Action
I guess a similar solution as what was used to support https://github.com/openai/codex/issues/2798 could be applied here. This would also be very useful for running in other headless environments, such as containers.
@janEbert @eric-oai What exactly is the solution? Actually, the current functionality almost supports authenticating with oauth protected mcp servers in a webide. There is just one technicality which needs to be handled. I explain it here: https://github.com/openai/codex/issues/24058
Hey, quoting from the linked issue, because it summarizes the solution well:
Add “Hosted Redirect + Copy-Paste Code” Flow (PKCE)
- CLI launches OAuth with PKCE and
redirect_uripointing to an OpenAI-hosted page (e.g.,https://console.openai.com/cli/callback).- After the user signs in (in any browser), the hosted page displays a short one-time code (e.g.,
ABCD-EFGH-IJKL) tied to the CLI session viastate.- The CLI prompts:
Paste the authentication code:and exchanges it (withcode_verifier) for tokens.- The CLI never depends on a local HTTP server.
As another option, Claude Code, for example, also redirects to a local server, but you can just paste the redirect URL into Claude Code to finish authentication. So even if you can't reach the local exchange server the URL points to, as long as you got correctly redirected to the URL (again, from an external auth provider), you can still authenticate.
Confirmed this still occurs with Codex CLI 0.153.4 using Linear's remote MCP server over SSH.
Reproduction:
- SSH into a Linux VM.
- Run
codex mcp add linear --url https://mcp.linear.app/mcp(orcodex mcp login linear). - Open the authorization URL in a browser on the local machine and approve access.
- Linear redirects the browser to a loopback URL such as
http://127.0.0.1:<port>/callback/<path>?code=...&state=.... - The browser cannot reach that address because
127.0.0.1is the local machine while the callback listener belongs to Codex on the VM. The CLI offers no prompt or option to paste the resulting callback URL, so it waits indefinitely.
As a workaround, sending that complete callback URL to the listener from inside the VM with curl immediately returns Authentication complete and codex mcp list then reports Linear as enabled with OAuth authentication. This confirms the authorization flow and callback handler work; the missing piece for SSH/headless use is a CLI fallback that accepts the callback URL (or authorization code) directly.
A Paste the callback URL: fallback after printing the browser URL would solve this without requiring users to configure SSH port forwarding.
this is also happening with the 0.154.0, why is this so hard to fix? add a backup option to just paste the callback url like claude code does