Skip to main content
Glama
gunjanjp

PowerShell MCP Server

by gunjanjp
README.md
# 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)
```bash
# 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)
```bash
# 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
```bash
# 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
```bash
# Start the server
npm start

# Test components
npm test

# Run diagnostics
node diagnose.bat

# Start server directly  
node src/server.js
```

### Configuration Management
```bash
# 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
```bash
# 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):

```json
{
  "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
```bash
# Check Node.js version (need 18+)
node --version

# Check dependencies
npm install

# Test components
node test-server.js
```

### Claude Desktop integration issues  
```bash
# Run setup again
setup.bat

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

# Restart Claude Desktop completely
```

### PowerShell execution issues
```bash
# 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](LICENSE) file for details.

## šŸ”— **Links**

- [GitHub Repository](https://github.com/gunjanjp/powershell-mcp)
- [Model Context Protocol](https://modelcontextprotocol.io/)
- [Claude Desktop](https://claude.ai/)

---

**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.

TDQS

A3.5/5.0

Scored across 10 tools

Disambiguation4/5

Tools are mostly distinct with clear purposes. Slight overlap between list-directory and search-files, but descriptions differentiate them. Other tools like check-disk-space and get-system-info are unique.

Naming Consistency5/5

All tool names follow a consistent verb-noun pattern with hyphens (e.g., check-disk-space, get-process-list). No mixing of styles or vague verbs.

Tool Count5/5

With 10 tools, the server is well-scoped. It covers core PowerShell administration tasks without being overcrowded or too sparse.

Completeness3/5

The surface covers basic system info and file operations but lacks update/delete for files, process management (start/stop), and service management (start/stop). These are notable gaps given the 'PowerShell' domain.

Maintenance

ActivityInactive
ResponsivenessNo issues