You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In src/mcp/os/win32/utilities.py:64-81, get_windows_executable_command is defined as:
defget_windows_executable_command(command: str) ->str:
"""Resolves the command to a Windows executable path. Tries the bare name first, then the common script extensions (.cmd, .bat, .exe, .ps1). """try:
ifcommand_path:=shutil.which(command):
returncommand_pathforextin [".cmd", ".bat", ".exe", ".ps1"]:
ext_version=f"{command}{ext}"ifext_path:=shutil.which(ext_version):
returnext_pathreturncommandexceptOSError:
returncommand# path probing failed (permissions, broken symlinks)
There are two issues with this fallback loop:
.ps1 cannot be resolved by shutil.which and cannot be directly executed as a Win32 executable:
On Windows, shutil.which() requires file extensions to match an entry in the system PATHEXT environment variable. By default, PATHEXT contains .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, but does not include .ps1. Therefore, shutil.which(f"{command}.ps1") never resolves a PowerShell script.
Furthermore, even if a path ending in .ps1 were returned, attempting to pass a .ps1 file directly to anyio.open_process() or subprocess.Popen without invoking powershell.exe -File fails with OSError: [WinError 193] %1 is not a valid Win32 application.
Redundant fallback loop for .cmd, .bat, and .exe:
Because shutil.which(command) at line 71 already checks the current directory and PATH against all entries in PATHEXT (which already includes .cmd, .bat, and .exe), looping over [".cmd", ".bat", ".exe"] with f"{command}{ext}" is redundant dead code when the executable is on PATH.
Minimal Reproduction
importshutilfrommcp.os.win32.utilitiesimportget_windows_executable_command# Notice shutil.which("something.ps1") returns None because .ps1 is not in PATHEXTprint("PATHEXT:", shutil._get_pathext()) # .ps1 is absent by default on Windows
Expected Behavior
Do not attempt to treat .ps1 as a direct executable target via shutil.which() unless invoked via the PowerShell host, or remove .ps1 from the extension list.
Simplify executable probing to avoid redundant checks for extensions already covered by shutil.which's PATHEXT handling.
Environment
OS: Windows 10 / 11
Python: 3.11+
MCP Python SDK: 2.x (main branch)
I would be happy to submit a PR with test coverage if assigned.
I reproduced this and prepared a tested branch for it.
Problem
On Windows shutil.which only matches extensions listed in PATHEXT, and .ps1 is not in the default list (_WIN_DEFAULT_PATHEXT). So the f"{command}.ps1" probe in get_windows_executable_command can never resolve, and a returned .ps1 path could not be launched anyway: passing one to anyio.open_process or Popen raises OSError: [WinError 193].
Branch
fix/3878-windows-ps1-probe, commit 31e5684, on my fork. Changes:
src/mcp/os/win32/utilities.py: .ps1 removed from the fallback extension list, with a one line comment citing PATHEXT and WinError 193, and the docstring updated.
tests/issues/test_3878_windows_ps1_probe.py: new regression test that makes a .ps1 probe resolve and asserts the resolver still returns the bare command, plus three small tests for the existing bare name hit, extension hit and OSError fallback paths.
I left the .cmd / .bat / .exe loop in place. Under the default PATHEXT those probes duplicate the bare name lookup, but if PATHEXT is set without one of the entries, shutil.which("<name>.<ext>") still matches that exact filename, so deleting the loop would change behavior in that configuration. If you consider that configuration out of scope, the loop can go in the same branch.
GREEN with the branch, 4 passed in 0.02s. The related stdio tests (tests/client/test_stdio.py, tests/transports/stdio/test_posix.py) also pass, 41 tests.
Coverage for the touched function is 100% of statements and branches. The file itself stays at 34% locally because the rest of it is Windows only code and src/mcp/os/win32/utilities.py is omitted from the coverage source in pyproject.toml, so fail_under = 100 is unaffected.
Activity
Shanmukh-l33t commentedon Nov 19, 2026
I reproduced this and prepared a tested branch for it.
Problem
On Windows
shutil.whichonly matches extensions listed inPATHEXT, and.ps1is not in the default list (_WIN_DEFAULT_PATHEXT). So thef"{command}.ps1"probe inget_windows_executable_commandcan never resolve, and a returned.ps1path could not be launched anyway: passing one toanyio.open_processorPopenraisesOSError: [WinError 193].Branch
fix/3878-windows-ps1-probe, commit31e5684, on my fork. Changes:src/mcp/os/win32/utilities.py:.ps1removed from the fallback extension list, with a one line comment citingPATHEXTandWinError 193, and the docstring updated.tests/issues/test_3878_windows_ps1_probe.py: new regression test that makes a.ps1probe resolve and asserts the resolver still returns the bare command, plus three small tests for the existing bare name hit, extension hit andOSErrorfallback paths.I left the
.cmd/.bat/.exeloop in place. Under the defaultPATHEXTthose probes duplicate the bare name lookup, but ifPATHEXTis set without one of the entries,shutil.which("<name>.<ext>")still matches that exact filename, so deleting the loop would change behavior in that configuration. If you consider that configuration out of scope, the loop can go in the same branch.Evidence
RED on unmodified
main, 1 failed, 3 passed:GREEN with the branch, 4 passed in 0.02s. The related stdio tests (
tests/client/test_stdio.py,tests/transports/stdio/test_posix.py) also pass, 41 tests.Coverage for the touched function is 100% of statements and branches. The file itself stays at 34% locally because the rest of it is Windows only code and
src/mcp/os/win32/utilities.pyis omitted from the coverage source inpyproject.toml, sofail_under = 100is unaffected.Branch: Shanmukh-l33t/python-sdk@main...fix/3878-windows-ps1-probe
If a maintainer assigns this issue, I am happy to open a PR from this branch.
Implemented with AI assistance and reviewed by the account owner.