Windows: get_windows_executable_command() attempts invalid .ps1 probe and contains redundant extension loop
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #3927 di @EnesKartal — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
Inizia da src/mcp/os/win32/utilities.py ed esamina get_windows_executable_command, poi controlla i test specifici di Windows per la risoluzione degli eseguibili. Rimuovi il controllo di .ps1 e i controlli ridondanti delle estensioni descritti nell’issue, e aggiungi test per il comportamento di fallback. Il lavoro è completato quando i test mostrano che .ps1 non viene restituito come comando direttamente eseguibile e che la ricerca esistente degli eseguibili Windows continua a funzionare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 Windows
Expected 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.
- Lingua principale
- Python
- Stelle
- 25k
- Fork
- 4.2k
- Merge medio
- 10m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di modelcontextprotocol/python-sdk
-
v2
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
modelcontextprotocol/python-sdk#3978 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Client serves cached tools after its context exits with an exceptionForse già presa @jonxsong l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
modelcontextprotocol/python-sdk#3968 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
modelcontextprotocol/python-sdk#3957 ·
I maintainer di solito rispondono entro 1 giorno
-
v2
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
modelcontextprotocol/python-sdk#3934 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug v1
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
modelcontextprotocol/python-sdk#3929 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di modelcontextprotocol/python-sdk
Issue simili
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwiseForse già presa @abdulwaarith0 l’ha presa oggi. Apertaneeds-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
MakazhanAlpamys/Soup#3690 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug data-types native-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
ClickHouse/clickhouse-connect#1320 ·
I maintainer di solito rispondono entro 1 giorno
-
Public benchmark import end-to-end test fails when the test stack's worker runs the parity jobApertaaccepted
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
future-agi/future-agi#6392 ·
I maintainer di solito rispondono entro 1 giorno