Pwsh Exec Mcp

io.github.Jason26214由 GitHub 账号 Jason26214 发布v1.0.1更新于 Oct 24, 2026

A minimal, transparent PowerShell 7 MCP for Windows — one tool: raw exit code, stdout, stderr.

概览

AI 生成的概览

一个精简的 Windows MCP 服务器,只提供一个工具,让助手运行 PowerShell 7 命令并取回原始退出码、标准输出和标准错误。

可以做什么
在新的 pwsh 进程中运行 PowerShell 命令或脚本,需提供以秒为单位的超时和可选的绝对工作目录,返回退出码以及带标签的 stdout 和 stderr 原文,并附时间戳和耗时页脚。每个输出流超过 500 行时只保留首尾各 250 行。每次调用都是无状态的,目录切换和变量不会在调用之间保留。
适用场景
适用于 Windows 上的助手需要真实终端执行一次性命令的场景,例如 git status、查看文件或运行短脚本,并且希望得到未经过滤的原始输出而非摘要结果。不适合持久 shell、需要管理员权限的任务,以及长时间运行或后台作业。
运行要求
Windows 系统,PATH 中需有 PowerShell 7(pwsh),而非系统自带的 Windows PowerShell 5.1。需要 uv 提供的 uvx 运行器,通过 stdio 启动该 PyPI 包。可选设置 PWSH_EXEC_DEFAULT_DIR 指定默认工作目录,否则回退到 %TEMP% 下的子目录。
安装前请注意
该工具以宿主用户身份执行任意 PowerShell 命令,助手运行的任何内容都可能读取、修改或删除文件并访问网络。它不提权运行,超时会终止整个进程树。命令是同步的且上限为 300 秒,长时间任务会被中断。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Pwsh Exec Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

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 inputs — command, 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:

bash
uvx pwsh-exec

Claude Desktop

Edit claude_desktop_config.json:

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

ParameterTypeRequiredDescription
commandstringyesThe PowerShell command or script to run.
timeoutintegeryesTimeout in seconds (not milliseconds). 1–300.
working_directorystringnoAbsolute 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 mainChanges 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:

json
{  "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

来源:README.md,提交 4cb68fd

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分