PowerShell MCP 服务器

PowerShell MCP 服务器是一个基于 Python 的 Model Context Protocol (MCP) 服务器,用于自动化 Windows PowerShell 任务。它通过 JSON-RPC 接口提供程序化执行 PowerShell 脚本、剪贴板操作和终端输出捕获的功能。

  • by maithaen
  • 更新于
在 GitHub 查看 maithaen/pwsh-mcp

使用说明

基本能力

产品定位

PowerShell MCP 服务器是一个用于自动化 Windows PowerShell 任务的工具,特别适合需要程序化执行 PowerShell 脚本的场景。

核心功能

  • 执行 PowerShell 脚本:通过剪贴板在 Windows 终端中粘贴并运行 PowerShell 脚本。
  • 剪贴板访问:获取当前剪贴板的内容。
  • 终端截图:捕获 PowerShell 终端的输出为图像。

适用场景

  • 自动化 PowerShell 脚本执行
  • 程序化获取剪贴板内容
  • 捕获终端输出用于日志或调试

工具列表

  • execute_pwsh_script:通过粘贴到终端执行 PowerShell 脚本。
  • get_clipboard:获取当前剪贴板内容。
  • capture_pwsh_response:捕获 PowerShell 终端输出的截图。

使用教程

使用依赖

  • Windows 操作系统
  • Python 3.8+
  • 安装依赖包:
    pip install uv && uv sync && uv pip install -e .
    

安装教程

  1. 安装依赖包(如上所述)。
  2. 启动服务器:
    uv run powershell-mcp
    

调试方式

服务器通过 stdin/stdout 进行 JSON-RPC 通信。可以使用以下示例请求进行测试:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "execute_pwsh_script",
    "arguments": {
      "script": "Get-Process",
      "timeout": 30
    }
  }
}