Skip to content

fix(mcp): Add critical Windows environment variables to resolve MCP startup timeouts - #3994

Closed
25621 wants to merge 1 commit into
openai:mainfrom
25621:fix/windows-mcp-env-vars
Closed

25621 wants to merge 1 commit into
openai:mainfrom
25621:fix/windows-mcp-env-vars

Conversation

@25621

@25621 25621 commented Sep 20, 2025

Copy link
Copy Markdown
Contributor

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:

  1. 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 with EAI_FAIL errors, preventing npm registry connections needed by commands like npx @playwright/mcp@latest.

  2. APPDATA: npm and npx store their configuration and cache in %APPDATA%\npm and %APPDATA%\npm-cache. Without this variable, npm cannot locate its cache directory and fails with ENOENT: no such file or directory errors when attempting any package operations.

How

Changes

  • codex-rs/mcp-client/src/mcp_client.rs: Added two critical environment variables to DEFAULT_ENV_VARS on Windows:
    "APPDATA",    // Required for npm configuration and cache storage
    "SYSTEMROOT", // Required for DNS resolution and network operations

Testing

Added comprehensive test suite (windows_env_tests) that empirically validates which environment variables are critical for npm/npx operations on Windows:

  • SYSTEMROOT tests: Verify that network operations fail without SYSTEMROOT (DNS resolution fails)
  • APPDATA tests: Verify that npm cache operations fail without APPDATA
  • Baseline tests: Confirm npx works correctly with all required variables
  • Comprehensive validation: Systematically removes each variable to determine criticality

To run the validation tests:

cargo test -p codex-mcp-client --lib tests::windows_env_tests -- --ignored --nocapture --test-threads=1

Tested On

  • Windows 11 (NT 10.0.26100.0 x64)
  • PowerShell 5.1 & 7+, CMD, Git Bash
  • MCP servers: playwright, context7, supabase, fetch
  • WSL (verified no regression)

Local Checks

All checks pass:

cargo test && cargo clippy --tests && cargo fmt -- --config imports_granularity=Item

Result

Before:

🖐 MCP client for `playwright` failed to start: request timed out
🖐 MCP client for `fetch` failed to start: request timed out
🖐 MCP client for `context7` failed to start: request timed out

After:

✅ All MCP servers start successfully without manual environment configuration

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.

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
@etraut-openai

Copy link
Copy Markdown
Contributor

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?

@25621

25621 commented Oct 30, 2025 •

Copy link
Copy Markdown
Contributor Author

@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.

@dylan-hurd-oai

dylan-hurd-oai commented Nov 4, 2025 •

Copy link
Copy Markdown
Contributor

I believe this has already been resolved via #5579

@etraut-openai

Copy link
Copy Markdown
Contributor

@25621, yes it looks like #5579 adds support for the same env variables as this PR, so I'm going to close this one. If you think that we've missed something, let us know.

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2025
@openai openai unlocked this conversation Nov 4, 2025
@25621

25621 commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCPs do not work natively on Windows (Powershell)

3 participants