mirror of
https://github.com/openai/codex.git
synced 2026-11-17 14:58:36 +00:00
Propagate custom CA settings to local MCP servers (#38040)
## Why Local stdio MCP servers may start in a different working directory from Codex, so inherited relative CA bundle paths can otherwise resolve to the wrong file. ## What changed - Forward the supported custom CA environment variables to local stdio MCP servers, convert inherited non-empty paths to absolute paths, and let explicit MCP environment overrides take precedence. - Match CA variable names and `PATH` case-insensitively where required, avoiding duplicate environment entries and preserving executable discovery on Windows. ## Testing - Add an end-to-end stdio MCP test covering relative inherited CA paths, empty values, explicit overrides, alternate key casing, and a different server working directory. - Exercise executable resolution with Windows-style `Path` casing. GitOrigin-RevId: ea1bc0ae63bc0dc780acb8363b2ed102120f282e
This commit is contained in:
1 parent
dad1db87bb
commit
b2543af02b
5 files changed
+171
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use codex_config::types::McpServerEnvVar;
|
||||
use codex_network_proxy::CUSTOM_CA_ENV_KEYS;
|
||||
use codex_protocol::shell_environment::is_non_inheritable_env_var;
|
||||
use http::HeaderMap;
|
||||
use http::HeaderName;
|
||||
@@ -22,8 +23,34 @@ pub(crate) fn create_env_for_mcp_server(
|
||||
.copied()
|
||||
.chain(additional_env_vars)
|
||||
.filter_map(|var| env::var_os(var).map(|value| (OsString::from(var), value)))
|
||||
.chain(extra_env.unwrap_or_default())
|
||||
.collect();
|
||||
for name in CUSTOM_CA_ENV_KEYS {
|
||||
let Some(value) = env::var_os(name) else {
|
||||
continue;
|
||||
};
|
||||
if value.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let value = std::path::absolute(value)?.into_os_string();
|
||||
#[cfg(windows)]
|
||||
env.retain(|key, _| !key.to_string_lossy().eq_ignore_ascii_case(name));
|
||||
env.insert(OsString::from(name), value);
|
||||
}
|
||||
for (name, value) in extra_env.unwrap_or_default() {
|
||||
if cfg!(windows)
|
||||
|| name.to_str().is_some_and(|name| {
|
||||
CUSTOM_CA_ENV_KEYS
|
||||
.iter()
|
||||
.any(|ca_name| ca_name.eq_ignore_ascii_case(name))
|
||||
})
|
||||
{
|
||||
env.retain(|key, _| {
|
||||
!key.to_string_lossy()
|
||||
.eq_ignore_ascii_case(&name.to_string_lossy())
|
||||
});
|
||||
}
|
||||
env.insert(name, value);
|
||||
}
|
||||
env.retain(|name, _| {
|
||||
name.to_str()
|
||||
.is_none_or(|name| !is_non_inheritable_env_var(name))
|
||||
|
||||
Reference in new issue
Block a user