openai/codex · error · anyhow::Error

invalid MCP OAuth callback port `{config_port}`: port must b

Error message

invalid MCP OAuth callback port `{config_port}`: port must be between 1 and 65535

What it means

Error "invalid MCP OAuth callback port `{config_port}`: port must be between 1 and 65535" thrown in openai/codex.

Source

Thrown at codex-rs/rmcp-client/src/perform_oauth_login.rs:415

struct OauthLoginFlow {
    auth_url: String,
    oauth_state: OAuthState,
    authorization_server_issuer: Option<String>,
    rx: oneshot::Receiver<CallbackResult>,
    guard: CallbackServerGuard,
    server_name: String,
    server_url: String,
    store_mode: OAuthCredentialsStoreMode,
    keyring_backend_kind: AuthKeyringBackendKind,
    launch_browser: bool,
    timeout: Duration,
}

fn resolve_callback_port(callback_port: Option<u16>) -> Result<Option<u16>> {
    if let Some(config_port) = callback_port {
        if config_port == 0 {
            bail!(
                "invalid MCP OAuth callback port `{config_port}`: port must be between 1 and 65535"
            );
        }
        return Ok(Some(config_port));
    }

    Ok(None)
}

fn local_redirect_uri(server: &Server) -> Result<String> {
    match server.server_addr() {
        tiny_http::ListenAddr::IP(std::net::SocketAddr::V4(addr)) => {
            let ip = addr.ip();
            let port = addr.port();
            Ok(format!("http://{ip}:{port}/callback"))
        }
        tiny_http::ListenAddr::IP(std::net::SocketAddr::V6(addr)) => {
            let ip = addr.ip();

View on GitHub (pinned to 339751715c)

When it happens

Trigger: Thrown at codex-rs/rmcp-client/src/perform_oauth_login.rs:415 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/3a3ec96c64134483. Report an issue: GitHub.