Repository navigation
Open
Labels
enhancementRequest for a new feature that's not currently supported
Description
Release Line
2.x (main branch)
Problem Description
In src/mcp/os/win32/utilities.py:64-81, get_windows_executable_command is defined as:
def get_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:
if command_path := shutil.which(command):
return command_path
for ext in [".cmd", ".bat", ".exe", ".ps1"]:
ext_version = f"{command}{ext}"
if ext_path := shutil.which(ext_version):
return ext_path
return command
except OSError:
return command # path probing failed (permissions, broken symlinks)There are two issues with this fallback loop:
-
.ps1cannot be resolved byshutil.whichand cannot be directly executed as a Win32 executable:- On Windows,
shutil.which()requires file extensions to match an entry in the systemPATHEXTenvironment variable. By default,PATHEXTcontains.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
.ps1were returned, attempting to pass a.ps1file directly toanyio.open_process()orsubprocess.Popenwithout invokingpowershell.exe -Filefails withOSError: [WinError 193] %1 is not a valid Win32 application.
- On Windows,
-
Redundant fallback loop for
.cmd,.bat, and.exe:- Because
shutil.which(command)at line 71 already checks the current directory andPATHagainst all entries inPATHEXT(which already includes.cmd,.bat, and.exe), looping over[".cmd", ".bat", ".exe"]withf"{command}{ext}"is redundant dead code when the executable is onPATH.
- Because
Minimal Reproduction
import shutil
from mcp.os.win32.utilities import get_windows_executable_command
# Notice shutil.which("something.ps1") returns None because .ps1 is not in PATHEXT
print("PATHEXT:", shutil._get_pathext()) # .ps1 is absent by default on WindowsExpected Behavior
- Do not attempt to treat
.ps1as a direct executable target viashutil.which()unless invoked via the PowerShell host, or remove.ps1from the extension list. - Simplify executable probing to avoid redundant checks for extensions already covered by
shutil.which'sPATHEXThandling.
Environment
- OS: Windows 10 / 11
- Python: 3.11+
- MCP Python SDK: 2.x (
mainbranch)
I would be happy to submit a PR with test coverage if assigned.
Assisted by AI; reviewed and verified.
Metadata
Metadata
Assignees
Labels
enhancementRequest for a new feature that's not currently supported
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.