Skip to content

MCP OAuth callback URL override is not used as an exact redirect URI #30460

Open

Description

@sshishigin

What issue are you seeing?

mcp_oauth_callback_url is documented and configurable as an optional redirect URI override for MCP OAuth login, but Codex still appends a server-derived callback id to the configured URL before sending it as redirect_uri.

For example, with config overrides equivalent to:

mcp_oauth_callback_port = 10230
mcp_oauth_callback_url = "http://localhost:10230/callback"

Codex builds an authorization URL whose redirect_uri is effectively:

http://localhost:10230/callback/<callback_id>

This breaks OAuth providers that require exact redirect URI matching, such as enterprise OIDC/Keycloak clients registered with a fixed localhost callback URL. The provider rejects the request before the authorization-code exchange with an error like:

invalid_request: The requested redirect_uri is missing in the client configuration.

The configured callback URL is valid for the provider, but the mutated URL with the extra path segment is not.

What steps can reproduce the bug?

  1. Configure a streamable HTTP MCP server that uses OAuth with an OIDC provider whose client has only this redirect URI registered:
http://localhost:10230/callback
  1. Run MCP login with explicit callback settings:
codex mcp login <server> \
  -c mcp_oauth_callback_port=10230 \
  -c 'mcp_oauth_callback_url="http://localhost:10230/callback"'
  1. Inspect or open the authorization URL emitted by Codex.

Actual result: the redirect_uri includes an additional server-derived path segment after /callback, so strict OIDC clients reject it.

A small branch that demonstrates the proposed behavior is available here:

https://github.com/sshishigin/codex/tree/codex-respect-mcp-oauth-callback-url

Commit:

3560426d05 Respect configured MCP OAuth callback URL

What is the expected behavior?

When mcp_oauth_callback_url is explicitly configured, Codex should use it exactly as the OAuth redirect_uri.

The existing callback-id behavior can remain for generated local redirect URIs, where Codex chooses the listener address and callback path itself. The surprising part is mutating an explicit redirect URI override.

Additional information

This appears to be in codex-rs/rmcp-client/src/perform_oauth_login.rs: resolve_redirect_uri(...) returns the configured callback URL, and then append_callback_id_to_redirect_uri(...) is applied unconditionally.

Suggested high-level fix:

  • if callback_url / mcp_oauth_callback_url is set, use it as-is;
  • otherwise keep appending the server-derived callback id to generated local callback URLs.

Local validation of the proposed patch:

cargo fmt -p codex-rmcp-client
cargo test -p codex-rmcp-client callback

Environment used while diagnosing:

Codex CLI: codex-cli 0.0.0 local build
Platform: Darwin 25.5.0 arm64 arm
Terminal: Apple Terminal

I read docs/contributing.md and understand unsolicited PRs are not accepted. I am opening this issue first with root-cause analysis and a high-level fix outline; the branch is provided only as a concrete reference if maintainers want it.

Palantir context — October 15, 2026

Related Palantir request: per-plugin fixed callback ports are implemented in merged PR #38448, including oauth.callbackPort in compatibility .mcp.json packages. This is distinct from this ticket’s callback-URL fidelity defect; the PR is not evidence that this ticket is fixed. Palantir’s installed version and authentication retest remain unverified.

