安全命令执行 MCP 服务器是一个功能强大的服务,可安全地管理和执行系统命令。它具备安全检查机制,能对危险命令发出警告,还支持详细的日志记录,且日志会进行每日轮转。此 README.md 文件由 DeepSeek V3 编写。
安全命令执行 MCP 服务器旨在安全地管理和执行系统命令。以下是快速上手的步骤:
git clone https://github.com/HappyAny/secure-command-executor-mcp-server.git
cd secure-command-executor-mcp-server
npm install minimist
npm install @modelcontextprotocol/sdk
npm install zod
commands.json 文件以定义可用命令。node index.js --file commands.json --logs logs --port 3000
git clone https://github.com/HappyAny/secure-command-executor-mcp-server.git
cd secure-command-executor-mcp-server
npm install minimist
npm install @modelcontextprotocol/sdk
npm install zod
commands.json 文件以定义可用命令。node index.js --file commands.json --logs logs --port 3000
{
"mcpServers": {
"cmd-exec": {
"command": "node",
"args": [
"path_to_file/index.js",
"--file",
"path_to_file/commands.json",
"--logs",
"path_to_dict/logs"
]
}
}
}
commands.json 文件定义了可用命令。示例:
[
{
"name": "dir",
"description": "列出目录内容",
"example": "dir /w",
"dangerous": false,
"enabled": true,
"confirmationPrompt": "",
"consequences": ""
},
{
"name": "format",
"description": "格式化磁盘分区",
"example": "format C:",
"dangerous": true,
"enabled": false,
"confirmationPrompt": "这将永久删除所有数据。确认?",
"consequences": "永久数据丢失"
}
]
curl -X POST http://localhost:3000/execute -H "Content-Type: application/json" -d '{"command": "dir", "args": "/w"}'
curl -X GET http://localhost:3000/queryCommands?filter=enabled&detailed=true
curl -X POST http://localhost:3000/manageCommand -H "Content-Type: application/json" -d '{"action": "add", "name": "ping", "description": "测试网络连接", "example": "ping example.com"}'
curl -X GET http://localhost:3000/queryLogs?limit=50&filter=failed
NODE_ENV:设置为 production 以启用生产模式。PORT:覆盖默认端口(3000)。--file:指定命令文件路径(默认:commands.json)。--logs:指定日志目录路径(默认:logs)。--port:指定服务运行的端口(默认:3000)。日志存储在指定目录中,每日轮转。每个日志文件名为 YYYY-MM-DD.json。
本项目采用 MIT 许可证。
欢迎提交拉取请求。对于重大更改,请先打开问题以讨论您想要更改的内容。