Skip to main content

A minimal, transparent PowerShell 7 MCP for Windows — one tool: run a command, get raw exit code / stdout / stderr back.

Project description

pwsh-exec

version license python platform PowerShell

A minimal, transparent PowerShell 7 MCP for Windows — one tool: run a command, get raw exit code / stdout / stderr back.

pwsh-exec is a minimal, transparent PowerShell 7 MCP server for Windows. It exposes a single tool, run_command, that runs a command in a fresh pwsh process and returns the raw exit_code, stdout, and stderr — nothing parsed, filtered, or reformatted.

  • One tool, three inputscommand, timeout (seconds), optional working_directory.
  • Transparent — exit code + stdout + stderr returned verbatim, errors and all.
  • Stateless — every call is a new process; no session state persists.
  • Bounded — 1–300 s timeout per call; on timeout the whole process tree is killed.
  • Windows-hardened — UTF-8 output on any locale, PATH read fresh from the registry, no stdin hangs.
  • Not for — persistent shells, admin-elevated tasks, or long-running / background jobs.

It gives any AI agent on Windows a real terminal: you send a command, you get back exactly what the terminal produced.

Status — stable & complete

Feature-complete and stable. One tool, a frozen v1.0.0 API, 38 passing tests, in daily use driving real agent work since April 2026 with no known bugs. Reproducible bugs get fixed; the scope stays intentionally small — it does one thing.

Requirements

  • Windows
  • PowerShell 7 (pwsh) on PATH — this is the modern cross-platform PowerShell, not the built-in Windows PowerShell 5.1 (powershell.exe). Install it via winget install Microsoft.PowerShell or from the official install guide.
  • uv — provides the uvx runner used below.

Install

No clone required — uvx fetches and runs it on demand. Register it with your MCP client (stdio transport):

Any MCP client

Use this as the server's launch command:

uvx pwsh-exec

Claude Desktop

Edit claude_desktop_config.json:

{
  "mcpServers": {
    "pwsh-exec": {
      "command": "cmd",
      "args": ["/c", "uvx", "pwsh-exec"]
    }
  }
}

The cmd /c wrapper is recommended on Claude Desktop: as an Electron app it has no console of its own, and launching a console program directly can leave child processes (pwsh → git and other external .exes) without a working console — flickering windows, lost stdout, PATH lookups failing. cmd.exe acquires the hidden console first and every child inherits it. This is the same pattern Desktop Commander and other Windows MCP servers use.

The tool: run_command

Parameter Type Required Description
command string yes The PowerShell command or script to run.
timeout integer yes Timeout in seconds (not milliseconds). 1–300.
working_directory string no Absolute path. Defaults to the resolved working directory (see Configuration).

The output is plain text: the exit code first, then labelled stdout and stderr sections (empty ones still show, so the two streams are never ambiguous), then a diagnostic footer with a timestamp and elapsed time.

For example, calling run_command with command: "git status" returns the raw git output, untouched:

exit_code: 0

stdout:
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   app.py

no changes added to commit (use "git add" and/or "git commit -a")

stderr:
(empty)

[2026-06-13 08:43:11 | 625ms]

Nothing is summarised or filtered. A non-zero exit code, a syntax error written to stderr, an empty result — all of it comes back as the terminal produced it. Output longer than 500 lines per stream is trimmed to the first and last 250 lines so it never floods the context window.

Why it's robust on Windows

Running a shell on Windows from a host process is full of small traps. pwsh-exec handles them so the agent doesn't have to:

  • UTF-8 on any locale — output encoding is forced to UTF-8 end to end, so text isn't mangled even on non-English Windows. It was hardened on zh-CN / GBK systems, where these encoding bugs bite hardest; the fix is universal.
  • Always-fresh PATH — User-scope environment variables are read from the registry on every call, so CLIs you installed after the host started are still found (and REG_EXPAND_SZ values like %USERPROFILE%\... are expanded correctly).
  • Clean process-tree kills — on timeout the whole tree is terminated (pwsh plus any children it spawned, e.g. node, python), leaving no orphans.
  • No stdin hangs — stdin is detached, so tools that probe it (git and other MSYS2 programs) don't deadlock.
  • Sane truncation — very long output is head+tail trimmed instead of blowing up the model's context.

What it's not for

The small scope is the design. pwsh-exec deliberately does not do:

  • Persistent sessions — each call is stateless; cd and variables don't carry over. Pass working_directory, or combine dependent steps into one command.
  • Admin-elevated tasks — it runs as the host user, with no elevation.
  • Long-running / background jobs — the hard cap is 300 s and calls are synchronous. Installers, large builds, dev servers, and watchers are out of scope.

Configuration

working_directory defaults to a resolved directory, chosen in this order (highest priority first):

  1. The working_directory argument passed on the call.
  2. The PWSH_EXEC_DEFAULT_DIR environment variable, if set.
  3. The built-in fallback: %TEMP%\pwsh-exec.

To change the default, set PWSH_EXEC_DEFAULT_DIR in your MCP client's config:

{
  "mcpServers": {
    "pwsh-exec": {
      "command": "cmd",
      "args": ["/c", "uvx", "pwsh-exec"],
      "env": { "PWSH_EXEC_DEFAULT_DIR": "D:\\scratch" }
    }
  }
}

An unset or blank value falls back to the built-in default. The default lives under %TEMP% (its own subfolder, so you can wipe it wholesale) rather than scattering files into the shared temp directory.

License

MIT © 2026 Jason26214

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwsh_exec-1.0.1.tar.gz (79.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pwsh_exec-1.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pwsh_exec-1.0.1.tar.gz.

File metadata

  • Download URL: pwsh_exec-1.0.1.tar.gz
  • Upload date:
  • Size: 79.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pwsh_exec-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dc788651c39fad262721257655634eebbb631106d3129368dc77023d308a9ca3
MD5 64fb669ed65ec7206aedc6a7c238d52f
BLAKE2b-256 9dbbe369f6fe4de8394b5d616281b4dacc67514546b42b402c1d9a01a1b0aa02

See more details on using hashes here.

File details

Details for the file pwsh_exec-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pwsh_exec-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pwsh_exec-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 903cd709f522159eeec73ae7ce8597d682517d8f18655a5c686f6e267bacee81
MD5 aed38950c14e9139bc4821ebcea94c3b
BLAKE2b-256 3711f8ebac46e030b978eb1959aba778f85d1cf6f13176790314e9956fef1601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page