PowerShell MCP服务器

一个全面的模型上下文协议(MCP)服务器,使Claude和其他LLM应用程序能够在Windows系统上执行PowerShell命令、脚本和系统操作。

  • by MartinMiles
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Zont-Innovation/Custom-Sitecore-MCP-Server

使用说明

PowerShell MCP服务器

一个全面的模型上下文协议(MCP)服务器,使Claude和其他LLM应用程序能够在Windows系统上执行PowerShell命令、脚本和执行系统操作。

🛠️ 可用工具

PowerShell工具

  • sym-search-replace -在Sitecore环境中对内容执行搜索和替换操作 脚本

📋 先决条件

  • 视窗 10/11或Windows Server 2016+
  • Node.js 18.0.0或更高
  • PowerShell 5.1+或PowerShell Core 7+
  • 网站核心 启用SPE远程传输的环境

环境变量

在启动服务器之前,您必须在下面设置 .env 文件:

# PowerShell Script Path
DEFAULT_SEARCH_REPLACE_SCRIPT=c:\Projects\Symposium\Custom-Sitecore-MCP-Server\examples\SearchReplace-SitecoreContent.ps1

# Sitecore SPE Remoting Configuration
SITECORE_CONNECTION_URI=https://xmcloudcm.localhost/
SITECORE_USERNAME=sitecore\speremoting
SPE_REMOTING_SECRET=YOUR_SPE_REMOTING_SECRET

🚀 快速设置

# Clone the repository
git clone https://github.com/Zont-Innovation/Custom-Sitecore-MCP-Server.git
cd Custom-Sitecore-MCP-Server

# Install dependencies
npm install

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

# Restart your MCP client (ie. Claude Desktop)

📖 使用示例

问克劳德:

  • “将/SiteCore/content/Zont下的所有字段值‘SiteCore’替换为‘SiteCore’”
  • …您可能想要实现的任何其他工具

🔧 命令

服务器命令

# Start the server
npm start

# Test components
npm test

# Run diagnostics
node diagnose.bat

# Start server directly
node src/server.js

📁 项目结构

Custom-Sitecore-MCP-Server/
├── examples/               # Tool PowerShell script
├── src/
│   ├── server.js           # Main MCP server
│   ├── tools/              # Tool implementations
│   │   ├── sym-tools.js
│   └── utils/              # Utility modules
│       └── system-utils.js
├── scripts/                # Setup utilities
└── README.md

⚙️ Claude桌面配置

服务器使用此配置:

{
  "mcpServers": {
    "powershell": {
      "command": "node",
      "args": ["c:/Projects/Symposium/Custom-Sitecore-MCP-Server/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.js

Claude桌面集成问题

# Run setup again
setup.bat

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

# Restart Claude Desktop completely

PowerShell执行问题

# Test PowerShell
powershell -Command "Get-Date"

# Check execution policy
Get-ExecutionPolicy

# Run diagnostics
node diagnose.bat