Windows: get_windows_executable_command() attempts invalid .ps1 probe and contains redundant extension loop
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #3927 của @EnesKartal — đã đóng, không merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Bắt đầu với src/mcp/os/win32/utilities.py và kiểm tra get_windows_executable_command, sau đó xem các bài kiểm thử dành riêng cho Windows về việc phân giải tệp thực thi. Xóa bước kiểm tra .ps1 và các bước kiểm tra phần mở rộng dư thừa được mô tả trong issue, đồng thời bổ sung kiểm thử cho hành vi dự phòng. Hoàn tất khi các bài kiểm thử cho thấy .ps1 không được trả về dưới dạng lệnh có thể thực thi trực tiếp và việc tra cứu tệp thực thi Windows hiện có vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 25k
- Fork
- 4.2k
- Merge trung bình
- 10 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/python-sdk
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
modelcontextprotocol/python-sdk#3978 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Client serves cached tools after its context exits with an exceptionCó thể đã có người làm @jonxsong đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
modelcontextprotocol/python-sdk#3968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/python-sdk#3957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
v2
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
modelcontextprotocol/python-sdk#3934 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug v1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
modelcontextprotocol/python-sdk#3929 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/python-sdk
Issue tương tự
-
Relatório de erro do LinuxToysĐang mởauto-reported bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
backend bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
nolte/kamerplanter#3193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
soup prune-prompt exits 1 after writing its output on a file over 100,000 rows, and reports a capped row count otherwiseCó thể đã có người làm @abdulwaarith0 đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
MakazhanAlpamys/Soup#3690 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày