mcp powershell
A Model Context Protocol server that enables AI assistants to execute PowerShell commands, retrieve system information, manage modules, and run scripts on Windows systems.
A Model Context Protocol server that enables AI assistants to execute PowerShell commands, retrieve system information, manage modules, and run scripts on Windows systems.
A Model Context Protocol server for interacting with PowerShell. This server provides tools for executing PowerShell commands, retrieving system information, managing modules, and more.
Install dependencies:
npm install
Build the project:
npm run build
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"
]
}
}
}
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"
]
}
}
}
Edit config: $HOME/.cursor/mcp.json
Add to mcpServers:
{
"mcpServers": {
"mcp-powershell": {
"command": "node",
"args": [
"/absolute/path/to/mcp-powershell/dist/index.js"
]
}
}
}
This PowerShell MCP server provides the following tools:
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")
Retrieve detailed system information, including OS details, processor, memory, and PowerShell version.
Parameters: None
Example usage:
get_system_info()
List all installed PowerShell modules with details like name, version, and type.
Parameters: None
Example usage:
list_modules()
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")
Search for PowerShell commands by name or pattern.
Parameters:
- search (string): Search term for PowerShell commands
Example usage:
find_commands(search: "Process")
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")
To run in development mode:
npm run dev
To add your own PowerShell tools:
src/index.ts
registerTools()
methodnpm 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}`,
},
],
};
}
}
);
Use Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
to allow local scripts
Path not found errors
Use appropriate path separators for your OS
Command not found errors
Install-Module ModuleName
to install required modulesMIT
[
{
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"command": {
"description": "PowerShell command to execute",
"type": "string"
}
},
"required": [
"command"
],
"type": "object"
},
"name": "execute_ps"
},
{
"annotations": {},
"inputSchema": {
"type": "object"
},
"name": "get_system_info"
},
{
"annotations": {},
"inputSchema": {
"type": "object"
},
"name": "list_modules"
},
{
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"command": {
"description": "PowerShell command to get help for",
"type": "string"
}
},
"required": [
"command"
],
"type": "object"
},
"name": "get_command_help"
},
{
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"search": {
"description": "Search term for PowerShell commands",
"type": "string"
}
},
"required": [
"search"
],
"type": "object"
},
"name": "find_commands"
},
{
"inputSchema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"parameters": {
"description": "Optional parameters to pass to the script",
"type": "string"
},
"scriptPath": {
"description": "Path to the PowerShell script file",
"type": "string"
}
},
"required": [
"scriptPath"
],
"type": "object"
},
"name": "run_script"
}
]