openai/codex · error

MCP HTTP headers helper returned an invalid header value

Error message

MCP HTTP headers helper returned an invalid header value

What it means

Generic validation guard in the MCP HTTP headers helper: a header name/value pair produced by the helper could not be converted into a valid http::HeaderValue, meaning the value contains illegal bytes (non-visible ASCII, control characters, or non-ASCII) and the request cannot be sent with that header.

Solutions

  1. Fix the MCP header helper configuration so the header value contains only visible ASCII characters
  2. Trim or sanitize the header value before it reaches HeaderValue::from_str
  3. Log the offending header name (not value) to identify the source of the invalid bytes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/rmcp-client/src/http_headers.rs:401 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/0e5c2c5d12688db8. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rmcp-client/src/http_headers.rs:401

                | "origin"
                | "proxy-connection"
                | "referer"
                | "te"
                | "trailer"
                | "transfer-encoding"
                | "upgrade"
        ) {
            return Err(anyhow!(
                "MCP HTTP headers helper returned a reserved header"
            ));
        }
        if parsed.contains_key(&name) {
            return Err(anyhow!(
                "MCP HTTP headers helper returned duplicate header names"
            ));
        }
        let value = HeaderValue::from_str(&value)
            .map_err(|_| anyhow!("MCP HTTP headers helper returned an invalid header value"))?;
        parsed.insert(name, value);
    }
    Ok(parsed)
}

#[cfg(test)]
#[path = "http_headers_tests.rs"]
mod tests;

View on GitHub (pinned to 339751715c)