Activity

  1. added
    bug
    CLI
    mcp
    auth
    config
    on Jun 28, 2026
  2. sshishigin commented on Jun 29, 2026

    @sshishigin
    Author

    Related public MCP OAuth reports I found while debugging this:

    This issue is narrower: even when the OAuth client id and callback port/url are already configurable, is not treated as an exact redirect URI. Fixing that should help the static/pre-registered-client cases where providers require exact redirect URI matching.

  3. sshishigin commented on Jun 29, 2026

    @sshishigin
    Author

    Small correction to my previous comment: the omitted config key in the last paragraph is mcp_oauth_callback_url.

  4. wgu9 commented on Jun 29, 2026

    @wgu9

    I checked current main (80f54d1) and this looks like a precise path-construction mismatch in the MCP OAuth helper.

    Relevant owner path: codex-rs/rmcp-client/src/perform_oauth_login.rs.

    The code currently does both:

    • resolve_redirect_uri(server, callback_url) returns the configured callback URL as the redirect URI
    • append_callback_id_to_redirect_uri(redirect_uri, callback_id) appends a server-derived path segment before query params

    There are tests for appending the callback id and for preserving query placement, but the reported issue is about wanting the configured callback URL to be used as an exact registered redirect URI. If an OAuth provider has strict redirect URI matching, appending /{callback_id} turns a valid configured URL into a different URI.

    A conservative fix shape would be to split the concepts:

    • the registered redirect URI sent to the OAuth provider
    • the local/host callback route Codex listens for or matches
    • the anti-confusion server binding token currently encoded as callback_id

    Regression test: configure callback_url = "https://callbacks.example.com/oauth/callback", assert the authorize request uses exactly that URI, and separately assert callback validation still binds the response to the intended MCP server.

  5. Poent commented on Aug 14, 2026

    @Poent

    Adding a concrete reproduction against a public hosted MCP server: ElevenLabs Hosted MCP.

    Environment

    • Windows 11
    • Codex Desktop / CLI 0.147.0-alpha.6.6
    • MCP endpoint: https://api.us.elevenlabs.io/v1/mcp
    • Transport: Streamable HTTP
    • ElevenLabs' published OAuth client ID: dee9ba45-a592-4730-a321-a7b90a00c436

    Configuration:

    [mcp_servers.elevenlabs]
    url = "https://api.us.elevenlabs.io/v1/mcp"
    scopes = ["convai_read", "convai_write", "text_to_speech", "speech_history_read"]
    
    [mcp_servers.elevenlabs.oauth]
    client_id = "dee9ba45-a592-4730-a321-a7b90a00c436"

    Login command:

    codex mcp login elevenlabs --scopes convai_read,convai_write,text_to_speech,speech_history_read

    Observed progression

    1. Without the explicit client ID, Codex attempts dynamic client registration and fails because ElevenLabs does not support DCR:

      Registration failed: Dynamic client registration not supported
      
    2. Adding the published client ID correctly bypasses DCR and opens the authorization URL.

    3. Codex sends a loopback redirect shaped like:

      http://127.0.0.1:63546/callback/6MFBM1In3Ey-
      

      The 6MFBM1In3Ey- suffix is exactly the deterministic callback ID Codex derives from https://api.us.elevenlabs.io/v1/mcp.

    4. ElevenLabs rejects the request before consent with:

      Authorization Error
      Invalid redirect_uri
      

      Codex subsequently times out waiting for a callback that the provider never sends.

    Working control case

    The same ElevenLabs account, endpoint, published client ID, and scopes authenticate successfully through Claude. Claude sends its registered hosted callback:

    https://claude.ai/api/mcp/auth_callback
    

    The ElevenLabs consent screen then opens normally and identifies the OAuth application as “Claude — Official ElevenLabs connector for Claude.”

    This confirms the ElevenLabs OAuth service and account are working; the interoperability failure is specific to the redirect URI produced by Codex.

    Relevant provider documentation:

    Why this issue blocks the integration

    ElevenLabs provides a fixed/pre-registered client and no DCR endpoint. Codex can now accept that static client ID, but it unconditionally appends the server-specific callback ID to both generated and explicitly configured callback URLs. Therefore, there is no native Codex configuration that can send an exact pre-registered redirect URI for this integration.

    A compatible fix could preserve the callback-ID behavior by default while providing an explicit exact-redirect mode for static/pre-registered OAuth clients, or provide a Codex-hosted callback flow.

    This reproduces on a current Codex build, and current main still appears to append the callback ID unconditionally.

  6. iKondratiy commented on Sep 2, 2026

    @iKondratiy

    I can confirm a current real-world interoperability case with Codex CLI 0.152.1 and Higgsfield's Blender Bridge (https://bridge.higgsfield.ai/mcp).

    Environment:

    • macOS 26.7 (25G227), Apple Silicon
    • Codex CLI 0.152.1
    • Blender 5.2
    • Higgsfield Blender add-on 1.5.48

    The latest Higgsfield add-on hard-codes http://localhost:56444/callback, while Codex uses the server-specific callback http://127.0.0.1:56444/callback/sqXrK_ZgopWE. Higgsfield's upstream Clerk authorization endpoint rejects the latter with:

    invalid_request: The 'redirect_uri' parameter does not match any of the OAuth 2.0 Client's pre-registered redirect urls.
    

    The provider's DCR endpoint accepts and echoes both callback forms, but authorization still rejects them. Its authorization-server metadata does not advertise authorization_response_iss_parameter_supported: true.

    The current Codex documentation now explicitly says that Codex appends a server-specific callback ID when issuer-bound responses are not advertised, and that a configured callback without the correct ID is ignored:
    https://learn.chatgpt.com/docs/extend/mcp#oauth-client-registration-and-callbacks

    So the immediate server-side defect is Higgsfield's DCR/Clerk registration mismatch. However, Codex could make this failure much easier to diagnose. Suggested diagnostic improvement:

    • when ignoring a configured callback because issuer support is absent, print that reason explicitly;
    • display the exact callback URI that the provider must register;
    • mention that stable /callback requires authorization_response_iss_parameter_supported: true plus a matching iss response.

    This preserves Codex's mix-up protection while making provider-side misconfiguration obvious. I am filing the provider-specific issue with Higgsfield separately.

  7. prabhuavula7 commented on Sep 3, 2026

    @prabhuavula7

    Hit this exact behavior integrating a production MCP server (Auth0-backed, exact-match callback allowlisting, DCR/CIMD both intentionally disabled) with Codex CLI 0.146.0 and confirmed unchanged on 0.153.0.

    Config:

    [mcp_servers.actionatlas.oauth]
    client_id = "..."
    callback_port = 33418
    callback_url = "http://127.0.0.1:33418/callback"

    codex mcp login generates redirect_uri=http://127.0.0.1:33418/callback/<callback_id> instead of the configured URL verbatim, exactly as described here. Our authorization server rejects it with a callback URL mismatch since it requires exact registration.

    One data point that might help triage: the appended <callback_id> is deterministic, not random — reproduced locally as base64url(SHA256(<exact MCP server URL string>)[:9]). It's stable across mcp remove/mcp add cycles and across the 0.146.0 → 0.153.0 upgrade. We worked around this by pre-registering the full deterministic URL (callback_url + / + that hash) on our end, which works but obviously depends on an implementation detail rather than the documented contract. Would much rather have callback_url, when explicitly set, be used verbatim as this issue requests.

    Happy to share more repro detail if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIauthbugconfigmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions