Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Preserve Windows environment variables for remote MCP servers (#50129)

aidan7d3e696c4c12
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")