Skip to main content
Glama
safe-runbook-mcp

safe-runbook-mcp

safe-runbook-mcp

一个基于策略门控的 MCP 服务器,用于运维 runbook。它允许 AI 检查并运行已知命令,而不会给它一个不受限制的 shell。

为什么存在

AI 代理对运维很有用,但把终端交给它是一个很大的信任决定。这个项目将有用的部分——可重复的诊断和维护——保留在一个小而可审查的边界内:

AI 客户端 → 检查计划 → 策略检查 → 可选的人工批准 → 精确命令

Related MCP server: govmcp

安全模型

  • Runbook 是版本控制的 JSON;AI 不能发明命令。

  • 默认情况下不执行。

  • 可执行文件必须被明确列入白名单。

  • 变量经过正则验证,并成为完整的进程参数。

  • 命令在 shell: false 下运行,并限制在 realpath 限定的工作区内。

  • 变更性和破坏性计划需要 MCP 之外生成的短期 HMAC 批准令牌。

  • 令牌绑定到 runbook 和精确的计划哈希,因此更改的输入会使它失效。

  • 进程有时间和输出限制;声明的秘密会被编辑。

MCP 工具注解也提供给客户端,而服务器端检查仍然是权威。

技术栈

TypeScript 7、Node.js 22、MCP TypeScript SDK v2、Zod 4、Vitest 4、Biome 2、Docker 和 GitHub Actions。该项目是开源的,没有付费 API 依赖。

快速开始

npm install
npm run cli -- list
npm run cli -- plan docker-service-status --var service=api
npm test

必须显式启用执行:

RUNBOOK_EXECUTION_ENABLED=true npm run cli -- run disk-usage

对于变更性 runbook,在 MCP 连接之外生成批准,并使用相同的变量进行批准和执行:

export RUNBOOK_EXECUTION_ENABLED=true
export RUNBOOK_APPROVAL_SECRET='replace-with-a-long-random-secret'

TOKEN=$(npm run --silent cli -- approve restart-compose-service --var service=api)
npm run cli -- run restart-compose-service --var service=api --approval "$TOKEN"

连接 MCP 客户端

先构建,然后将这个 stdio 服务器添加到兼容 MCP 的客户端。将路径替换为你机器上的绝对路径。

{
  "mcpServers": {
    "safe-runbooks": {
      "command": "node",
      "args": ["/absolute/path/safe-runbook-mcp/dist/server.js"],
      "env": {
        "RUNBOOK_DIRECTORY": "/absolute/path/safe-runbook-mcp/runbooks",
        "RUNBOOK_WORKSPACE": "/workspace/to/manage",
        "RUNBOOK_EXECUTION_ENABLED": "false"
      }
    }
  }
}

服务器暴露:

  • list_runbooks — 发现可用的 runbook 和风险级别。

  • inspect_runbook — 解析变量并返回精确的计划及其哈希。

  • execute_runbook — 在策略检查后执行已定义的计划。

  • runbook://catalog — 只读目录资源。

日志输出到 stderr,因为 stdout 保留给 MCP JSON-RPC 流量。

添加 runbook

在 runbooks/ 中创建一个 JSON 文件:

{
  "id": "service-status",
  "title": "Inspect a service",
  "description": "Read one Compose service state.",
  "risk": "diagnostic",
  "variables": {
    "service": {
      "description": "Compose service name",
      "pattern": "[a-zA-Z0-9][a-zA-Z0-9_-]{0,62}",
      "required": true
    }
  },
  "steps": [
    {
      "id": "status",
      "title": "Read status",
      "executable": "docker",
      "args": ["compose", "ps", "{{service}}"]
    }
  ]
}

选择 diagnostic、mutating 或 destructive。变量必须占据完整的参数,如 "{{service}}";字符串插值被有意拒绝。

Docker

docker build -t safe-runbook-mcp .
docker run --rm -i \
  -v "$PWD:/workspace:ro" \
  -e RUNBOOK_WORKSPACE=/workspace \
  -e RUNBOOK_DIRECTORY=/app/runbooks \
  safe-runbook-mcp

保持执行禁用,以实现只读挂载。如果 runbook 需要 Docker,在审查该信任边界后,只挂载所需的套接字或远程上下文。

开发

npm run check
npm run typecheck
npm test
npm run build

参见 CONTRIBUTING.md 了解分支工作流,以及 AGENTS.md 了解编码代理使用的仓库规则。

参考

许可证

MIT

Available Tools

3 tools
execute_runbookExecute an approved runbookA
Destructive

Execute only commands declared in a version-controlled runbook. Requires the global execution gate; mutating plans also require an out-of-band approval token.

Inputs: id (required), variables, approvalToken.

inspect_runbookInspect a resolved runbook planA
Read-onlyIdempotent

Validate variables and return the exact commands, plan hash, risk, and approval requirement without executing.

Inputs: id (required), variables.

list_runbooksList safe runbooksA
Read-onlyIdempotent

List version-controlled runbooks and their risk levels. Does not execute anything.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: inspect validates and previews, execute runs commands, and list enumerates available runbooks. There is no overlap or ambiguity between them.

    Naming Consistency5/5

    All three tool names follow a consistent verb_noun pattern: inspect, execute, and list all pair with 'runbook'. The naming is uniform and predictable.

    Tool Count4/5

    With only three tools, the server is lean but covers the essential operations for runbook management: discover, preview, and execute. It is slightly minimal but appropriate for a focused purpose.

    Completeness4/5

    The server provides the core lifecycle for runbooks: list, inspect, and execute. Missing are update/delete operations, but since runbooks are version-controlled externally, those may be intentionally out of scope. No critical gaps for safe execution.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to operate a simulated IT operations environment through policy-enforced, risk-tiered tool calls with human approval for risky writes, dry-run previews, rate limits, emergency lockdown, and tamper-evident auditing.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI assistants to safely interact with operations systems such as cloud inventory, runbooks, and ticketing while enforcing role-based access, JWT authentication, write confirmation, secret and PII redaction, rate limits, and audit logging.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to perform safe, auditable Kubernetes write actions such as scaling, restarting and rolling back Deployments through a plan → policy-check → approve → apply → audit flow, with server-side guards, single-use plans and scoped RBAC. Read-only planning and Prometheus SLO/alert tools support the same guarded workflow.
      Apache 2.0