PowerShell沙盒服务器

一个自托管的Model Context Protocol (MCP)服务器,为AI助手提供沙盒化的PowerShell环境。

  • by NopeNix
  • PowerShell
  • 本地部署
  • 更新于
在 GitHub 查看 NopeNix/PowerShell-MCP-Server

使用说明

PowerShell MCP服务器

一个自托管的模型上下文协议(MCP)服务器,为AI助手提供沙盒PowerShell环境。

🚀 快速开始

# Run the server (it will be available at http://localhost:8080)
docker run -d -p 8080:8080 --name mcp-server nopenix/powershell-mcp-server:latest

就是这样!您的服务器现在正在运行,并准备连接到AI工具。

💡 这是干什么用的?

此服务器提供 沙盒PowerShell环境 AI助手可以用来:

  • ✅ 在隔离环境中运行PowerShell命令
  • ✅ 通过成功/失败信息获得有组织的结果
  • ✅ 优雅地处理错误并清楚地报告
  • ✅ 以易于AI理解的格式查看命令输出
  • ✅ 学习PowerShell语法和功能

重要提示:这运行在一个 集装箱化、隔离的环境 -它不能直接访问主机系统的文件、进程或资源。它非常适合学习PowerShell、安全测试命令或在受控环境中运行PowerShell特定任务。

🏗️ 引擎盖下

此服务器构建于:

  • 基本图像:微软官方PowerShell Docker镜像(mcr.microsoft.com/powershell:latest)
  • Web框架: 可以 -用于REST API、网站和TCP/UDP服务器的跨平台PowerShell框架
  • 容器尺寸:轻量级(~400MB),下载速度快,资源使用量小
  • 隔离:默认情况下在没有主机文件系统访问权限的安全容器中运行

集装箱包括:

  • PowerShell 7+完整版。NET支持
  • 预安装的常见PowerShell模块
  • 用于HTTP处理的Pode web框架
  • 结构化JSON响应格式
  • 内置日志记录和错误处理
  • OpenAPI规范 在 /openapi.yaml API文件

🤖 连接到AI助手

OpenWebUI集成

  1. 确保您的PowerShell MCP服务器正在以下位置运行 http://localhost:8080
  2. 在OpenWebUI中,转到 管理设置→ 外部工具
  3. 点击 +添加服务器
  4. 集 类型 到 MCP(流式HTTP)
  5. 进入 服务器URL: http://localhost:8080
  6. 点击 保存 并在系统提示时重新启动OpenWebUI

现在,您可以要求OpenWebUI运行PowerShell命令!

VS代码继续集成

  1. 确保您的PowerShell MCP服务器正在以下位置运行 http://localhost:8080
  2. 在VS Code中,打开Continue扩展设置
  3. 将MCP服务器添加到您的配置中(具体步骤可能因Continue版本而异)

Claude桌面集成

  1. 确保您的PowerShell MCP服务器正在以下位置运行 http://localhost:8080
  2. 在Claude Desktop设置中,查找“工具”或“外部工具”
  3. 使用URL添加新的MCP工具: http://localhost:8080
  4. 保存并重新启动Claude

🔧 如何使用

连接后,您可以要求您的AI助手运行PowerShell命令,例如:

"Show me how to list files in PowerShell"
"Generate a random password using PowerShell"
"How do I work with JSON in PowerShell?"
"Show me PowerShell examples for string manipulation"
"What are the built-in PowerShell variables?"
"Help me understand PowerShell pipelines"
"What PowerShell commands are available for working with dates?"

由于这是一个沙盒环境,因此实验和学习是安全的!

🛡️ 安全与安保

✅ 沙盒环境:在隔离的容器中运行,保护您的主机系统 ✅ 安全实验:非常适合无风险学习PowerShell ✅ 受控访问:无法直接访问主机文件或进程 ✅ 清除日志记录:所有执行的命令都会记录下来以供查看

📝 日志记录

服务器提供全面的日志记录:

  • 请求日志记录:所有带有状态代码的HTTP请求
  • 错误记录:命令失败时的详细错误信息
  • 操作日志:显示正在发生的事情的清晰信息

要查看日志,请执行以下操作:

# View container logs
docker logs mcp-server

日志中的敏感信息会自动屏蔽。

🧪 测试您的设置

您可以测试您的服务器是否使用简单的curl命令:

# Test basic connectivity
curl http://localhost:8080/test

# Check available capabilities
curl http://localhost:8080/capabilities

# List available tools
curl http://localhost:8080/tools/list

# View OpenAPI specification
curl http://localhost:8080/openapi.yaml

# Run a simple command
curl -X POST http://localhost:8080/tools/runCommand \
  -H "Content-Type: application/json" \
  -d '{"command":"Get-Date"}'

🐳 替代部署

如果你更喜欢docker compose:

# Download the compose file
curl -O https://raw.githubusercontent.com/NopeNix/PowerShell-MCP-Server/main/docker-compose.yml

# Start the service
docker-compose up -d

使用docker compose查看日志:

docker-compose logs -f