powershell-mcp

This tool assists in creating automation scripts using PowerShell. Implemented in JavaScript, it provides features that allow users to easily generate PowerShell scripts. This enables developers to work more efficiently and reduces the likelihood of errors.

GitHub Stars

3

User Rating

Not Rated

Favorites

0

Views

23

Forks

1

Issues

0

README
PowerShell MCP Server

A comprehensive Model Context Protocol (MCP) server that enables Claude and other LLM applications to execute PowerShell commands, scripts, and perform system operations on Windows systems.

๐ŸŒŸ Key Features
  • ๐Ÿ”ง PowerShell Execution: Execute commands, run scripts, and create new PowerShell files
  • ๐Ÿ–ฅ๏ธ System Monitoring: Get system info, monitor processes, check services and disk space
  • ๐Ÿ“ File Operations: List directories, get file info, and search files with pattern matching
  • โš™๏ธ Simple Setup: One-command installation with automatic Claude Desktop configuration
  • ๐Ÿ›ก๏ธ Secure: Safe execution with proper error handling and session management
๐Ÿ› ๏ธ Available Tools
PowerShell Tools
  • execute-powershell - Execute PowerShell commands with optional working directory
  • execute-powershell-script - Run PowerShell script files with parameters
  • create-powershell-script - Create new PowerShell scripts
System Tools
  • get-system-info - Comprehensive Windows system information
  • get-process-list - Running processes with CPU/memory usage (sortable/filterable)
  • get-service-status - Windows services status with filtering
  • check-disk-space - Disk space usage for all or specific drives
File Tools
  • list-directory - Enhanced directory listing with filtering
  • get-file-info - Detailed file and directory metadata
  • search-files - Recursive file search with pattern matching
๐Ÿ“‹ Prerequisites
  • Windows 10/11 or Windows Server 2016+
  • Node.js 18.0.0 or higher
  • PowerShell 5.1+ or PowerShell Core 7+
  • Claude Desktop application
๐Ÿš€ Quick Setup
Option 1: Safe Automated Setup (Recommended)
# Clone and setup with configuration management
git clone https://github.com/gunjanjp/powershell-mcp.git
cd powershell-mcp
complete-setup.bat
Option 2: Configuration Recovery (If you had existing settings)
# If previous setup overwrote your existing configuration
node recovery.js status      # Check current state
node recovery.js scan        # Find backup configurations
node recovery.js restore 1   # Restore from backup
# OR
node recovery.js merge 1     # Merge backup with current config
Option 3: Manual Setup
# Clone the repository
git clone https://github.com/gunjanjp/powershell-mcp.git
cd powershell-mcp

# Install dependencies
npm install

# Safely add to existing configuration
node recovery.js add-powershell

# Restart Claude Desktop
๐Ÿ“– Usage Examples

Ask Claude:

  • "Execute PowerShell: Get-Date"
  • "Check my system information"
  • "Show me the top 10 processes by CPU usage"
  • "What's my disk space usage?"
  • "List files in my Downloads folder"
  • "Search for all .txt files in C:\Users"
  • "Create a PowerShell script to backup my Documents folder"
๐Ÿ”ง Commands
Server Commands
# Start the server
npm start

# Test components
npm test

# Run diagnostics
node diagnose.bat

# Start server directly  
node src/server.js
Configuration Management
# Check configuration status
node recovery.js status

# Find backup configurations
node recovery.js scan

# Safely add PowerShell server
node recovery.js add-powershell

# Restore from backup
node recovery.js restore <number>

# Merge configurations
node recovery.js merge <number>

# Show backup contents
node recovery.js show <number>
Quick Setup Commands
# Complete setup with safety checks
complete-setup.bat

# Test server only
run-test.bat
๐Ÿ“ Project Structure
powershell-mcp/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ server.js           # Main MCP server (with stderr logging fix)
โ”‚   โ”œโ”€โ”€ tools/              # Tool implementations
โ”‚   โ”‚   โ”œโ”€โ”€ powershell-tools.js
โ”‚   โ”‚   โ”œโ”€โ”€ system-tools.js
โ”‚   โ”‚   โ””โ”€โ”€ file-tools.js
โ”‚   โ””โ”€โ”€ utils/              # Utility modules
โ”‚       โ””โ”€โ”€ system-utils.js
โ”œโ”€โ”€ examples/               # Example PowerShell scripts
โ”œโ”€โ”€ scripts/               # Setup utilities
โ”œโ”€โ”€ test/                  # Test files
โ”œโ”€โ”€ claude_desktop_config.json  # Claude Desktop configuration
โ”œโ”€โ”€ setup.bat             # Automated setup script
โ”œโ”€โ”€ diagnose.bat          # Diagnostic tool
โ”œโ”€โ”€ test-server.js        # Component testing
โ””โ”€โ”€ README.md
โš™๏ธ Claude Desktop Configuration

The server uses this configuration (automatically applied by setup):

{
  "mcpServers": {
    "powershell": {
      "command": "node",
      "args": ["D:/claude/claude-powershell-mcp/src/server.js"],
      "env": {}
    }
  }
}

Config location: %APPDATA%\Claude\claude_desktop_config.json

๐Ÿ›ก๏ธ Security Features
  • Safe Execution: Uses -ExecutionPolicy Bypass and -NoProfile for security
  • Input Validation: All inputs validated with Zod schemas
  • Session Management: PowerShell sessions properly disposed after use
  • Error Handling: Comprehensive error handling prevents system issues
  • Logging: All operations logged to stderr (not interfering with JSON-RPC)
๐Ÿ› Troubleshooting
Server won't start
# Check Node.js version (need 18+)
node --version

# Check dependencies
npm install

# Test components
node test-server.js
Claude Desktop integration issues
# Run setup again
setup.bat

# Check configuration
type "%APPDATA%\Claude\claude_desktop_config.json"

# Restart Claude Desktop completely
PowerShell execution issues
# Test PowerShell
powershell -Command "Get-Date"

# Check execution policy
Get-ExecutionPolicy

# Run diagnostics
node diagnose.bat
๐Ÿ”„ Recent Updates (v1.1.2)
Configuration Management Improvements
  • โœ… Safe Configuration Management - No more overwriting existing configs
  • โœ… Automatic Backups - Creates backups before any configuration changes
  • โœ… Configuration Recovery - Tools to find and restore previous configurations
  • โœ… Merge Capability - Intelligent merging of multiple MCP server configs
  • โœ… Interactive Recovery - Step-by-step configuration recovery process
Previous Fixes (v1.1.1)
  • โœ… Fixed Claude Desktop JSON parsing error - Changed console.log to console.error (stderr)
  • โœ… Cleaned up project structure - Removed redundant server files
  • โœ… Simplified setup - One script setup process
  • โœ… Proper error handling - Enhanced logging and error management
๐Ÿค Contributing
  1. Fork the repository
  2. Create feature branch: git checkout -b feature-name
  3. Make changes and test: npm test
  4. Commit: git commit -am 'Add feature'
  5. Push: git push origin feature-name
  6. Submit pull request
๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ”— Links

Made with โค๏ธ for the Claude and PowerShell communities

โš ๏ธ Important: This tool provides direct access to PowerShell commands. Use responsibly and be aware of security implications.