Skip to content

[v1.x] fix(client): add missing Windows env vars to DEFAULT_INHERITED_ENV_VARS (backport of #2043) - #3116

Open
tanishqbaweja wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
tanishqbaweja:fix/v1.x-windows-inherited-env-vars
Open

tanishqbaweja wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
tanishqbaweja:fix/v1.x-windows-inherited-env-vars

Conversation

@tanishqbaweja

Copy link
Copy Markdown

Backport of #2043 to v1.x. Fixes #2037 for v1.

Motivation and Context

#2037 reported that the Windows branch of DEFAULT_INHERITED_ENV_VARS drops variables that Windows tools need. #2043 fixed it on main (shipped in @modelcontextprotocol/client 2.1.0) and closed the issue, but v1.x still has the old list as of 1.32.2. The triage note on #2037 says v1.x needs the same change.

When StdioClientTransport gets no env, or an env that is merged over getDefaultEnvironment(), a Windows server process starts without PATHEXT, COMSPEC or PROGRAMDATA. A server that shells out to PowerShell then can't resolve native executables, and Windows OpenSSH exits 255. Both failures were reported on #2043.

This PR makes the Windows list identical to main's: the same six names (COMSPEC, PATHEXT, PROGRAMDATA, PROGRAMFILES(X86), PROGRAMW6432, WINDIR) in the same sorted order, so later cherry-picks stay clean. It adds a test and a patch changeset.

How Has This Been Tested?

On Windows 11, Node 24.20:

  • npx vitest run test/client/stdio.test.ts -t "Windows variables" fails on unchanged v1.x (missing COMSPEC, PATHEXT, PROGRAMDATA, PROGRAMFILES(X86), PROGRAMW6432, WINDIR) and passes with this change. The test sets process.platform to win32 and re-imports the module, so it checks the Windows list on Linux CI too. The test on main only checks the host platform's list.
  • npm run check (typecheck, eslint, prettier) passes.
  • npm run build passes for ESM and CJS.
  • npm test: 56 files, 1859 tests pass (1858 before, plus the new one). On Windows the run also reports 2 unhandled Unexpected end of JSON input errors from the existing more-based tests in test/client/stdio.test.ts. The same 2 errors appear on unchanged v1.x. CI runs on Linux, where those tests use tee.
  • npx vitest run test/e2e/scenarios/stdio.test.ts: 6 of 7 pass, including transport:stdio:default-env-safelist. transport:stdio:shutdown-escalation fails on Windows with or without this change.
  • End to end: a stdio McpServer started by StdioClientTransport with no env option. Its tool runs PowerShell Get-Command node and ssh.exe -V:
    • unchanged v1.x: the server has no PATHEXT, COMSPEC or PROGRAMDATA. PowerShell fails with The term 'node' is not recognized ..., and ssh.exe -V exits 255 with no output.
    • this branch: PowerShell resolves C:\Program Files\nodejs\node.exe, and ssh.exe -V exits 0 (OpenSSH_for_Windows_9.5p1).
    • Each fix comes from one variable: adding only PATHEXT fixes PowerShell, and adding only PROGRAMDATA fixes OpenSSH. COMSPEC alone fixes neither.

Breaking Changes

None. On Windows, child processes that use the default environment now also get these six system variables. None of them holds secrets. Non-Windows platforms are unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed (patch changeset)

Additional context

No error handling is involved: the change only adds names to a list.

🤖 Generated with Claude Code

…RS (v1.x backport of modelcontextprotocol#2043)

Backport of modelcontextprotocol#2043 to v1.x. On Windows, StdioClientTransport spawned servers
without PATHEXT, COMSPEC or PROGRAMDATA in their environment, so a server
that shells out to PowerShell could not resolve native executables, and
Windows OpenSSH exited 255. The Windows list now matches main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tanishqbaweja
tanishqbaweja requested a review from a team as a code owner October 27, 2026 19:08
@changeset-bot

changeset-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3fa2bd4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@3116

commit: 3fa2bd4

This branch has not been deployed

No deployments
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.

1 participant