PoshMCP
Expose explicitly whitelisted PowerShell commandlets as a MCP Tool
PowerShell MCP Server
A Model Context Protocol (MCP) server that exposes PowerShell cmdlets as tools for AI assistants like Claude or Github Copilot. Built with security in mind through explicit whitelisting of allowed cmdlets.
Overview
This MCP server dynamically loads PowerShell cmdlets from modules and scripts, automatically generating tool schemas from cmdlet documentation. Unlike traditional PowerShell remoting, this server uses a whitelist approach - only explicitly configured cmdlets are exposed, making it safer for AI interactions.
Key Features
- Declarative Configuration: Define available tools in a simple JSON config file
- Automatic Schema Generation: Uses PowerShell reflection to generate MCP tool schemas from cmdlet help documentation
- Security by Whitelisting: Only explicitly listed cmdlets are exposed as tools
- Dynamic Loading: Supports both PowerShell modules (.psm1) and script files (.ps1)
- Type Conversion: Automatically handles parameter type conversions (DateTime, switch parameters, etc.)
How It Works
- Configuration Loading: Reads
mcp-config.jsonto determine which cmdlets to expose - Module/Script Import: Loads specified PowerShell modules and dot-sources script files
- Schema Generation: Uses
Get-CommandandGet-Helpto introspect each cmdlet:- Extracts cmdlet synopsis as tool description
- Maps PowerShell parameter types to JSON schema types
- Identifies mandatory parameters from
[Parameter(Mandatory)]attributes - Generates camelCase parameter names for JSON (e.g.,
StartDate→startDate)
- Tool Invocation: When a tool is called, dynamically dispatches to the corresponding cmdlet with parameter mapping
Installation
From PowerShell Gallery (Recommended)
Install-Module -Name PoshMCP -Scope CurrentUser
From Source
- Clone or download this repository to your local machine
- Ensure PowerShell 7+ is installed (
pwsh)
Configuration
MCP Server Configuration
Add the following to your VS Code MCP configuration file (typically %APPDATA%\Code\User\mcp.json on Windows):
{
"servers": {
"posh-mcp": {
"type": "stdio",
"command": "pwsh",
"args": [
"-NoProfile",
"-NoLogo",
"-Command",
"Import-Module PoshMCP;",
"Start-PoshMcp -ConfigPath C:\\path\\to\\your\\mcp-config.json"
]
}
}
}
Tool Configuration
Edit mcp-config.json to define which cmdlets to expose:
{
"serverInfo": {
"name": "posh-mcp",
"version": "1.0.0"
},
"modules": [
{
"name": "ModuleName",
"path": "./MyModule.psm1",
"cmdlets": [
"Get-MyData",
"Set-MyConfig"
]
}
],
"scripts": [
{
"path": "./my-tools.ps1",
"cmdlets": [
"Get-CustomInfo",
"Invoke-CustomTask"
]
}
]
}
Configuration Structure:
-
serverInfo: Metadata about the MCP servername: Server name displayed to MCP clientsversion: Server version
-
modules: PowerShell modules to importname: Module name (informational)path: Relative or absolute path to the.psm1filecmdlets: Array of cmdlet names to expose as tools
-
scripts: PowerShell script files to dot-sourcepath: Relative or absolute path to the.ps1filecmdlets: Array of function names to expose as tools
Creating Custom Tools
Example: Creating a Custom Script
Create a script file (e.g., my-tools.ps1):
function Get-SystemUptime {
<#
.SYNOPSIS
Returns the system uptime information.
.DESCRIPTION
Gets how long the system has been running since last boot.
.EXAMPLE
Get-SystemUptime
Returns uptime information.
.OUTPUTS
Hashtable with uptime details.
#>
[CmdletBinding()]
param()
$os = Get-CimInstance Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
return @{
LastBootTime = $os.LastBootUpTime.ToString("o")
UptimeDays = $uptime.Days
UptimeHours = $uptime.Hours
UptimeMinutes = $uptime.Minutes
}
}
Add to mcp-config.json:
{
"scripts": [
{
"path": "./my-tools.ps1",
"cmdlets": [
"Get-SystemUptime"
]
}
]
}
The tool will automatically be exposed as getSystemUptime (camelCase) with schema generated from the comment-based help.
Documentation Best Practices
For best results, include complete comment-based help in your cmdlets:
function Get-MyData {
<#
.SYNOPSIS
Brief one-line description (becomes tool description)
.PARAMETER Name
Detailed parameter description (appears in tool schema)
.PARAMETER StartDate
Start date for filtering results
.EXAMPLE
Get-MyData -Name "Test" -StartDate "2025-01-01"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $false)]
[DateTime]$StartDate = (Get-Date).AddDays(-7)
)
# Your implementation
}
Security Considerations
Why This Is Safer
- Whitelist-Only: Only cmdlets explicitly listed in
mcp-config.jsonare accessible - No Dynamic Execution: The server doesn't execute arbitrary PowerShell commands
- Parameter Validation: All parameters go through PowerShell's native validation
- Isolated Scope: Each cmdlet runs in a controlled context
Related Servers
Withings
MCP server for Withings health data integration
Sherlock Domains
A server to buy and manage domains with Sherlock.
Weather MCP Server
Provides real-time weather alerts and detailed forecasts for US locations using the National Weather Service API.
maven-indexer-mcp
A Model Context Protocol (MCP) server that indexes your local Maven repository (~/.m2/repository) and Gradle cache ( ~/.gradle/caches/modules-2/files-2.1) to provide AI agents with tools to search for Java classes, method signatures, and source code.
mcp-atomictoolkit
An MCP-compatible server providing atomistic simulation capabilities through ASE, pymatgen, etc.
MCP-HA-Connect
A production-ready Model Context Protocol (MCP) server for Home Assistant integration with AI assistants like Claude.
Suppr-MCP (超能文献)
Suppr - AI-powered document translation and academic search service. Supports high-quality translation of PDF, DOCX, PPTX and other formats in 11 languages with optimized mathematical formula handling. Includes PubMed-integrated intelligent literature search for researchers. https://suppr.wilddata.cn/
Kite Trading
A server for performing trading operations using the Kite Connect API.
Video Still Capture MCP
An MCP server for accessing and controlling webcams using OpenCV.
MCP Weather Server
Provides real-time weather information and forecasts using the OpenWeatherMap API.