fix(mcp): honor env PATHEXT for stdio commands - #56537
Open
ooiuuii wants to merge 1 commit into
Open
Conversation
teknium1
reviewed
Jul 15, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing the Windows MCP environment-resolution mismatch. Current main still calls shutil.which() from tools/mcp_tool.py:587-589 after _build_safe_env() merges the configured subprocess environment at tools/mcp_tool.py:426-446, so the fix targets a live path.
Problems
tests/tools/test_mcp_tool_issue_948.py:87createsdemo.cmd, but the same new test suppliesPATHEXT=.CMD. The proposed resolver derivesdemo.CMD; since the test only patchessys.platformand runs on Linux's case-sensitive filesystem, itsos.path.isfile()lookup cannot find the lowercase fixture.
Suggested changes
- Make the fixture extension match the configured PATHEXT casing (for example
demo.CMD), or mock the filesystem check while retaining a platform-independent regression test.
Automated hermes-sweeper review.
| bin_dir = tmp_path / "bin" | ||
| bin_dir.mkdir() | ||
| cmd_path = bin_dir / "demo.cmd" | ||
| cmd_path.write_text("@echo off\n", encoding="utf-8") |
Contributor
There was a problem hiding this comment.
This fixture is demo.cmd, while the test configures PATHEXT=.CMD. _which_in_env() constructs demo.CMD; with only sys.platform patched, Linux CI uses a case-sensitive filesystem and will not find this fixture. Please match the fixture casing or mock the lookup.
This was referenced Jul 28, 2026
Open
ooiuuii
force-pushed
the
fix/mcp-pathext-env-resolution
branch
from
August 12, 2026 11:23
2c9ae8e to
b64baac
Compare
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.
Fixes #56536
What does this PR do?
PATHEXTfrom the MCP env when a config supplies bothPATHandPATHEXT.Path/Pathextcasing instead of creating a duplicatePATHkey while prepending the resolved command directory.PATHEXTand mixed-case Windows env keys.Why?
_resolve_stdio_command()already supports resolving commands against a filtered MCPPATH, but on Windowsshutil.which(..., path=...)still consults the parent processPATHEXT. A stdio MCP config with its ownPATHEXTcould therefore fail to resolve a command that is valid in the configured subprocess environment.Proof
python -m py_compile tools\\mcp_tool.py tests\\tools\\test_mcp_tool_issue_948.pyLimitations
python -m pytest tests\\tools\\test_mcp_tool_issue_948.py -qcould not run in this checkout because pytest is not installed (No module named pytest).