From e97eb6fff37f8adb969264323980bf2dd6ee54bd Mon Sep 17 00:00:00 2001 From: Scott Turnbull Date: Mon, 20 Apr 2026 12:24:33 -0400 Subject: [PATCH] fix(runtime): pass HOME/TMP/TEMP to stdio MCP servers on all platforms Node/npx-backed stdio MCP servers (Gmail, AgentMail, Exa, etc.) need a usable HOME directory for npm cache and temp-file scratch space. Without it, npm errors with EACCES on /nonexistent or silently falls over when trying to write cache entries. Previously these three variables were only passed on Windows. Linux and macOS hosts launching stdio MCP servers through npx would get an empty env for HOME/TMP/TEMP, breaking most community MCP servers. Move the HOME/TMP/TEMP passthrough above the cfg!(windows) block so it applies to every platform. Remove the now-redundant entries from the Windows-only list. --- crates/openfang-runtime/src/mcp.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/openfang-runtime/src/mcp.rs b/crates/openfang-runtime/src/mcp.rs index 483ae7aa..13f59028 100644 --- a/crates/openfang-runtime/src/mcp.rs +++ b/crates/openfang-runtime/src/mcp.rs @@ -247,6 +247,13 @@ impl McpConnection { if let Ok(path) = std::env::var("PATH") { cmd.env("PATH", path); } + // Some stdio MCP servers launched via node/npx require a usable home + // directory even when they do not declare any explicit secret env vars. + for var in &["HOME", "TMP", "TEMP"] { + if let Ok(val) = std::env::var(var) { + cmd.env(var, val); + } + } // On Windows, npm/node need extra vars if cfg!(windows) { for var in &[ @@ -254,9 +261,6 @@ impl McpConnection { "LOCALAPPDATA", "USERPROFILE", "SystemRoot", - "TEMP", - "TMP", - "HOME", "HOMEDRIVE", "HOMEPATH", ] {