PowerShell MCP Server

by posidron

Integrations

  • Offers a Node.js-based server for executing PowerShell commands, with support for system information retrieval, module management, and script execution through Node.js runtime.

  • Enables interaction with PowerShell, providing tools for executing commands, retrieving system information, managing modules, getting command help, finding commands, and running scripts.

PowerShell MCP 服务器

用于与 PowerShell 交互的模型上下文协议服务器。此服务器提供用于执行 PowerShell 命令、检索系统信息、管理模块等的工具。

要求

  • Node.js 18+
  • PowerShell 5.1 或 PowerShell Core 7+

安装

  1. 安装依赖项:
    npm install
  2. 构建项目:
    npm run build

配置

对于克劳德桌面

编辑配置: $HOME/Library/Application\ Support/Claude/claude_desktop_config.json

添加到 mcpServers:

{ "mcpServers": { "mcp-powershell": { "command": "node", "args": [ "/absolute/path/to/mcp-powershell/dist/index.js" ] } } }

对于 VS Code

编辑配置: $HOME/Library/Application\ Support/Code/User/settings.json

添加到设置:

"mcp": { "servers": { "mcp-powershell": { "command": "node", "args": [ "/absolute/path/to/mcp-powershell/dist/index.js" ] } } }

对于 Cursor IDE

编辑配置: $HOME/.cursor/mcp.json

添加到 mcpServers:

{ "mcpServers": { "mcp-powershell": { "command": "node", "args": [ "/absolute/path/to/mcp-powershell/dist/index.js" ] } } }

可用工具

此 PowerShell MCP 服务器提供以下工具:

执行_ps

执行 PowerShell 命令并获取结果。

Parameters: - command (string): PowerShell command to execute

使用示例:

execute_ps(command: "Get-Process | Select-Object -First 5")

获取系统信息

检索详细的系统信息,包括操作系统详细信息、处理器、内存和 PowerShell 版本。

Parameters: None

使用示例:

get_system_info()

列表模块

列出所有已安装的 PowerShell 模块,包括名称、版本和类型等详细信息。

Parameters: None

使用示例:

list_modules()

获取命令帮助

获取特定 PowerShell 命令的详细帮助,包括语法、参数和示例。

Parameters: - command (string): PowerShell command to get help for

使用示例:

get_command_help(command: "Get-Process")

查找命令

按名称或模式搜索 PowerShell 命令。

Parameters: - search (string): Search term for PowerShell commands

使用示例:

find_commands(search: "Process")

运行脚本

运行带有可选参数的 PowerShell 脚本文件。

Parameters: - scriptPath (string): Path to the PowerShell script file - parameters (string, optional): Optional parameters to pass to the script

使用示例:

run_script(scriptPath: "/path/to/script.ps1", parameters: "-Name 'Test' -Value 123")

发展

要在开发模式下运行:

npm run dev

扩展服务器

要添加您自己的 PowerShell 工具:

  1. 编辑src/index.ts
  2. registerTools()方法中添加新工具
  3. 遵循现有的模式以实现一致的错误处理
  4. 使用npm run build进行构建

添加工具示例

// In the registerTools() method: this.server.tool( "my_ps_tool", { param1: z.string().describe("Description of parameter 1"), param2: z.number().optional().describe("Optional numeric parameter"), }, async ({ param1, param2 }) => { try { // Your PowerShell command const command = `Your-PowerShell-Command -Param1 "${param1}" ${param2 ? `-Param2 ${param2}` : ''}`; const { stdout, stderr } = await execAsync(`powershell -Command "${command.replace(/"/g, '\\"')}"`); if (stderr) { return { isError: true, content: [ { type: "text" as const, text: `Error in my_ps_tool: ${stderr}`, }, ], }; } return { content: [ { type: "text" as const, text: stdout, }, ], }; } catch (error) { return { isError: true, content: [ { type: "text" as const, text: `Error in my_ps_tool: ${(error as Error).message}`, }, ], }; } } );

安全注意事项

  • 该服务器直接在您的系统上执行 PowerShell 命令
  • 命令以与运行 MCP 服务器的进程相同的权限执行
  • 暴露破坏性操作时要小心
  • 考虑对敏感命令实施额外验证

故障排除

常见问题

  1. PowerShell 执行策略限制
    • 您可能需要调整 PowerShell 执行策略以允许脚本执行
    • 使用Set-ExecutionPolicy RemoteSigned -Scope CurrentUser允许本地脚本
  2. 未找到路径错误
    • 确保文件路径是绝对路径或相对于工作目录正确路径
    • 为您的操作系统使用适当的路径分隔符
  3. 未找到命令错误
    • 某些命令可能需要安装特定模块
    • 使用Install-Module ModuleName安装所需的模块

执照

麻省理工学院

You must be authenticated.

A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

local-only server

The server can only run on the client's local machine because it depends on local resources.

模型上下文协议服务器,使 AI 助手能够在 Windows 系统上执行 PowerShell 命令、检索系统信息、管理模块和运行脚本。

  1. 要求
    1. 安装
      1. 配置
        1. 对于克劳德桌面
        2. 对于 VS Code
        3. 对于 Cursor IDE
      2. 可用工具
        1. 执行_ps
        2. 获取系统信息
        3. 列表模块
        4. 获取命令帮助
        5. 查找命令
        6. 运行脚本
      3. 发展
        1. 扩展服务器
          1. 添加工具示例
        2. 安全注意事项
          1. 故障排除
            1. 常见问题
          2. 执照

            Related MCP Servers

            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that provides programmatic access to the Windows terminal, enabling AI models to interact with the Windows command line through standardized tools for writing commands, reading output, and sending control signals.
              Last updated -
              3
              JavaScript
              MIT License
            • A
              security
              F
              license
              A
              quality
              A Model Context Protocol server that allows secure execution of pre-approved commands, enabling AI assistants to safely interact with the user's system.
              Last updated -
              1
              3
              18
              JavaScript
            • -
              security
              F
              license
              -
              quality
              A Model Context Protocol server that enables AI assistants like Claude to perform Python development tasks through file operations, code analysis, project management, and safe code execution.
              Last updated -
              1
              Python
              • Linux
              • Apple
            • -
              security
              F
              license
              -
              quality
              A comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.
              Last updated -
              16
              TypeScript

            View all related MCP servers

            ID: fjhi52pfdt