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
@@ -44,7 +44,11 @@ pub fn resolve(
|
||||
cwd: &Path,
|
||||
) -> std::io::Result<OsString> {
|
||||
// Extract PATH from environment for search locations
|
||||
let search_path = env.get(std::ffi::OsStr::new("PATH"));
|
||||
let search_path = env.iter().find_map(|(name, value)| {
|
||||
name.to_string_lossy()
|
||||
.eq_ignore_ascii_case("PATH")
|
||||
.then_some(value)
|
||||
});
|
||||
|
||||
// Attempt resolution via which crate
|
||||
match which::which_in(&program, search_path, cwd) {
|
||||
@@ -139,6 +143,16 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_resolved_program_executes_successfully() -> Result<()> {
|
||||
let env = TestExecutableEnv::new()?;
|
||||
#[cfg(windows)]
|
||||
let env = {
|
||||
let mut env = env;
|
||||
let path = env
|
||||
.mcp_env
|
||||
.remove(std::ffi::OsStr::new("PATH"))
|
||||
.expect("test environment should include PATH");
|
||||
env.mcp_env.insert(OsString::from("Path"), path);
|
||||
env
|
||||
};
|
||||
let program = OsString::from(&env.program_name);
|
||||
|
||||
// Apply platform-specific resolution
|
||||
|
||||
@@ -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