PowerShell MCP服务器
一个全面的模型上下文协议(MCP)服务器,使Claude和其他LLM应用程序能够在Windows系统上执行PowerShell命令、脚本和执行系统操作。
🌟 主要特点
- 🔧 PowerShell执行:执行命令、运行脚本和创建新的PowerShell文件
- 🖥️ 系统监控:获取系统信息、监视进程、检查服务和磁盘空间
- 📁 文件操作:列出目录,获取文件信息,并使用模式匹配搜索文件
- ⚙️ 简单设置:一个命令安装,带有自动Claude Desktop配置
- 🛡️ 安全:通过适当的错误处理和会话管理安全执行
🛠️ 可用工具
PowerShell工具
execute-powershell-使用可选工作目录执行PowerShell命令execute-powershell-script-运行带有参数的PowerShell脚本文件create-powershell-script-创建新的PowerShell脚本
系统工具
get-system-info-全面的Windows系统信息get-process-list-以CPU/内存使用率运行进程(可排序/可过滤)get-service-status-带筛选的Windows服务状态check-disk-space-所有或特定驱动器的磁盘空间使用情况
文件工具
list-directory-具有过滤功能的增强目录列表get-file-info-详细的文件和目录元数据search-files-带模式匹配的递归文件搜索
📋 先决条件
- 视窗 10/11或Windows Server 2016+
- Node.js 18.0.0或更高
- PowerShell 5.1+或PowerShell Core 7+
- 克劳德桌面 应用
🚀 快速设置
选项1:安全自动设置(推荐)
# Clone and setup with configuration management
git clone https://github.com/gunjanjp/powershell-mcp.git
cd powershell-mcp
complete-setup.bat选项2:配置恢复(如果您有现有设置)
# 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选项3:手动设置
# 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📖 使用示例
问克劳德:
- *“执行PowerShell:获取日期”*
- *“检查我的系统信息”*
- *“按CPU使用率显示前10个进程”*
- *“我的磁盘空间使用情况如何?”*
- *“列出我的下载文件夹中的文件”*
- *“在C:\\Users中搜索所有.txt文件”*
- *“创建PowerShell脚本以备份我的Documents文件夹”*
🔧 命令
服务器命令
# Start the server
npm start
# Test components
npm test
# Run diagnostics
node diagnose.bat
# Start server directly
node src/server.js配置管理
# 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
# Merge configurations
node recovery.js merge
# Show backup contents
node recovery.js show 快速设置命令
# Complete setup with safety checks
complete-setup.bat
# Test server only
run-test.bat📁 项目结构
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桌面配置
服务器使用此配置(由安装程序自动应用):
{
"mcpServers": {
"powershell": {
"command": "node",
"args": ["D:/claude/claude-powershell-mcp/src/server.js"],
"env": {}
}
}
}配置位置: %APPDATA%\Claude\claude_desktop_config.json
🛡️ 安全功能
- 安全执行:用途
-ExecutionPolicy Bypass和-NoProfile出于安全考虑 - 输入验证:所有输入均已Zod模式验证
- 会话管理:PowerShell会话在使用后已正确处理
- 错误处理:全面的错误处理可防止系统问题
- 日志记录:记录到stderr的所有操作(不干扰JSON-RPC)
🐛 故障排除
服务器无法启动
# Check Node.js version (need 18+)
node --version
# Check dependencies
npm install
# Test components
node test-server.jsClaude桌面集成问题
# Run setup again
setup.bat
# Check configuration
type "%APPDATA%\Claude\claude_desktop_config.json"
# Restart Claude Desktop completelyPowerShell执行问题
# Test PowerShell
powershell -Command "Get-Date"
# Check execution policy
Get-ExecutionPolicy
# Run diagnostics
node diagnose.bat🔄 最近更新(v1.1.2)
配置管理改进
- ✅ 安全配置管理 -不再覆盖现有配置
- ✅ 自动备份 -在任何配置更改之前创建备份
- ✅ 配置恢复 -查找和恢复以前配置的工具
- ✅ 合并功能 -多个MCP服务器配置的智能合并
- ✅ 交互式恢复 -逐步配置恢复过程
以前的修复程序(v1.1.1)
- ✅ 修复了Claude Desktop JSON解析错误 -已将console.log更改为console.error(stderr)
- ✅ 清理项目结构 -已删除冗余服务器文件
- ✅ 简化设置 -一个脚本设置过程
- ✅ 正确的错误处理 -增强的日志记录和错误管理
🤝 贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 进行更改和测试:
npm test - 承诺:
git commit -am 'Add feature' - 推:
git push origin feature-name - 提交拉取请求
📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🔗 链接
______________________________________________________________________
由以下材料制成❤️ Claude和PowerShell社区
⚠️ 重要:此工具提供对PowerShell命令的直接访问。负责任地使用并意识到安全影响。
