Add dynamic HTTP header helpers for MCP servers (#38245)

## What changed

- Add `http_headers_helper` configuration for local streamable HTTP MCP servers. The configured shell command runs once per connection and returns a JSON object of headers that is cached across requests.
- Apply helper headers to MCP startup and OAuth flows while restricting them to the server origin, stopping redirects, rejecting reserved or duplicate headers, and enforcing output and execution limits.
- Reject helpers for remote or managed-disabled servers, use the local environment working directory, and redact helper commands from `codex mcp list` and `codex mcp get` output.

## Testing

- Cover configuration validation, helper lifecycle and output parsing, origin isolation, OAuth discovery and token refresh, managed requirements, environment selection, and CLI redaction.

GitOrigin-RevId: 84e0e26ce75520b0869d37c72b1678e033bd6818
This commit is contained in:
xl-openai authored and copyberry committed 2026-08-12 20:36:32 +00:00
1 parent 8d4d57387a
commit 379cb68444
38 files changed
+1285 -72

No files matched your search

+17
View File
@@ -14,6 +14,7 @@ use codex_rmcp_client::OAuthDiscoveryTimeout;
use codex_rmcp_client::OAuthProviderError;
use codex_rmcp_client::StreamableHttpRedirectMode;
use codex_rmcp_client::determine_streamable_http_auth_status;
use codex_rmcp_client::determine_streamable_http_auth_status_from_credentials;
use codex_rmcp_client::discover_streamable_http_oauth;
use futures::FutureExt;
use futures::future::join_all;
@@ -92,6 +93,7 @@ fn oauth_login_candidate(transport: &McpServerTransportConfig) -> Option<McpOAut
bearer_token_env_var,
http_headers,
env_http_headers,
..
} = transport
else {
return None;
@@ -247,7 +249,22 @@ async fn compute_auth_status(
bearer_token_env_var,
http_headers,
env_http_headers,
http_headers_helper,
} => {
if http_headers_helper.is_some() {
// Status inspection must not execute an arbitrary local helper. Existing
// credentials remain reportable; otherwise discovery waits for startup/login.
return Ok(determine_streamable_http_auth_status_from_credentials(
config.oauth_credential_name(server_name).as_ref(),
url,
bearer_token_env_var.as_deref(),
http_headers.clone(),
env_http_headers.clone(),
store_mode,
keyring_backend_kind,
)?
.unwrap_or(McpAuthState::Unknown));
}
let http_client = runtime_context
.resolve_http_client(server_name, config)
.map_err(anyhow::Error::msg)?;
+1
View File
@@ -565,6 +565,7 @@ fn mcp_server_config_for_url(
bearer_token_env_var: codex_apps_mcp_bearer_token_env_var(),
http_headers: Some(http_headers),
env_http_headers,
http_headers_helper: None,
},
auth: auth_mode,
environment_id: codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
+2
View File
@@ -401,6 +401,7 @@ async fn effective_mcp_servers_preserve_runtime_servers() {
bearer_token_env_var: None,
http_headers: None,
env_http_headers: None,
http_headers_helper: None,
},
environment_id: codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
enabled: true,
@@ -428,6 +429,7 @@ async fn effective_mcp_servers_preserve_runtime_servers() {
bearer_token_env_var: None,
http_headers: None,
env_http_headers: None,
http_headers_helper: None,
},
environment_id: codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
enabled: true,