Repository navigation
[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
Conversation
…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>
🦋 Changeset detectedLatest 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 |
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #2043 to
v1.x. Fixes #2037 for v1.Motivation and Context
#2037 reported that the Windows branch of
DEFAULT_INHERITED_ENV_VARSdrops variables that Windows tools need. #2043 fixed it onmain(shipped in@modelcontextprotocol/client2.1.0) and closed the issue, butv1.xstill has the old list as of 1.32.2. The triage note on #2037 says v1.x needs the same change.When
StdioClientTransportgets noenv, or anenvthat is merged overgetDefaultEnvironment(), a Windows server process starts withoutPATHEXT,COMSPECorPROGRAMDATA. 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 unchangedv1.x(missingCOMSPEC,PATHEXT,PROGRAMDATA,PROGRAMFILES(X86),PROGRAMW6432,WINDIR) and passes with this change. The test setsprocess.platformtowin32and re-imports the module, so it checks the Windows list on Linux CI too. The test onmainonly checks the host platform's list.npm run check(typecheck, eslint, prettier) passes.npm run buildpasses for ESM and CJS.npm test: 56 files, 1859 tests pass (1858 before, plus the new one). On Windows the run also reports 2 unhandledUnexpected end of JSON inputerrors from the existingmore-based tests intest/client/stdio.test.ts. The same 2 errors appear on unchangedv1.x. CI runs on Linux, where those tests usetee.npx vitest run test/e2e/scenarios/stdio.test.ts: 6 of 7 pass, includingtransport:stdio:default-env-safelist.transport:stdio:shutdown-escalationfails on Windows with or without this change.McpServerstarted byStdioClientTransportwith noenvoption. Its tool runs PowerShellGet-Command nodeandssh.exe -V:v1.x: the server has noPATHEXT,COMSPECorPROGRAMDATA. PowerShell fails withThe term 'node' is not recognized ..., andssh.exe -Vexits 255 with no output.C:\Program Files\nodejs\node.exe, andssh.exe -Vexits 0 (OpenSSH_for_Windows_9.5p1).PATHEXTfixes PowerShell, and adding onlyPROGRAMDATAfixes OpenSSH.COMSPECalone 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
Checklist
Additional context
No error handling is involved: the change only adds names to a list.
🤖 Generated with Claude Code