A2A x402 Guard MCP

Fail-closed x402 Base/Solana USDC payee-binding, integer atomic-unit & SQLite WAL replay guard

Documentation

a2a-x402-guard-mcp

a2a-x402-guard-mcp Architecture Banner

Official Anthropic MCP Registry .mcpb Bundle CI Status A2A v1.0.1 + x402 + AP2 MIT License

a2a-x402-guard-mcp (v1.0.0) is a zero-dependency (dependencies = [], 100% Python >= 3.10 stdlib) deterministic security guard for x402 HTTP 402 Micropayments, A2A AP2 (Agent Payments Protocol) Mandates, Integer Minor-Unit Spend Caps, and S4-REJECT-005-Safe A2A v1.0.1 agent-card.json Signing, packaged as a 1-click .mcpb desktop bundle (< 50ms cold boot).

Autonomous agents interacting with paid HTTP 402 endpoints or A2A AP2 merchants face five concrete failure modes: IEEE-754 floating-point rounding drift (0.1 + 0.2 != 0.3), rogue/spoofed ERC-20 or SPL token contracts in PAYMENT-REQUIRED challenges, EIP-3009 authorization replay or unbounded validBefore windows, tampered CartMandate line-item totals, and broken agent-card.json JWS signatures caused by placing "x402" at the ProtoJSON top level (S4-REJECT-005). a2a-x402-guard-mcp eliminates all five deterministically with zero external pip dependencies.


