PowerShell MCP Server

PowerShell MCP Server

A Model Context Protocol server that enables AI assistants to execute PowerShell commands, retrieve system information, manage modules, and run scripts on Windows systems.

Category
访问服务器

Tools

execute_ps

get_system_info

list_modules

find_commands

get_command_help

run_script

README

PowerShell MCP Server

A Model Context Protocol server for interacting with PowerShell. This server provides tools for executing PowerShell commands, retrieving system information, managing modules, and more.

Requirements

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

Installation

  1. Install dependencies:

    npm install
    
  2. Build the project:

    npm run build
    

Configuration

For Claude Desktop

Edit config: $HOME/Library/Application\ Support/Claude/claude_desktop_config.json

Add to mcpServers:

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

For VS Code

Edit config: $HOME/Library/Application\ Support/Code/User/settings.json

Add to settings:

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

For Cursor IDE

Edit config: $HOME/.cursor/mcp.json

Add to mcpServers:

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

Available Tools

This PowerShell MCP server provides the following tools:

execute_ps

Execute a PowerShell command and get the result.

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

Example usage:

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

get_system_info

Retrieve detailed system information, including OS details, processor, memory, and PowerShell version.

Parameters: None

Example usage:

get_system_info()

list_modules

List all installed PowerShell modules with details like name, version, and type.

Parameters: None

Example usage:

list_modules()

get_command_help

Get detailed help for a specific PowerShell command, including syntax, parameters, and examples.

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

Example usage:

get_command_help(command: "Get-Process")

find_commands

Search for PowerShell commands by name or pattern.

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

Example usage:

find_commands(search: "Process")

run_script

Run a PowerShell script file with optional parameters.

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

Example usage:

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

Development

To run in development mode:

npm run dev

Extending the Server

To add your own PowerShell tools:

  1. Edit src/index.ts
  2. Add new tools in the registerTools() method
  3. Follow the existing pattern for consistent error handling
  4. Build with npm run build

Adding a Tool Example

// 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}`,
          },
        ],
      };
    }
  }
);

Security Considerations

  • This server executes PowerShell commands directly on your system
  • Commands are executed with the same privileges as the process running the MCP server
  • Use caution when exposing destructive operations
  • Consider implementing additional validation for sensitive commands

Troubleshooting

Common Issues

  1. PowerShell execution policy restrictions

    • You may need to adjust your PowerShell execution policy to allow script execution
    • Use Set-ExecutionPolicy RemoteSigned -Scope CurrentUser to allow local scripts
  2. Path not found errors

    • Ensure file paths are absolute or properly relative to the working directory
    • Use appropriate path separators for your OS
  3. Command not found errors

    • Some commands may require specific modules to be installed
    • Use Install-Module ModuleName to install required modules

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选