modelcontextprotocol / modelcontextprotocol/typescript-sdk

DEFAULT_INHERITED_ENV_VARS

Open Beginner friendly
#2,037 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P2 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Summary

The Windows branch of DEFAULT_INHERITED_ENV_VARS in src/client/stdio.ts is missing several variables that Windows needs to resolve and execute common commands. As a result, MCP servers that try to spawn npm, git, .bat/.cmd files, or use cmd.exe features can fail in non-obvious ways even when PATH is correctly inherited.

Current state

src/client/stdio.ts (identical on main):

export const DEFAULT_INHERITED_ENV_VARS =
    process.platform === 'win32'
        ? [
              'APPDATA', 'HOMEDRIVE', 'HOMEPATH', 'LOCALAPPDATA',
              'PATH', 'PROCESSOR_ARCHITECTURE', 'SYSTEMDRIVE',
              'SYSTEMROOT', 'TEMP', 'USERNAME', 'USERPROFILE',
              'PROGRAMFILES'
          ]
        : ['HOME', 'LOGNAME', 'PATH', 'SHELL', 'TERM', 'USER'];

Missing variables

  • PATHEXT — Windows uses this to determine which file extensions count as executable when resolving a bare command name. Without it, spawning npm, git, or any .cmd/.bat shim by name fails with ENOENT even when PATH is set correctly.
  • COMSPEC — Path to cmd.exe. Required by Node's child_process.spawn({ shell: true }), by npm run scripts internally, and by anything that shells out via cmd.exe.
  • PROGRAMFILES(X86) — 32-bit Program Files path on 64-bit Windows. Tools that probe both paths get inconsistent results when only one is inherited.
  • PROGRAMW6432 — Resolves to the 64-bit Program Files path even from 32-bit processes.
  • WINDIR — Path to the Windows directory. Used as a fallback by some legacy tooling and PowerShell modules.

Proposed change

Add these five variables to the Windows branch of DEFAULT_INHERITED_ENV_VARS. They're non-secret, system-defined, and pose no privacy or security concern beyond what's already inherited (PATH, SYSTEMROOT, etc.).

The same gap exists on both main and v1.x.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/client/stdio.ts, especially the Windows branch of DEFAULT_INHERITED_ENV_VARS. Review how the inherited environment is used when spawning MCP servers, then add PATHEXT, COMSPEC, PROGRAMFILES(X86), PROGRAMW6432, and WINDIR to both main and v1.x as applicable. Done means the Windows environment includes all five variables without changing the non-Windows list.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.