Core Engineering Capabilities

  • Multi-Chain CAIP-2 x402 Header Forensics: Parses and audits PAYMENT-REQUIRED, X-PAYMENT, and PAYMENT-SIGNATURE headers (JSON, base64, and base64url) across eip155:8453 (Base Mainnet USDC EIP-3009 TransferWithAuthorization), eip155:84532 (Base Sepolia USDC), solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp (Solana USDC & SOL), and stacks:1 (sBTC SIP-010).
  • SPEC_CLASS_09 100% Integer Minor-Unit Spend Gate: Strictly rejects float inputs and negative slippage (slippage_bps < 0), computes exact integer basis-point fees (net_minor = amount_minor * (10000 - fee_bps) // 10000), enforces max_per_tx_minor and daily_cap_minor, and blocks nonce replays via stateless sets or an atomic thread-safe SQLite WAL ledger (BEGIN IMMEDIATE).
  • Pure-Python AP2 IntentMandate & CartMandate Verifier: Verifies ISO-4217 and crypto minor-unit exponents (0 JPY/VND, 2 USD/EUR, 3 KWD, 6 USDC, 8 sBTC, 9 SOL, 18 WEI), line-item sum conservation, human_confirmation_threshold_minor, and pure-Python RFC 8032 Ed25519 + RFC 8785 JCS signatures.
  • S4-REJECT-005-Safe A2A v1.0.1 agent-card.json Scaffolder: Emits spec-compliant HTTP 402 PAYMENT-REQUIRED headers alongside an Ed25519-signed /.well-known/agent-card.json + /.well-known/jwks.json bundle that embeds x402 and AP2 metadata inside capabilities.extensions[] and skills[] so a2a-python, @a2a-js/sdk, and a2a-go ProtoJSON JWS verifiers agree bit-for-bit.
  • SPEC_CLASS_14 Settlement Webhook & DLP Guard: Verifies facilitator webhooks with constant-time hmac.compare_digest (HMAC-SHA256) or Ed25519, deduplicates idempotency_key, and automatically redacts accidental API keys, secrets, and payment card digits.

Quick Install

Option 1: 1-Click .mcpb Bundle (Claude Desktop)

Download a2a-x402-guard-mcp.mcpb from the v1.0.0 Release and open it in Claude Desktop (manifest_version: "0.3", zero pip install step).

Option 2: Zero-Install uvx Prebuilt Wheel CLI & MCP Server

# Works immediately with zero install (0 external dependencies)
uvx --from https://github.com/khoap1220-hue/a2a-x402-guard-mcp/releases/latest/download/a2a_x402_guard_mcp-1.0.0-py3-none-any.whl a2a-x402-guard-mcp selftest --json
claude mcp add a2a-x402-guard -- uvx --from https://github.com/khoap1220-hue/a2a-x402-guard-mcp/releases/latest/download/a2a_x402_guard_mcp-1.0.0-py3-none-any.whl a2a-x402-guard-mcp-server

Option 3: MCP Client Configuration (claude_desktop_config.json / Cursor / VS Code)

{
  "mcpServers": {
    "a2a-x402-guard": {
      "command": "a2a-x402-guard-mcp-server",
      "env": {
        "X402_DEFAULT_MAX_TX_USDC_ATOMIC": "5000000"
      }
    }
  }
}

6 Deterministic MCP Tools (readOnlyHint = True)

ToolPurpose & Enforced Invariants
x402_inspect_payment_headerAudits PAYMENT-REQUIRED, X-PAYMENT, and PAYMENT-SIGNATURE headers across Base, Base Sepolia, Solana, and Stacks; flags IEEE-754 floats, rogue token contracts, payee mismatches, expired validBefore, and future validAfter.
x402_enforce_spend_policyEnforces SPEC_CLASS_09 integer-only minor-unit math, fee_bps, slippage_bps >= 0, per-tx & daily spend ceilings, CAIP-2/payee allowlists, and stateless or SQLite WAL idempotency_nonce replay locking.
ap2_verify_cart_mandateVerifies A2A AP2 IntentMandate & CartMandate line-item integer sums, currency exponents (0/2/3/6/8/9/18), TTL expiry, human confirmation gates, and pure-Python RFC 8032 Ed25519 + RFC 8785 JCS signatures.
x402_scaffold_agent_card_extensionGenerates HTTP 402 PAYMENT-REQUIRED JSON/base64 headers and an S4-REJECT-005-compliant Ed25519-signed /.well-known/agent-card.json + /.well-known/jwks.json deployment bundle.
x402_convert_atomic_unitsExact Decimal string <-> integer minor/atomic unit converter (USD, EUR, VND, JPY, KWD, USDC, sBTC, SOL, WEI) with SUB_ATOMIC_DUST_REJECTED rounding protection.
x402_verify_settlement_webhookConstant-time hmac.compare_digest / Ed25519 webhook signature verifier with replay-window enforcement, idempotency_key deduplication, and SPEC_CLASS_14 DLP secret/PAN scrubbing.

Built-in Prompts & Reference Resources

  • Slash Prompts (3): audit-402-payment-challenge, verify-ap2-cart-mandate, add-x402-pricing-to-agent-card
  • Resources (2):
    • x402-guard://spec/caip2-assets-and-decimals — Canonical Base/Sepolia USDC, Solana USDC/SOL, Stacks sBTC asset descriptors & minor-unit exponents.
    • x402-guard://checklists/spec-class-09-payment-invariants — Production payment security invariants, linked to khoaphan.dev/a2a-iq/ and khoaphan.dev/webhooks/.

Engineering & Support Workflow (Transparent Written-First A2A Operation)

Maintained by Khoa Phan via an open, transparent A2A (AI-Orchestrated Senior Engineering) workflow:

  • 100% Written Asynchronous Communication: All bug reports, integration specifications, and custom security engagements operate strictly via written channels (GitHub Issues, Pull Requests, and written async briefs at khoaphan.dev/services/ — zero live meetings) backed by deterministic Code-First PoCs and automated pytest suites.
  • Interactive Benchmarks & Guides: Explore live A2A v1.0.1 conformance benchmarks at khoaphan.dev/a2a-iq/ and webhook hardening patterns at khoaphan.dev/webhooks/.

License

MIT © 2026 Khoa Phan.