
Agent Guardrail
io.github.rudimentall1由 GitHub 账号 rudimentall1 发布v1.0.2更新于 Oct 24, 2026
Deterministic policy firewall for AI agent tool calls - YAML rules, not a fuzzy risk score.
概览
本地 MCP 服务器,按 YAML 策略规则检查 AI 智能体的工具调用,返回放行、警告或阻止的判定。
- 可以做什么
- 按 YAML 策略检查拟执行的工具调用,返回判定、命中的规则和通俗原因,覆盖工具黑名单、参数正则、数值上限、域名规则和速率限制。记录动作的真实结果,使失败时临时计入的额度被退回。从 SQLite 审计日志查询某个智能体的历史调用。建议式 MCP 服务器只是多种接入方式之一;Python 装饰器和强制式 MCP 服务器变体可让检查无法绕过。
- 适用场景
- 当智能体可能执行不可逆操作(如 shell 命令、发邮件、HTTP 请求、删除文件、写数据库或转账),而你想要可审计的确定性规则而非风险评分时使用。最适合单台开发机或你自己掌控的自定义智能体循环。
- 运行要求
- 以本地 Python 进程运行,可从 guardrail-mcp 的 PyPI 包或代码仓库安装。需要一个策略 YAML 文件,通过 GUARDRAIL_POLICY 环境变量指定,或使用内置默认策略。无需账号或 API 密钥。速率限制和审计日志使用本地 SQLite 文件。
安装
在 SourceWeft 中
- 打开 控制台中的 Agent Guardrail,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Guardrail
Put a policy firewall between an AI agent and every irreversible action.
Your agent wants to run a shell command, send an email, or move money. Guardrail checks that request against rules you wrote, before it happens, and either lets it through, asks a human, or blocks it — with a plain- English reason every time.
60-second quickstart
Or pip install guardrail-mcp gives you a guardrail
command directly — same output, no repo checkout required (falls back to
the policy bundled in the package if you don't point --policy at your
own file):
That's it — no server, no account, no API key. policies/default.yaml is
the file that decided this; open it and change the numbers to match your
own rules.
Why this, not another "AI risk scoring" tool
Most "AI agent security" projects (including an earlier project of mine) lean on statistical risk scores computed from data nobody can actually verify at build time — wallet age, "reputation," contract "risk" — which either requires paid data feeds you don't have yet, or quietly becomes mock data pretending to be real. Fine for prototyping, dishonest to ship.
Guardrail only makes claims it can back up. Every check is a deterministic rule — a blocklist entry, a regex match, a numeric cap, a rate limit — evaluated against a policy file you write and can audit yourself, backed by a real, persistent audit log (SQLite) you can query. Nothing here pretends to know something it doesn't.
It's also not blockchain-specific. Shell execution, email, HTTP requests, file deletion, database writes, crypto transactions — same engine, same policy file, same rules.
Four ways to use it
1. CLI — for testing a policy by hand
Shown above. No setup, instant feedback while you write rules.
2. MCP server (mcp_server.py) — the easy on-ramp, advisory
Exposes guardrail_check, guardrail_record_outcome, and
guardrail_agent_history as MCP tools any MCP-compatible agent (Claude
Desktop, Claude Code, custom MCP clients) can call.
Then tell your agent (in its system prompt) to always call
guardrail_check before spending money, deleting data, messaging someone
externally, or running code.
Be clear-eyed about its limit: like any MCP tool, nothing stops the calling model from just not invoking it. This only helps if the agent is instructed to always check first — for a guarantee it can't skip, see #3.
3. guardrail.decorator.enforce — the real guarantee
Wraps the actual Python function that performs a tool's side effect. The check runs in your code, before that function executes — the model never gets a chance to call the real function directly.
Use this if you're building your own agent loop (LangChain, CrewAI, a
custom MCP host, a Slack bot with tool access). Run python3 examples/example_agent_usage.py to see it block a real function call.
4. guardrail.mcp_enforced_server.EnforcedGuardrailMCPServer — the real guarantee, over MCP
The MCP server in #2 above is honest about being advisory: the model
gets a guardrail_check tool, but nothing stops it from calling the
actual tool (exposed by some other MCP server, or by the model's own
direct access) without checking first, or checking one thing and doing
another. If the model talks to your infrastructure only over MCP - no
Python decorator possible - this is the same #3 guarantee for that case:
the operator registers real action executors (the code that holds real
credentials and performs the real side effect) as the only way the
model can invoke that action at all.
The model is given exactly one MCP tool named wallet.transfer - there
is no separate, unguarded way to move funds through this server. A BLOCK
decision means do_transfer never runs. Both this and enforce() share
one implementation of "check, maybe route WARN to a human, run only if
not blocked, report the real outcome back" (guardrail/enforcement.py) -
not two independently-maintained copies of the same guarantee.
Getting a human to actually confirm a WARN
on_warn is the hook — Guardrail ships two ready-made implementations:
Local web UI (guardrail/confirmation/web_ui.py) — a tiny built-in
server (stdlib only, no Flask) with Approve/Reject buttons. The wrapped
function blocks until someone clicks one, or times out (fails closed —
timeout means reject, not "allow by default").
Try it live: python3 examples/example_web_confirmation.py, then open
http://localhost:8787.
Terminal prompt (guardrail/confirmation/cli_ui.py) — for scripts and
local testing where a browser is overkill:
Neither is required — on_warn is just a function (decision) -> bool,
so a Slack message, a ticket, or anything else you already use works too.
Writing a policy
Policies are plain YAML — see policies/default.yaml for a real, working
starting point (11 confirmation-gated tools, 10 destructive-pattern
checks, numeric caps, domain rules, rate limits, all commented).
numeric_caps limits each tool independently — wallet.transfer capped
at 1000/day and wallet.approve capped at 1000/day separately means an
agent using both can still move 2000/day combined. aggregate_caps
closes that: every tool listed in the same group draws from one shared
running total, e.g.
Only confirmed spend counts toward the total: a BLOCKed request never
adds anything, and a request that's provisionally recorded (because its
own check passed) is refunded if the real action later turns out not to
have succeeded — engine.record_outcome(request_id, "error"), called
automatically by both enforce() and the enforced MCP server (they
share one implementation of this, guardrail/enforcement.py) when the
real executor raises, or when a WARN a human rejects results in a
BlockedActionError. Real enforcement of this therefore has the same
caveat as everything else that depends on record_outcome being called:
it works fully under enforce() and the enforced MCP server (see
below); under the advisory-only MCP server (#2 above), a
provisionally-recorded amount just stays recorded, since nothing ever
reports back whether the action actually happened. See
guardrail/storage/aggregate_spend.py's module docstring for the full
picture.
No code changes needed to adjust any of this — edit the YAML, restart the process (or the MCP server).
Running the tests
134 tests: rule evaluation, the full engine pipeline (real SQLite-backed
rate limiting, aggregate spend tracking, and audit persistence), the
enforce decorator and the enforced MCP server (both proving a BLOCK
genuinely prevents the real action from running, sharing one
implementation of that guarantee), the advisory MCP server's JSON-RPC
handling, the confirmation web UI over real HTTP requests against a
live server, and a dedicated suite that checks the shipped
policies/default.yaml — not just synthetic test policies — actually
catches what it claims to.
What's honestly still missing
- Single-process SQLite by default. Fine for one agent process; for multiple replicas sharing rate limits/audit history, point every process at the same file on shared storage, or swap in a real database (the storage classes are small and easy to re-target).
- Secrets/PII redaction in the audit log is on by default.
AuditLogredacts values whose key looks sensitive (password,api_key,authorization, ...) and a couple of high-confidence value shapes (PEM private key blocks, JWT-shaped strings) regardless of key name, recursing into nested dicts/lists - seeguardrail/storage/redaction.pyfor exactly what is and isn't caught, and why general-purpose entropy heuristics were deliberately left out (too many false positives on ordinary UUIDs/hashes). PassAuditLog(redact=False)to store arguments as-submitted, orextra_sensitive_keys={...}to redact additional field names specific to your tools. - The default policy is a reasonable starting point, not a complete
threat model. It catches well-known destructive shell/SQL patterns
and obvious credential formats — extend
argument_patternsfor whatever your agents actually touch. - The confirmation web UI has no auth. It binds to
127.0.0.1by design (not exposed on the network), but anyone with local access to that port can approve/reject. Fine for a single developer's machine; put it behind your own auth if multiple people share the host.
None of these are mocked or faked — they're just not built yet, and they're the honest next steps if you adopt this.
Publishing this / getting people to actually use it
See PUBLISHING.md for a concrete checklist: MCP directories to submit
to, what a listing needs, and what "done" looks like.
Related projects
Same author, same principle applied elsewhere:
- agentic-wallet-guardian-v3 - a security decision layer for AI agents transacting on-chain. MIT, 112 tests.
- x402-attest - cryptographically signed (Ed25519), independently verifiable attestations for agent-to-agent payment policy decisions. Early proof of concept.
- open-agent-attestation - vendor-neutral open spec (JWT+EdDSA) for signing agent policy decisions, verifiable by anyone. x402-attest above uses a custom format; this is the generalized version. Draft v0.1.
Project layout
来源:README.md,提交 9ecea96
工具
0版本历史
1- v1.0.2最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分