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 -1
View File
@@ -566,6 +566,7 @@ fn declared_placement_preserves_local_plugin_normalization() {
bearer_token_env_var: None,
http_headers: None,
env_http_headers: None,
http_headers_helper: None,
},
environment_id: DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
enabled: true,
@@ -585,6 +586,18 @@ fn declared_placement_preserves_local_plugin_normalization() {
oauth_resource: None,
tools: HashMap::new(),
};
let mut expected_helper = McpServerConfig {
oauth: None,
..expected_http.clone()
};
let McpServerTransportConfig::StreamableHttp {
http_headers_helper,
..
} = &mut expected_helper.transport
else {
unreachable!("expected HTTP transport");
};
*http_headers_helper = Some("./auth.sh".to_string());
let outcome = parse_plugin_mcp_config(
&plugin_root,
@@ -598,7 +611,8 @@ fn declared_placement_preserves_local_plugin_normalization() {
"type": "http",
"url": "https://example.com/mcp",
"oauth": {"clientId": "client-id", "callbackPort": 9876}
}
},
"helper": {"type":"http","url":"https://example.com/mcp","http_headers_helper":"./auth.sh"}
}"#,
)
.expect("parse plugin MCP config");
@@ -608,6 +622,7 @@ fn declared_placement_preserves_local_plugin_normalization() {
PluginMcpConfigParseOutcome {
servers: BTreeMap::from([
("demo".to_string(), expected_stdio),
("helper".to_string(), expected_helper),
("hosted".to_string(), expected_http),
]),
errors: Vec::new(),
@@ -839,6 +854,7 @@ fn local_environment_placement_preserves_http_env_references() {
"X-Account".to_string(),
"ACCOUNT_ID".to_string(),
)])),
http_headers_helper: None,
},
environment_id: DEFAULT_MCP_SERVER_ENVIRONMENT_ID.to_string(),
enabled: true,