forked from NousResearch/hermes-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(mcp): honor subprocess PATHEXT for stdio resolution #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hashbender
wants to merge
1
commit into
main
Choose a base branch
from
mirror/pr-56594
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| from tools import mcp_tool | ||
|
|
||
|
|
||
| def test_which_with_subprocess_env_uses_subprocess_pathext_on_windows(monkeypatch): | ||
| seen = {} | ||
| monkeypatch.setattr(mcp_tool.os, "name", "nt") | ||
| monkeypatch.setenv("PATHEXT", ".EXE") | ||
|
|
||
| def fake_which(command, path=None): | ||
| seen["command"] = command | ||
| seen["path"] = path | ||
| seen["pathext"] = os.environ.get("PATHEXT") | ||
| return "C:/tools/server.CMD" | ||
|
|
||
| with patch("tools.mcp_tool.shutil.which", side_effect=fake_which): | ||
| resolved = mcp_tool._which_with_subprocess_env( | ||
| "server", | ||
| path="C:/tools", | ||
| env={"PATH": "C:/tools", "PATHEXT": ".CMD"}, | ||
| ) | ||
|
|
||
| assert resolved == "C:/tools/server.CMD" | ||
| assert seen == {"command": "server", "path": "C:/tools", "pathext": ".CMD"} | ||
| assert os.environ["PATHEXT"] == ".EXE" | ||
|
|
||
|
|
||
| def test_resolve_stdio_command_passes_subprocess_path_and_pathext(monkeypatch): | ||
| monkeypatch.setattr(mcp_tool.os, "name", "nt") | ||
|
|
||
| def fake_which(command, path=None): | ||
| assert command == "server" | ||
| assert path == "C:/mcp/bin" | ||
| assert os.environ.get("PATHEXT") == ".BAT" | ||
| return "C:/mcp/bin/server.BAT" | ||
|
|
||
| with patch("tools.mcp_tool.shutil.which", side_effect=fake_which): | ||
| command, env = mcp_tool._resolve_stdio_command( | ||
| "server", | ||
| {"PATH": "C:/mcp/bin", "PATHEXT": ".BAT"}, | ||
| ) | ||
|
|
||
| assert command == "C:/mcp/bin/server.BAT" | ||
| assert env["PATH"].startswith("C:/mcp/bin") | ||
| assert env["PATHEXT"] == ".BAT" |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Misleading comments claim non-existent start_new_session fix; PID filter markers incomplete for LSP servers (bug)
Three issues in the
_filter_mcp_childrendefense added by this PR intools/mcp_tool.py:Line 1895 says "See agent/lsp/client.py for the complementary start_new_session fix" — but
agent/lsp/client.py:266does NOT passstart_new_session=Truetoasyncio.create_subprocess_exec.Lines 3037-3038 say "LSP servers and slash_worker now use start_new_session=True too" — but
tui_gateway/server.py:287does NOT passstart_new_session=Truetosubprocess.Popen, and neither does the LSP client.Lines 1891-1892 say the filter covers "jdtls/pyright/yaml-ls" — but
_NON_MCP_CHILD_CMDLINE_MARKERS(lines 3042-3048) only contains markers forjdtlsand TUI components (tui_gateway.slash_worker,tui_gateway.entry, Eclipse launcher markers). There are no markers forpyright-langserveroryaml-language-server.The pgid guard in
_send_signal(line 4933:pgid == _my_pgidcheck) prevents the gateway from self-killing when an LSP child leaks into_stdio_pgids. However, LSP servers that race into the PID snapshot delta and are not caught by the filter would still be incorrectly tracked and force-killed during MCP shutdown (lines 4965, 4979), disrupting language server features for the user.💡 Suggestion: The primary fix is to add
start_new_session=Truetoagent/lsp/client.py:266(asyncio.create_subprocess_exec) andtui_gateway/server.py:287(subprocess.Popen). This makes the PID filter true defense-in-depth. If that fix is deferred, at minimum: (a) addpyright-langserverandyaml-language-serverto_NON_MCP_CHILD_CMDLINE_MARKERS, and (b) update the misleading comments at lines 1895 and 3037-3038 to reflect the actual state.📋 Prompt for AI Agents
In agent/lsp/client.py, line 266, add
start_new_session=Trueto theasyncio.create_subprocess_exec()call. In tui_gateway/server.py, line 287, addstart_new_session=Trueto thesubprocess.Popen()call. Then update the comment at tools/mcp_tool.py line 1895 to remove the reference to the complementary fix (since it will now be present), and update the comment at line 3037 to say the fix has been applied rather than claiming it already exists. Consider adding'pyright-langserver'and'yaml-language-server'to_NON_MCP_CHILD_CMDLINE_MARKERSat line 3042 as defense-in-depth.