命令执行器 MCP 服务器
用于安全地执行预先批准的命令的模型上下文协议服务器。
🎥 演示
https://github.com/user-attachments/assets/ed763a12-b685-4e0b-b9a5-bc948a590f51
✨ 特点
使用预先批准的命令列表来确保命令执行的安全
通过环境变量配置允许的命令
使用 TypeScript 和 MCP SDK 构建
通过 stdio 进行通信,实现无缝集成
错误处理和安全验证
实时命令输出流
🚀 安装
安装依赖项:
构建服务器:
对于使用自动重建的开发:
⚙️ 配置
🔒 允许的命令
默认情况下,允许以下命令:
git
ls
mkdir
光盘
npm
NPX
Python
您可以通过设置ALLOWED_COMMANDS环境变量来自定义允许的命令:
🔌 Claude 桌面集成
要与 Claude Desktop 一起使用,请添加服务器配置:
在 MacOS 上:
在 Windows 上:
配置示例:
🛡️ 安全注意事项
命令执行器服务器实现了多项安全措施:
预先批准的命令列表
只能执行明确允许的命令
默认列表具有限制性且注重安全性
通过前缀验证命令以防止注入
命令验证
命令前缀验证可防止命令注入
无需执行任何 shell,安全性更高
环境变量已正确清理
错误处理
针对未经授权的命令的全面错误处理
清除错误信息以便调试
失败的命令不会导致服务器崩溃
环境隔离
服务器在其自己的环境中运行
环境变量可以控制
限制系统访问
💻 开发
📁 项目结构
🐛 调试
由于 MCP 服务器通过 stdio 进行通信,调试起来可能比较困难。我们建议使用MCP Inspector :
检查器将提供一个 URL 来访问浏览器中的调试工具。
🛠️ 工具 API
服务器提供一个单一工具:
执行命令
执行预先批准的命令。
参数:
command(字符串,必需):要执行的命令
示例请求:
响应示例:
错误响应:
❌错误处理
服务器针对各种场景提供了详细的错误消息:
未经授权的命令
{ "code": "InvalidParams", "message": "Command not allowed: [command]. Allowed commands: git, ls, mkdir, cd, npm, npx, python" }执行失败
{ "content": [ { "type": "text", "text": "Command execution failed: [error message]" } ], "isError": true }
🤝 贡献
分叉存储库
创建你的功能分支
提交你的更改
推送到分支
创建新的 Pull 请求
📄 许可证
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
模型上下文协议服务器允许安全执行预先批准的命令,使人工智能助手能够安全地与用户的系统交互。
Related Resources
Related MCP Servers
- -security-license-qualityA comprehensive Model Context Protocol server implementation that enables AI assistants to interact with file systems, databases, GitHub repositories, web resources, and system tools while maintaining security and control.Last updated -361
- Asecurity-licenseAqualityA secure Model Context Protocol server that allows AI models to safely interact with Windows command-line functionality, enabling controlled execution of system commands, project creation, and system information retrieval.Last updated -87MIT License
- -security-license-qualityA Model Context Protocol server that provides secure curl command execution capabilities, allowing AI assistants to make HTTP requests with configurable parameters and built-in security protections.Last updated -1
- Asecurity-licenseAqualityA Model Context Protocol server that enables AI assistants to communicate with each other using Inter-Process Communication, featuring natural language commands and cross-platform compatibility.Last updated -9107MIT License