Skip to main content
Glama

MandateGuard

CI MCP Registry License: MIT

面向自主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-mcp

MandateGuard 已发布在官方 MCP Registryio.github.ezequiellich44-cmd/mandateguard(版本 1.0.0,mcpb 包,活跃)。同步注册表的 MCP 客户端可以直接发现并安装它。该包附带相同的 stdio 服务器和 14 个工具接口。

公开的工具:set_scopeset_global_policyauthorizeinit_ledgerledger_statuscreate_mandate_signerissue_mandatecheck_mandateactivate_licenselicense_statusreset_state,以及 Pro 版专属的 revoke_mandatepersist_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

A
license - permissive license
-
quality - not tested
A
maintenance

Maintenance

Maintainers
Response time
0dRelease cycle
2Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    A
    maintenance
    Budget & 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
  • A
    license
    -
    quality
    C
    maintenance
    An MCP server that enforces runtime governance on AI agent actions — file access, command execution, delegation chains, and permission escalation.
    MIT
  • A
    license
    -
    quality
    B
    maintenance
    MCP 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

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

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/ezequiellich44-cmd/MandateGuard'

If you have feedback or need assistance with the MCP directory API, please join our Discord server