Skip to content

Windows stdio resolves .ps1 then fails to spawn it #3496

Description

@sbguangha

Initial Checks

Release line

2.x (current stable)

Description

On Windows, get_windows_executable_command() already looks up .ps1 (alongside .cmd / .bat / .exe). The spawn path then passes that path to CreateProcess / anyio.open_process([command, *args]).

Windows cannot execute a .ps1 file directly. The lookup therefore advertises a working command that later fails with WinError 193 (not a valid Win32 application) or FileNotFoundError.

Expected: a command that resolves to something.ps1 is launched through PowerShell (powershell / pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -File <script> ...args).

Actual: the SDK finds the .ps1 and then cannot start it.

I hit this on Windows while starting a stdio MCP server whose command is a PowerShell script (or a bare name that shutil.which resolves to .ps1).

I used an LLM to help draft this report after reproducing the failure locally.

Example Code

import asyncio
from pathlib import Path
from mcp.client.stdio import StdioServerParameters, stdio_client

# On Windows, CreateProcess cannot run a .ps1 path returned by
# get_windows_executable_command().
params = StdioServerParameters(command=str(Path(rC:\path\to\server.ps1)))

async def main():
    async with stdio_client(params) as streams:
        print(streams)

asyncio.run(main())

Direct spawn of the same path also fails:

import subprocess
subprocess.Popen([rC:\path\to\echo-ok.ps1])  # WinError 193

Launching via PowerShell works:

subprocess.Popen(
    [powershell, -NoProfile, -NonInteractive, -ExecutionPolicy, Bypass, -File, rC:\path\to\echo-ok.ps1],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    creationflags=getattr(subprocess, CREATE_NO_WINDOW, 0),
)

Python & MCP Python SDK

Python 3.12 on Windows 10/11
MCP Python SDK 2.2.0 (modelcontextprotocol/python-sdk main as of this report)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions