protect-mcp
protect-mcp
用于 MCP 服务器和 Claude Code 钩子的企业级安全网关。提供签名回执、Cedar 策略和支持集群的审计追踪。
已集成至 Microsoft Agent Governance Toolkit | IETF 互联网草案 | 在线演示: acta.today/wiki
快速入门 — Claude Code
两条命令。每个工具调用都会生成回执。
# 1. Generate hooks, keys, Cedar policy, and /verify-receipt skill
npx protect-mcp init-hooks
# 2. Start the hook server
npx protect-mcp serve在同一项目中打开 Claude Code。现在,每个工具调用都会被拦截、评估并签名。
init-hooks 创建的内容
文件 | 用途 |
| 钩子配置 (PreToolUse, PostToolUse, 以及 9 个生命周期事件) |
| Ed25519 签名密钥对 (自动被 git 忽略) |
| Cedar 策略入门示例 — 可根据需要自定义 |
| 包含签名和速率限制的 JSON 策略 |
| 用于 Claude Code 的 |
架构
Claude Code → POST /hook → protect-mcp (Cedar + sign) → response
↓
.protect-mcp-log.jsonl
.protect-mcp-receipts.jsonlPreToolUse: 同步 Cedar 策略检查 → 拒绝则阻止工具执行
PostToolUse: 异步回执签名 → 对延迟无影响
拒绝在架构上是最终决定 — 模型或其他钩子无法覆盖它
端点
方法 | 路径 | 描述 |
POST |
| Claude Code 钩子端点 |
GET |
| 服务器状态、策略信息、签名者信息 |
GET |
| 最近的签名回执 |
GET |
| 最新的回执 |
GET |
| 自动生成的 Cedar 策略修复建议 |
GET |
| 配置篡改检测警报 |
验证回执
# Inside Claude Code:
/verify-receipt
# From terminal:
curl http://127.0.0.1:9377/receipts/latest | jq .
npx protect-mcp receipts
# Check policy suggestions:
curl http://127.0.0.1:9377/suggestions | jq .Related MCP server: verify-mcp
快速入门 — MCP 服务器封装
将任何 stdio MCP 服务器封装为透明代理:
# Shadow mode — log every tool call, enforce nothing
npx protect-mcp -- node my-server.js
# Enforce mode with policy
npx protect-mcp --policy protect-mcp.json --enforce -- node my-server.js
# Generate keys + config template
npx protect-mcp init工作原理
protect-mcp 根据策略(JSON、Cedar 或外部 PDP)评估每个工具调用,将决策作为 Ed25519 回执进行签名,并记录结果。
两种集成模式:
模式 | 传输 | 使用场景 |
钩子服务器 | HTTP ( | Claude Code, 智能体集群 |
Stdio 代理 | stdin/stdout ( | Claude Desktop, Cursor, 任何 MCP 客户端 |
三种策略引擎:
引擎 | 配置 | 说明 |
JSON |
| 简单的工具级规则 |
Cedar |
| 通过 |
外部 PDP |
| OPA, Cerbos 或任何 HTTP PDP |
集群追踪
在多智能体对话中,protect-mcp 会自动追踪集群拓扑。
处理 11 个钩子事件:
事件 | 类型 | 描述 |
| 同步 | 工具执行前的 Cedar/策略评估 |
| 异步 | 工具执行后的回执签名 |
| 生命周期 | 工作智能体生成/完成 |
| 生命周期 | 协调器任务分配 |
| 生命周期 | 包含沙箱检测的会话生命周期 |
| 生命周期 | 智能体利用率监控 |
| 安全 |
|
| 生命周期 | 完成 + 策略建议摘要 |
每个回执包含:
swarm.agent_id,swarm.agent_type,swarm.team_nametiming.tool_duration_ms,timing.hook_latency_mspayload_digest(针对 >1KB 有效载荷的 SHA-256 哈希)deny_iteration(被拒绝后的重试次数)sandbox_state(启用/禁用/不可用)OpenTelemetry
otel_trace_id和otel_span_id
策略文件
{
"default_tier": "unknown",
"tools": {
"dangerous_tool": { "block": true },
"admin_tool": { "min_tier": "signed-known", "rate_limit": "5/hour" },
"read_tool": { "require": "any", "rate_limit": "100/hour" },
"*": { "rate_limit": "500/hour" }
},
"signing": {
"key_path": "./keys/gateway.json",
"issuer": "protect-mcp",
"enabled": true
}
}Cedar 策略
Cedar 的拒绝决定是权威的 — 无法被覆盖。
// Allow read-only tools
permit(
principal,
action == Action::"MCP::Tool::call",
resource == Tool::"Read"
);
// Block destructive tools
forbid(
principal,
action == Action::"MCP::Tool::call",
resource == Tool::"delete_file"
);当工具被拒绝时,protect-mcp 会通过 GET /suggestions 自动建议最小化的 Cedar permit() 规则。
基于 CVE 的策略包
每个策略都能预防真实攻击:
策略 | 事件 | OWASP |
| CVE-2025-6514: MCP OAuth 代理劫持 (437K 环境) | A01, A03 |
| 自主 Terraform 智能体销毁生产环境 | A05, A06 |
| 通过精心构造的 GitHub Issue 进行提示词注入 | A01, A02, A03 |
| 通过出站工具滥用窃取智能体数据 | A02, A04 |
| 未经授权的金融交易 | A05, A06 |
policies/cedar/ 中提供 Cedar 等效策略。
MCP 客户端配置
Claude Desktop
{
"mcpServers": {
"my-protected-server": {
"command": "npx",
"args": [
"-y", "protect-mcp",
"--policy", "/path/to/protect-mcp.json",
"--enforce",
"--", "node", "my-server.js"
]
}
}
}Cursor / VS Code
模式相同 — 将服务器命令替换为封装它的 protect-mcp。
CLI 命令
Commands:
serve Start HTTP hook server for Claude Code (port 9377)
init-hooks Generate Claude Code hook config + skill + sample Cedar policy
quickstart Zero-config onboarding: init + demo + show receipts
init Generate Ed25519 keypair + config template
demo Start a demo server wrapped with protect-mcp
doctor Check your setup: keys, policies, verifier, connectivity
trace <id> Visualize the receipt DAG from a given receipt_id
status Show tool call statistics from the decision log
digest Generate a human-readable summary of agent activity
receipts Show recent persisted signed receipts
bundle Export an offline-verifiable audit bundle
simulate Dry-run a policy against recorded tool calls
report Generate a compliance report from an audit bundle
Options:
--policy <path> Policy/config JSON file
--cedar <dir> Cedar policy directory
--enforce Enable enforcement mode (default: shadow)
--port <port> HTTP server port (default: 9377 for serve)
--verbose Enable debug logging决策日志
每个工具调用都会向 stderr 输出结构化的 JSON:
[PROTECT_MCP] {"v":2,"tool":"read_file","decision":"allow","reason_code":"cedar_allow","policy_digest":"a1b2c3...","mode":"enforce","hook_event":"PreToolUse","timing":{"hook_latency_ms":1},"otel_trace_id":"..."}当配置了签名时,签名的回执会被持久化到 .protect-mcp-receipts.jsonl。
审计包
npx protect-mcp bundle --output audit.json包含回执和签名密钥的自包含、可离线验证的包。使用 npx @veritasacta/verify 进行验证。
验证知识库 (acta.today/wiki)
protect-mcp 的回执签名功能支持了全球首个验证型多模型知识库 acta.today/wiki。
每个知识单元 (Knowledge Unit) 均由 4 个前沿模型在 3 轮对抗中审议产生,且每个模型响应都有 Ed25519 回执。当前模型列表:
模型 | 提供商 | 来源 |
Claude Opus 4.6 | Anthropic | 美国 |
GPT-5.4 | OpenAI | 美国 |
Grok 4.20 | xAI | 美国 |
Gemini 3.1 Pro | 美国 | |
DeepSeek V3.2 | DeepSeek | 中国 |
MiniMax M2.7 | MiniMax | 中国 |
Kimi K2.5 | Moonshot | 中国 |
Qwen 2.5 72B | Alibaba | 中国 |
每个 KU 均可独立验证:npx @veritasacta/verify receipt.json
生态集成
项目 | 星标 | 集成 | 状态 |
600+ | Cedar 策略桥接 + 回执签名 | 已合并 (PR #667) | |
3,700+ | 用于 MCP 审计流水线的 Ed25519 回执签名 | 已提交 PR #556 | |
— | 将签名回执作为证据来源 | 积极讨论中 (#1029) | |
24,500+ | 技能执行的加密审计追踪 | Issue #5041 | |
57,600+ | 持久化层的加密完整性 | 讨论 #1855 | |
1,500+ | MCP 配置建议 | PR #41 | |
1,400+ | 验证器结论的加密回执 | Issue #464 |
标准与知识产权
IETF 互联网草案:
draft-farley-acta-signed-receipts-01 — 机器对机器访问控制的签名决策回执
draft-farley-acta-knowledge-units-00 — 多模型审议的知识单元
专利状态:4 项澳大利亚临时专利申请中 (2025-2026),涵盖具有可配置披露的决策回执、工具调用网关、智能体清单和便携式身份
验证:Apache-2.0 —
npx @veritasacta/verify --self-testMicrosoft AGT 集成:PR #667 — 智能体治理工具包的 Cedar 策略桥接
相关仓库
仓库 | 描述 |
可争议公共记录的开放协议 (Apache-2.0) | |
IETF 互联网草案源文件 | |
集成示例:Claude Code 钩子、Express API、MCP 服务器签名 | |
离线回执验证器 (Apache-2.0) | |
智能体身份 SDK (Apache-2.0) | |
Google ADK 回执签名插件 (MIT, Python) |
贡献
欢迎提交 Issue 和 Pull Request。对于重大变更,请先开启一个 Issue。
Bug 报告:包含 protect-mcp 版本、Node.js 版本和复现步骤
Cedar 策略:通过 PR 将可重用策略分享到
policies/cedar/目录集成示例:添加到 ScopeBlind/examples
许可证
MIT — 可自由使用、修改、分发和构建,无任何限制。
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ScopeBlind/scopeblind-gateway'
If you have feedback or need assistance with the MCP directory API, please join our Discord server