Skip to content

fix(mcp): preserve Windows env vars for MCP servers (#4180) - #4182

Closed
cpjet64 wants to merge 3 commits into
openai:mainfrom
cpjet64:fix/windows-compat
Closed

cpjet64 wants to merge 3 commits into
openai:mainfrom
cpjet64:fix/windows-compat

Conversation

@cpjet64

@cpjet64 cpjet64 commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #4180.

What
Expand the Windows DEFAULT_ENV_VARS list so MCP servers inherit COMSPEC, SYSTEMROOT, PROGRAMDATA, APPDATA, and other core variables used by CLI helpers and DNS
add a Windows-only regression test (test_create_env_for_mcp_server_includes_windows_defaults) that guards each entry in that list
keep the existing override test working cross‑platform by reading USERNAME on Windows

Why
Without those inherited variables, Windows MCP servers that shell out (Docker MCP gateway, npx-based servers, etc.) fail immediately because plugins, caches, or system DLLs can’t be located. The new test ensures we don’t regress on the required variable set.

How
Update codex-rs/mcp-client/src/mcp_client.rs
Introduce EnvVarGuard to safely mutate/restore env vars during tests
Document the rationale in the inline comment

Testing
just fmt
cargo test -p codex-mcp-client
just fix -p codex-mcp-client

@cpjet64

cpjet64 commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@github-actions

github-actions Bot commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


curtp seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

github-actions Bot added a commit that referenced this pull request Sep 24, 2025

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Comment thread codex-rs/mcp-client/src/mcp_client.rs Resolved
@cpjet64 cpjet64 closed this Oct 7, 2025
@cpjet64
cpjet64 deleted the fix/windows-compat branch October 7, 2025 12:57
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 7, 2025
@cpjet64
cpjet64 restored the fix/windows-compat branch October 9, 2025 22:57
@cpjet64
cpjet64 deleted the fix/windows-compat branch October 18, 2025 04:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers fail to start on Windows due to missing inherited environment variables

1 participant