Skip to content
πŸ’» 🧠 Code 1001 > ⚑ PowerShell Philosophy > MCP PowerShell Server > MCP PowerShell Server. README>

MCP PowerShell Server. README>

An MCP (Model Context Protocol) server for executing PowerShell scripts, supporting both HTTP and STDIO modes of operation.

Description

The MCP PowerShell Server allows AI assistants to execute PowerShell commands and scripts via the standardized MCP protocol. The server supports two modes of operation:

  • STDIO mode: For integration with gemini-cli and other local MCP clients.
  • HTTP mode: For web applications and network integration via a REST API.

Which mode to choose: HTTP or STDIO?

The choice between mcp-powershell-http.ps1 and mcp-powershell-stdio.ps1 depends on how and from where the client application will interact with the server.

  • mcp-powershell-http.ps1 (HTTP mode) works like a waiter in a restaurant. It takes orders (HTTP requests) from any client on the network, passes them to the “kitchen” (PowerShell), and returns the finished result (HTTP response).
  • mcp-powershell-stdio.ps1 (STDIO mode) works like a personal assistant in the kitchen. It receives tasks directly (via standard input stdin) from a managing process (e.g., gemini-cli) that launched it, and immediately returns the result (via standard output stdout).

When to use HTTP mode

You should choose HTTP if network communication is required.

  • Remote management: The client application is on a different computer.
  • Web integration: You need to call PowerShell scripts from a web application, admin panel, or via AJAX requests.
  • Microservice architecture: Other services on your network need to interact with PowerShell.
  • Simple testing: You want to use tools like curl, Postman, or Invoke-RestMethod to send commands.

In simple terms: choose HTTP if there is a network between the client and the server.

When to use STDIO mode

This mode is ideal for local and secure integration.

  • Primary scenario β€” Gemini CLI: The gemini-cli tool launches mcp-powershell-stdio.ps1 as a child process and communicates with it directly through standard input/output streams.
  • Integration with other local applications: Your program in Python, Node.js, or another language can start and manage the server without opening network ports.
  • Enhanced security: Since no network ports are opened, this method is more secure by default.

In simple terms: choose STDIO if the client and server are on the same machine, and the client launches the server itself.

Comparison Table

CharacteristicHTTP mode (mcp-powershell-http.ps1)STDIO mode (mcp-powershell-stdio.ps1)
Primary ScenarioNetwork communication, web APILocal integration with CLI tools
Communication TypeClient-server over the network (TCP/IP)Inter-process communication (IPC)
LocationClient and server can be on different machinesClient and server must be on the same machine
SecurityRequires attention (port access, firewall)More secure by default (no open ports)
Typical Clientscurl, Postman, web applications, remote scriptsgemini-cli, local wrapper applications

Features

  • βœ… Support for MCP protocol version 2024-11-05
  • βœ… Two modes of operation: STDIO and HTTP
  • βœ… Isolation of script execution in separate PowerShell processes
  • βœ… Configurable execution timeouts
  • βœ… Detailed logging of all operations
  • βœ… Handling of PowerShell errors and warnings
  • βœ… Support for script parameters
  • βœ… Configurable working directory
  • βœ… Automatic launchers for easy startup

System Requirements

  • PowerShell 7.0 or newer
  • Windows 10/11 or Windows Server 2019+
  • .NET 6.0 or newer

Project Structure

mcp-powershell-server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ clients/           # Client applications
β”‚   β”‚   β”œβ”€β”€ node/         # Node.js client
β”‚   β”‚   β”œβ”€β”€ powershell/   # PowerShell client
β”‚   β”‚   └── python/       # Python client
β”‚   └── servers/          # Server components
β”‚       β”œβ”€β”€ mcp-powershell-stdio.ps1   # STDIO version of the server
β”‚       β”œβ”€β”€ mcp-powershell-http.ps1    # HTTP version of the server
β”‚       β”œβ”€β”€ test-mcp.ps1               # Test server
β”‚       └── config.json                # Configuration file
β”œβ”€β”€ docs/                 # Documentation
β”œβ”€β”€ README.md            # This file
└── how-to-use.md        # Detailed user guide

Quick Start

STDIO mode (for gemini-cli)

  1. Start the server:
    powershell .\src\servers\mcp-powershell-stdio.ps1
  2. Test:
    powershell .\src\servers\test-mcp.ps1

HTTP mode

  1. Basic start:
    powershell .\src\servers\mcp-powershell-http.ps1
  2. With custom parameters:
    powershell .\src\servers\mcp-powershell-http.ps1 -Port 9090 -ServerHost "0.0.0.0"
  3. With a configuration file:
    powershell .\src\servers\mcp-powershell-http.ps1 -ConfigFile ".\src\servers\config.json"

Available MCP Tools

run-script

Executes a PowerShell script with specified parameters.

Parameters:

  • script (required) – PowerShell code to execute
  • parameters (optional) – Hashtable of parameters
  • workingDirectory (optional) – The working directory
  • timeoutSeconds (optional) – Execution timeout (1-3600 sec)

Example usage via MCP:

{
  "name": "run-script",
  "arguments": {
    "script": "Get-Process | Select-Object -First 5 | Format-Table",
    "workingDirectory": "C:\\",
    "timeoutSeconds": 30
  }
}

Configuration

The server supports configuration via the config.json file:

{
  "Port": 8090,
  "Host": "localhost",
  "MaxConcurrentRequests": 10,
  "TimeoutSeconds": 300,
  "AllowedPaths": [
    "C:\\Scripts\\",
    "C:\\Tools\\"
  ],
  "Security": {
    "EnableScriptValidation": true,
    "BlockDangerousCommands": true,
    "RestrictedCommands": [
      "Remove-Item",
      "Format-Volume",
      "Stop-Computer",
      "Restart-Computer"
    ]
  }
}

Security

  • Script execution occurs in isolated PowerShell processes
  • Support for a list of forbidden commands
  • Execution time limit
  • Logging of all executed commands
  • Ability to restrict accessible paths

Logging

  • STDIO mode: Logs are written to %TEMP%\mcp-powershell-server.log
  • HTTP mode: Logs are output to the console with color highlighting

Log levels: DEBUG, INFO, WARNING, ERROR

Integration with AI Assistants

Gemini CLI

gemini --mcp-config "path/to/mcp_servers.json" -m gemini-2.5-pro -p "Show the first 5 processes in the system"

Other MCP Clients

The server is compatible with all clients that support the MCP protocol 2024-11-05.

Troubleshooting

Common Problems

  1. Port is busy: Change the port in the configuration or stop the process using the port.
  2. Access rights: Running on privileged ports (<1024) requires administrator rights.
  3. Encoding: Ensure that PowerShell is configured for UTF-8.
  4. PowerShell version: Requires PowerShell 7+.

Diagnostics

Check the server logs to diagnose problems:

Get-Content "$env:TEMP\mcp-powershell-server.log" -Tail 20

Development and Extension

The server can be easily extended with new MCP tools. See how-to-use.md for detailed development instructions.

License

This project is distributed under the MIT License. See the LICENSE file for details.

Support

  • Create an Issue in the GitHub repository
  • Check the documentation in how-to-use.md
  • Review the usage examples

Versions

  • 1.0.0 – Initial version with support for STDIO and HTTP modes

Leave a Reply

Your email address will not be published. Required fields are marked *