为什么需要
拦在调用前,而不是事后翻 Trace
Agent 接上 MCP 后,危险写、密钥外泄、越权读往往已经发生才被观测到。 Guardian 只做一件事:在 tools/call 真正执行前做策略决策。
策略 deny 或 require_approval;未批准前下游不执行。
redact 改写后再转发,审计里只留脱敏摘要。
每次决策写本地 SQLite,可用 CLI / MCP 工具回看。
操作步骤
一键安装
一条命令写入 Cursor / Codex MCP 配置与本机 Gateway。装完重启 IDE,列表出现 mcp-guardian 即可。
git clone https://github.com/Ailian0206/mcp-guardian.git cd mcp-guardian bash scripts/install.sh # 重启 Cursor / Codex → 使用 mcp-guardian
仅一边:bash scripts/install.sh --cursor 或 --codex。默认挂演示下游;接真实磁盘见下方「真实下游」。
日常怎么工作
装上就能用,审批留在对话里
Agent 正常调工具;allow / deny / redact 多数无感完成。
返回 approval_required(含 confirm_code)→ Agent 在对话里问你。
Agent 调用 guardian_decide;allow 必须带同一 confirm_code,然后继续或结束。
真实下游
不止 demo:官方 Filesystem MCP
默认 profile 是演示工具。要护真实目录时,用 filesystem 画像并强制 --workspace(禁止回退 cwd)。
pnpm build node packages/gateway/dist/cli.js install --cursor \ --profile filesystem --workspace /ABS/PATH/TO/DIR # 读放行;写/改/移 → 会话内 confirm_code + guardian_decide
边界
与 Trace 平台的差异
| 能力 | Langfuse / LangSmith | MCP Guardian |
|---|---|---|
| 时机 | 调用后观测 | 调用前拦截 |
| 你怎么用 | 打开观测站 | 装进 IDE,跟 Agent 对话即可 |
| 核心对象 | Trace / Span | Tool call / Policy / Approval / Audit |
常见问题
先扫这几条
要不要天天开网页?
不要。网页只做介绍、FAQ 与可选策略试跑。真正干活的是本机 Gateway。
危险操作怎么批?
在 Agent 对话里批:看 confirm_code → 同意后 Agent 调 guardian_decide。
和 Langfuse 什么关系?
互补:它们事后观测,Guardian 事前拦截。
下一步
五分钟跑通主路径
安装 → 在 IDE 里触发一次危险写 → 对话内批准。想先看懂四种动作,可在浏览器试跑。