安全命令执行服务

一个安全管理和执行系统命令的服务,提供安全检查、日志记录和命令管理功能。

  • by HappyAny
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 happyany/secure-command-executor-mcp-server

使用说明

安全命令执行器MCP服务器

一个强大的命令执行MCP服务,具有每日日志轮换功能,旨在通过安全检查和日志记录安全地管理和执行系统命令。这个README.md是由DeepSeek V3编写的。

特性

  • 命令执行:使用可选参数执行系统命令。
  • 安全检查:警告并要求确认危险命令。
  • 命令管理:添加、更新、删除、启用或禁用命令。
  • 日志记录:每日日志轮换,并进行详细的行动跟踪。
  • 查询工具:使用筛选器查询可用命令和日志。

安装

  1. 克隆存储库:

    git clone https://github.com/HappyAny/secure-command-executor-mcp-server.git
    cd secure-command-executor-mcp-server
    
  2. 安装依赖项:

    npm install minimist
    npm install @modelcontextprotocol/sdk
    npm install zod
    
  3. 配置服务:

    • 修改 commands.json 以定义可用命令。
    • 设置环境变量(可选)。

用法

启动服务

node index.js --file commands.json --logs logs --port 3000

MCP设置

{
    "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": "List directory contents",
    "example": "dir /w",
    "dangerous": false,
    "enabled": true,
    "confirmationPrompt": "",
    "consequences": ""
  },
  {
    "name": "format",
    "description": "Format disk drive",
    "example": "format C:",
    "dangerous": true,
    "enabled": false,
    "confirmationPrompt": "This will PERMANENTLY erase all data. Confirm?",
    "consequences": "Permanent data loss"
  }
]

API终点

执行命令

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": "Test network connection", "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.

贡献

欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您想要更改的内容。

许可证

麻省理工学院