Skip to content

fix(client): stop an inherited PATH from shadowing an explicit Path o… - #2900

Draft
liwenjie200543 wants to merge 1 commit into
modelcontextprotocol:mainfrom
liwenjie200543:fix/stdio-env-case-collision
Draft

liwenjie200543 wants to merge 1 commit into
modelcontextprotocol:mainfrom
liwenjie200543:fix/stdio-env-case-collision

Conversation

@liwenjie200543

@liwenjie200543 liwenjie200543 commented Sep 30, 2026 •

Copy link
Copy Markdown

What

StdioClientTransport.start() merged the default environment with the caller's env by plain spread. On Windows that produces a spawn env containing both the inherited PATH (from getDefaultEnvironment()) and the caller's Path when the caller spells it that way. Windows resolves environment variables case-insensitively, the inherited entry wins, and the caller's explicit value is silently discarded (issue #2859, where an explicit Path never reaches the server process).

Change

mergeSpawnEnv now drops inherited entries that differ from an override only in casing, so the caller's entry is the single value the child sees, with the casing the caller chose. On POSIX, PATH and Path are distinct variables and both survive — the platform flag is a parameter, so tests pin both modes without touching process.platform.

Verification

  • Real-process check on Windows (Node + cross-spawn, no mocks): spawning node -e "process.stdout.write(process.env.Path ?? process.env.PATH)" with an env merged the old way prints the inherited value; merged the new way it prints the caller's value.
  • New tests in packages/client/test/client/stdioEnvCase.test.ts: merge semantics for case-insensitive and case-sensitive modes, plus a transport-level test asserting the spawned env keeps the caller's Path. The transport test fails against the old spread on Windows (verified by stashing the fix).
  • pnpm vitest run in packages/client: 921 passed, 2 skipped. tsgo typecheck, eslint and prettier clean on the touched files.
  • Changeset included.

Fixes #2859

@changeset-bot

changeset-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 394b991

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

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/core-internal Patch

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 Sep 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2900

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2900

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2900

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2900

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2900

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2900

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2900

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2900

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2900

commit: 394b991

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Oct 1, 2026

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

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StdioClientTransport: explicit Path in env is ignored on Windows (inherited PATH wins)

1 participant