openai/codex · error · anyhow::Error
invalid MCP OAuth callback port
Error message
invalid MCP OAuth callback port `{config_port}`: port must be between 1 and 65535 What it means
Validation in resolve_callback_port: a callback port was configured (config_port 0 or otherwise outside 1..=65535) for the MCP OAuth loopback callback server, which cannot bind to such a port, so login fails before the server starts.
Solutions
- Set the MCP callback_port config to a value between 1 and 65535
- Omit callback_port to let the OS pick an ephemeral port
- Check for config values like 0 that are rejected explicitly
Defensive patterns
Strategy: validation
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.
Appendix: 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)