MandateGuard
MandateGuard
面向自主AI代理的确定性、可审计支付策略。
MandateGuard 是一个前置执行强制层,位于代理与其工具/钱包之间。每一次涉及资金转移的工具调用,在执行之前都会经过一个纯确定性引擎的评估——预算、允许列表、拒绝列表、速率限制和签名授权。决策路径中绝不涉及LLM,这正是每个判定结果可复现、每笔账目条目可验证的关键所在。
它附带一个 MCP 服务器,任何代理(Claude、Cursor 或您自己的编排框架)都可以在几分钟内将其挂载为护栏。
为什么
2026 年代理经济现实:
OWASP LLM08——过度代理 是最主要的 LLM 应用风险之一。被赋予钱包的代理正在被掏空:关于代理商务的 SoK 记录了 超过 4000 万美元的真实损失(抽干攻击、记忆中毒、工具滥用)。
支付标准(Google AP2 的 Intent/Cart/Payment 授权,Coinbase x402,ERC-8004)定义了授权是什么——但都没有提供真正能在代理运行中拦截它的执行层。
Gartner:到 2026 年底,40% 的企业应用将嵌入代理。这些代理将移动资金。它们需要轨道。
市场空白:一个确定性(非 LLM)策略引擎 + 审计追踪 + MCP 分发。这就是本仓库。
Related MCP server: gov-mcp
功能
确定性引擎——相同的输入,相同的判定,始终如此。可通过重放进行审计,决策中不涉及模型采样。
按执行者划分的作用域——允许的工具、允许的目标、单次调用上限、货币、时间窗口内的调用次数限制。
全局防护——总预算上限、目标允许列表/拒绝列表。
签名授权(Ed25519)——短时效、绑定 nonce、由签发者签名的授权,采用 AP2 / x402 风格。代理无法自行扩大其作用域。
防篡改账本——每个决策都是追加写入且经过 SHA-256 链式哈希。任何编辑、重排或删除都会通过线性扫描被检测到。
MCP 服务器——作为护栏挂载;提供策略、授权、授权签发和账本健康检查等工具。
决策路径零依赖——
cryptography仅用于授权;核心规则仅依赖标准库运行。
安装
# from this repo (works today; also on the official MCP Registry)
git clone https://github.com/ezequiellich44-cmd/MandateGuard.git
cd MandateGuard
python -m pip install -e .
# or directly from the source:
python -m pip install "git+https://github.com/ezequiellich44-cmd/MandateGuard.git"注意:PyPI 上的
mandateguard正在等待 Trusted Publisher 设置;在此之前,仓库 URL 是规范的安装路径。MCP 包已上线官方 MCP Registry(io.github.ezequiellich44-cmd/mandateguard),因此支持 MCP 的客户端无需任何 Python 步骤即可安装。
快速开始
from mandateguard import Intent, Policy, PolicyEngine, Scope
policy = Policy(
scopes={
"wallet-agent": Scope(
tools=("pay",),
destinations=("0xGOOD",),
max_amount=1000, # per call
currency="usd",
max_calls_per_window=5,
)
},
global_max_amount=2000, # per actor
allowlist=("0xGOOD",),
denylist=("0xSCAM",),
)
engine = PolicyEngine(policy)
decision = engine.authorize(
Intent(tool="pay", destination="0xGOOD", amount=800, actor="wallet-agent")
)
print(decision.status) # DecisionStatus.APPROVED被拒绝的调用会以结构化的原因被阻止;状态(支出/速率)仅在批准时提交,因此重放是确定性的。
MCP 服务器
该包附带一个可安装的 MCP 服务器入口点:
python -m pip install -e ".[mcp]"
mandateguard-mcp # stdio server, ready for Claude/Cursor/harness对于 Claude Code:
claude mcp add mandateguard -- mandateguard-mcpMandateGuard 已发布在官方 MCP Registry:
io.github.ezequiellich44-cmd/mandateguard(版本 1.0.0,mcpb 包,活跃)。同步注册表的 MCP 客户端可以直接发现并安装它。该包附带相同的 stdio 服务器和 14 个工具接口。
公开的工具:set_scope、set_global_policy、authorize、init_ledger、
ledger_status、create_mandate_signer、issue_mandate、check_mandate、
activate_license、license_status、reset_state,以及 Pro 版专属的
revoke_mandate 和 persist_state,后者需要签名 Pro 许可证(USDT
购买——请参阅 购买部分)。
授权
from mandateguard import Mandate, MandateSigner, verify_mandate
issuer = MandateSigner()
m = Mandate(actor="wallet-agent", max_amount=500, currency="usd",
tools=("pay",), destinations=("0xGOOD",),
not_before="2026-01-01T00:00:00+00:00",
not_after="2099-01-01T00:00:00+00:00", nonce="abc", issuer="you")
sig = issuer.sign(m)
verify_mandate(issuer.public_key_bytes, m, sig) # True架构
有关决策流程和状态模型,请参阅 docs/ARCHITECTURE.md;有关其保护和不保护的内容,请参阅 docs/THREAT_MODEL.md;有关商业定位和上市工具包,请参阅 docs/LAUNCH.md。
Agent intent ──> authorize(intent) ──> PolicyEngine
│ scope? allowlist? denylist?
│ budget? rate limit? mandate?
▼
APPROVED / DENIED / REQUIRES_APPROVAL
│
▼
append-only SHA-256 ledger (audit)测试
python -m pytest -q许可证
MIT。请参阅 LICENSE。
This server cannot be deployed
Maintenance
Related MCP Connectors
Agent-native MCP for governed commerce, x402 payments, paid capabilities, and verifiable receipts.
Compliance MCP for AI agents: sanctions & KYT screening on 50+ chains, stablecoin-freeze, oracle.
Pre-spend firewall for AI agents. Approves, blocks, flags transactions against policy rules.
Zero-secret MCP gateway for AI agents: risk-scored, audited calls with human-in-the-loop approval.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceBudget & cost control for AI agents: hard per-agent spend caps, rate limits, idempotency, and human-in-the-loop approval — enforced before each LLM call, not after the invoice. One hosted MCP endpoint (no proxy or self-hosting), settled via x402 (USDC on Base).MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that enforces runtime governance on AI agent actions — file access, command execution, delegation chains, and permission escalation.MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that enables AI agents to propose USDC payments on the Soroban blockchain with deterministic policy enforcement and injection protection, while providing payment status and attestation tools.MIT
- FlicenseNot gradedqualityCmaintenanceAn MCP server that enables AI agents to safely interact with a double-entry payments ledger, enforcing idempotency, policy-based access control, and human-in-the-loop approval for high-value actions.-