Repository navigation
Conversation
Fixes MCP server startup timeouts on Windows by including critical environment variables required for npm/npx operations: - APPDATA: Required for npm configuration and cache storage - SYSTEMROOT: Required for DNS resolution and network operations Without these variables, npm fails with EAI_FAIL errors during package fetching, causing MCP servers to timeout during initialization. Includes comprehensive tests validating the necessity of these variables through empirical testing on Windows. Fixes openai#3408
|
Thanks for the contribution, and apologies for the slow response. This PR targets the same issue as another earlier PR that we received. Perhaps you could take a look at that PR and offer your thoughts on it? |
|
@etraut-openai Thank you for the review. PR #3866 does address this issue by including the critical environment variables needed. It also includes additional environment variables that might potentially be needed, which could make it a more robust solution than this PR #3994. This PR follows the YAGNI (You Aren't Gonna Need It) principle by including only the critical environment variables that have been empirically validated through comprehensive testing (windows_env_tests) as essential for npm/npx operations on Windows. Whether either PR or another alternative with the critical environment variables is adopted, it will resolve issue #3408 and enable Windows users to use MCP in Codex more seamlessly. |
|
I believe this has already been resolved via #5579 |
|
@etraut-openai Thanks for the follow-up and clarification. I've confirmed that PR #5579 does indeed resolve the issue. Glad to see the problem is fixed for Windows users! |
What
This PR fixes the "request timed out" error when initializing MCP servers on Windows that use
npx,uvx, or other script-based commands.Fixes #3408
Why
MCP servers fail to start on Windows due to missing critical environment variables:
SYSTEMROOT: Windows DNS resolution requires system libraries located under
%SystemRoot%\System32. Without this variable, the DNS resolver cannot locate essential components like the hosts file and system DLLs. This causes network requests to fail withEAI_FAILerrors, preventing npm registry connections needed by commands likenpx @playwright/mcp@latest.APPDATA: npm and npx store their configuration and cache in
%APPDATA%\npmand%APPDATA%\npm-cache. Without this variable, npm cannot locate its cache directory and fails withENOENT: no such file or directoryerrors when attempting any package operations.How
Changes
codex-rs/mcp-client/src/mcp_client.rs: Added two critical environment variables toDEFAULT_ENV_VARSon Windows:Testing
Added comprehensive test suite (
windows_env_tests) that empirically validates which environment variables are critical for npm/npx operations on Windows:To run the validation tests:
cargo test -p codex-mcp-client --lib tests::windows_env_tests -- --ignored --nocapture --test-threads=1Tested On
Local Checks
All checks pass:
Result
Before:
After:
With this fix, Windows users can run MCP servers without timeout errors, eliminating the need to manually configure SYSTEMROOT and APPDATA in
~/.codex/config.toml.Additional Context
This issue has been affecting Windows users since v0.31.0. While workarounds exist (manually adding environment variables to config.toml), this PR provides a proper fix at the source level, ensuring MCP servers work out-of-the-box on Windows just as they do on other platforms.
The extensive test suite ensures the fix is robust and documents the exact requirements for future maintainers.