From 7d3e696c4c120d15ee51c5cfa10d74aa356c9e0f Mon Sep 17 00:00:00 2001 From: aidan Date: Thu, 1 Oct 2026 22:30:50 +0000 Subject: [PATCH] Preserve Windows environment variables for remote MCP servers (#50129) ## Why When Codex runs on Unix and launches a stdio MCP server on a Windows executor, explicit remote environment variables activate an allowlist based on Unix defaults. This can filter out Windows runtime and temporary-directory variables. ## What changed Include `SYSTEMROOT`, `TEMP`, and `TMP` in the remote environment allowlist whenever explicit remote variables are requested. ## Testing Extend the environment-filtering test to verify that `SystemRoot`, `TEMP`, and `TMP` survive alongside requested variables while unrequested secrets remain excluded. GitOrigin-RevId: 059c9e23833be66aaf5b65ba5f95013f94f0f792 --- .../rmcp-client/src/stdio_server_launcher.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/codex-rs/rmcp-client/src/stdio_server_launcher.rs b/codex-rs/rmcp-client/src/stdio_server_launcher.rs index 433f532a13..195e00765f 100644 --- a/codex-rs/rmcp-client/src/stdio_server_launcher.rs +++ b/codex-rs/rmcp-client/src/stdio_server_launcher.rs @@ -687,8 +687,12 @@ impl ExecutorStdioServerLauncher { // environment, not copied from Codex. Start from `All` only so the // named remote variable is available to the filter below; the // effective child env is still limited by `include_only`. + // The orchestrator may be Unix while the executor is Windows. + // Preserve Windows runtime initialization and temporary-directory + // inputs even when explicit remote vars activate this allowlist. crate::utils::DEFAULT_ENV_VARS .iter() + .chain(["SYSTEMROOT", "TEMP", "TMP"].iter()) .map(|name| (*name).to_string()) .chain(remote_env_vars.iter().cloned()) .collect() @@ -763,6 +767,15 @@ mod tests { let env = shell_environment::create_env_from_vars( [ ("PATH".to_string(), "/remote/bin".to_string()), + ("SystemRoot".to_string(), r"C:\Windows".to_string()), + ( + "TEMP".to_string(), + r"C:\Users\test\AppData\Local\Temp".to_string(), + ), + ( + "TMP".to_string(), + r"C:\Users\test\AppData\Local\Temp".to_string(), + ), ("REMOTE_TOKEN".to_string(), "remote-secret".to_string()), ( "UNREQUESTED_SECRET".to_string(), @@ -774,6 +787,16 @@ mod tests { ); assert_eq!(env.get("PATH").map(String::as_str), Some("/remote/bin")); + assert_eq!( + env.get("SystemRoot").map(String::as_str), + Some(r"C:\Windows") + ); + for name in ["TEMP", "TMP"] { + assert_eq!( + env.get(name).map(String::as_str), + Some(r"C:\Users\test\AppData\Local\Temp") + ); + } assert_eq!( env.get("REMOTE_TOKEN").map(String::as_str), Some("remote-secret")