Skip to main content
Glama

x402_enforce_spend_policy

Read-onlyIdempotent

Enforce x402 per-transaction and daily spend caps with exact integer fee math, payee/network allowlists, and nonce replay rejection before payment authorization.

Instructions

Deterministic SPEC_CLASS_09 spend-cap & integer fee-math gate (net_minor = amount_minor * (10000 - fee_bps) // 10000, strictly rejecting IEEE-754 floats and slippage_bps < 0). Enforces max_per_tx_minor, cumulative_spent_minor + amount_minor <= daily_cap_minor, allowed_payees, allowed_caip2_networks, and idempotency_nonce replay rejection (stateless batch or optional thread-safe SQLite WAL ledger).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "amount_minor": "<amount_minor>",
      "payee": "<payee>",
      "caip2_network": "<caip2_network>",
      "idempotency_nonce": "<idempotency_nonce>"
    },
    "name": "x402_enforce_spend_policy"
  }
}

Input Schema

NameRequiredDescriptionDefault
payeeYesDestination wallet or merchant recipient address.
fee_bpsNoProtocol/facilitator fee in integer basis points (`0..10000`).
day_bucketNoOptional UTC date bucket (`YYYY-MM-DD`) override for deterministic testing.
seen_noncesNoOptional stateless list of previously used idempotency nonces.
amount_minorYesExact positive integer payment amount in atomic/minor units (floats rejected).
slippage_bpsNoSlippage tolerance in integer basis points (`>= 0`; negative values rejected).
caip2_networkYesCAIP-2 chain identifier (e.g. `eip155:8453`, `stacks:1`).
allowed_payeesNoOptional allowlist of approved payee addresses.
ledger_db_pathNoOptional path to a local SQLite WAL spend ledger for atomic multi-process/thread replay protection.
daily_cap_minorNoDaily cumulative integer atomic cap (default `50000000`).
commit_to_ledgerNoWhen `ledger_db_path` is provided and policy passes, atomically record the spend row.
max_per_tx_minorNoPer-transaction integer atomic cap (defaults to `X402_DEFAULT_MAX_TX_USDC_ATOMIC` or `5000000`).
max_slippage_bpsNoMaximum allowed slippage basis points (default `100` = `1.00%`).
idempotency_nonceYesUnique payment authorization nonce or EIP-3009 `bytes32` nonce.
allowed_caip2_networksNoOptional allowlist of permitted CAIP-2 networks.
cumulative_spent_minorNoPrior integer atomic spend in the current UTC day bucket (default `0`).

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Adds real context beyond the annotations: it discloses that nonce replay protection can be stateless (batch via `seen_nonces`) or stateful (thread-safe SQLite WAL ledger) and that passing entries are atomically recorded when a ledger path is supplied. It also discloses strict rejection behavior for floats and negative slippage. The one nuance an agent might miss is that the optional ledger path means a local write occurs despite `readOnlyHint: true`, though that is opt-in and only local bookkeeping.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It is only two sentences with no filler, but it is dense to the point of being hard to scan: a mid-sentence formula and backtick-heavy identifiers precede the plain-language statement of what is enforced, and 'SPEC_CLASS_09' conveys nothing to an agent. Front-loading the gate's purpose before the arithmetic would improve parsing.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 16-parameter policy gate the description covers the rule logic well, but there is no output schema and the description does not say what a rejection looks like (pass/fail shape, reason codes, which constraint fired), which an agent needs to handle failures. The stateful-vs-stateless mode is covered, so the gap is mainly the response contract.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, so the baseline is 3, but the description adds the actual arithmetic relationship ('cumulative_spent_minor + amount_minor <= daily_cap_minor') and the integer fee formula, explaining how the cap, fee and slippage parameters combine rather than just what each one is. The opaque identifiers and defaults are left to the schema, which is fine.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: a 'spend-cap & integer fee-math gate' that enforces per-tx caps, daily cumulative caps, payee/network allowlists and nonce replay rejection, and it even gives the exact fee formula. That is far more specific than the sibling tools (unit conversion, header inspection, settlement verification), though it never explicitly names those alternatives and the 'SPEC_CLASS_09' token is opaque jargon.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is only implied: the 'gate' framing and the presence of `cumulative_spent_minor`, `seen_nonces` and `commit_to_ledger` suggest a pre-authorization check before settling a payment. There is no explicit when-to-use, when-not-to-use, or statement about which sibling (e.g. x402_convert_atomic_units for float/unit conversion) to pick instead.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.