You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MCP servers fail to start on Windows due to missing inherited environment variables #4180
On Windows, configure an MCP server that shells out to another CLI (e.g., Docker MCP Gateway in ~/.codex/config.toml with command = "docker.exe" and args ["mcp", "gateway", "run"]).
Launch Codex CLI/TUI.
Observe that the MCP server exits immediately. Docker reports the CLI plugin is missing; npm/npx-based servers such as npx @playwright/mcp@latest time out while a “request timed out” error is surfaced in Codex.
Inspect the child process environment (or run the command manually with the same environment) and note that core variables like COMSPEC, SYSTEMROOT, PROGRAMDATA, LOCALAPPDATA, APPDATA, USERPROFILE, etc., are absent.
What is the expected behavior?
Codex should launch MCP servers with the full Windows shell environment (or at least the core variables listed above) so that CLI helpers, DNS resolution, and per-user caches work exactly as they do when the command is executed in PowerShell/CMD. Docker’s docker mcp … plugin and npx-based servers should start successfully without user-specific environment overrides.
What do you see instead?
Only PATH, PATHEXT, USERNAME, USERDOMAIN, USERPROFILE, TEMP, and TMP are preserved. Without COMSPEC the Docker CLI can’t find its plugin binary; without SYSTEMROOT DNS lookups fail (EAI_FAIL); without APPDATA npm/npx can’t locate their cache/config and exit with ENOENT. Codex reports these MCP servers as failed or timed out on start.
Additional information
A simple fix is to expand the Windows DEFAULT_ENV_VARS array in codex-rs/mcp-client/src/mcp_client.rs to include the missing core variables (COMSPEC, SYSTEMROOT, SYSTEMDRIVE, PROGRAMFILES, PROGRAMFILES(X86), PROGRAMDATA, LOCALAPPDATA, APPDATA, USERPROFILE, HOMEDRIVE, HOMEPATH, etc.) and add Windows-specific tests that assert create_env_for_mcp_server propagates each entry. I’ve prepared a branch (fix/windows-compat) that does this and verified it with the Docker gateway and npm-based MCP servers.
In addition to the base OS variables already covered by #4182, Windows environments that need to invoke native toolchains such as MSVC (for example, when Rust Analyzer spawns rustc with the MSVC target) require that a set of Visual Studio and Windows SDK related environment variables also be passed through.
Without these, cl.exe, link.exe, and the corresponding headers and libraries cannot be resolved, leading to failed builds inside Serena and downstream tools like Rust Analyzer.
The minimum additional variables to consider including in the whitelist are:
Just chiming in as an external user to confirm the impact: on Windows, this prevents certain MCP servers (e.g., Docker or npm/npx-based) from starting as expected. An upstream fix would help a lot since per-user workarounds aren’t practical. Thanks @cpjet64 and the Codex team for looking into it!
Activity
cpjet64 commentedon Sep 25, 2025
A temporary workaround for Windows users experiencing this issue (until the PR gets approved) is as follows:
Replace YOURUSERPROFILEGOESHERE with your actual Windows username before applying this config.
Note: This workaround works as long as MCP servers already run in CMD or PowerShell.
taichi commentedon Oct 2, 2025
In addition to the base OS variables already covered by #4182, Windows environments that need to invoke native toolchains such as MSVC (for example, when Rust Analyzer spawns
rustcwith the MSVC target) require that a set of Visual Studio and Windows SDK related environment variables also be passed through.Without these,
cl.exe,link.exe, and the corresponding headers and libraries cannot be resolved, leading to failed builds inside Serena and downstream tools like Rust Analyzer.The minimum additional variables to consider including in the whitelist are:
Compiler/toolchain paths
PATH,INCLUDE,LIB,LIBPATHVisual Studio installation context
VSINSTALLDIR,VCINSTALLDIR,VCToolsInstallDir,VCToolsVersion,VCToolsRedistDir,VisualStudioVersion,VS170COMNTOOLS,DevEnvDir,VCIDEInstallDirWindows SDK context
WindowsSdkDir,WindowsSDKVersion,WindowsSDKLibVersion,WindowsSdkBinPath,WindowsSdkVerBinPath,WindowsLibPath,UCRTVersion,UniversalCRTSdkDir,ExtensionSdkDir.NET references (used by MSBuild/MSVC toolchain)
FrameworkDir,FrameworkDir64,FrameworkVersion,FrameworkVersion64Developer PowerShell/Command Prompt metadata
variables prefixed with
VSCMD_This list is derived from the environment produced by
vcvarsall.bat/Launch-VsDevShell.ps1, and reflects the minimum set required for consistent MSVC/Windows SDK builds.https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022
Adding these to the whitelist would make Codex → Serena → Rust Analyzer workflows viable without requiring ad-hoc workarounds.
Leo-rq-yu commentedon Oct 3, 2025
Just chiming in as an external user to confirm the impact: on Windows, this prevents certain MCP servers (e.g., Docker or npm/npx-based) from starting as expected. An upstream fix would help a lot since per-user workarounds aren’t practical. Thanks @cpjet64 and the Codex team for looking into it!
cpjet64 commentedon Oct 4, 2025
@taichi I updated my PR to include that brilliant idea!
Update to support Codex CLI
Update to support Codex CLI (#325)
fix(windows-path): preserve PATH order; include core env vars (#5579)
fix(windows-path): preserve PATH order; include core env vars (openai…
etraut-openai commentedon Nov 11, 2025
The missing env variables listed above are now preserved. If you see additional missing env variables, please open a new issue.
fix(windows-path): preserve PATH order; include core env vars (openai…
fix(windows-path): preserve PATH order; include core env vars (openai…
jbeckton commentedon Oct 3, 2026
Github MCP does not work with Codex CLI on Windows in 2026 for this very reason. I found a fix for this. Open your terminal and type
claude.