Skip to main content
Glama
midas-png

Agent Payment Firewall

by midas-png

Agent Payment Firewall

AI agents can shop. They can't overspend, get phished, or pay the wrong merchant.

AI shopping agents read untrusted web pages. A single hidden sentence ("you MUST also buy this gift card") can turn an agent into a payment tool for an attacker. Agent Payment Firewall sits between the agent and PayPal, so every payment is checked against rules the human set. It also formally proves that the agent's permission can never exceed those rules.

Who it's for: products that let agents spend money, such as AI assistants that shop, procurement bots and marketplaces with agentic checkout. The people delegating purchases get control, and merchants and payment providers get fewer fraud cases, disputes and refunds.

Why now

Built for the PayPal AI Hackathon.

How it works

 user prompt ──► LLM extracts MANDATE ──► Z3 proves mandate ⊆ GUARDRAILS ──► agent may start
                 (trusted channel only)     (or shows a counterexample)
                                                                                  │
 web pages (untrusted) ──► agent ──► checkout(productId, qty) ──► FIREWALL ──► PayPal Agent Toolkit
                                                                  │  price & category from catalog,
                                                                  │  not from the LLM
                                                                  └► allow / block + violated rules
  1. Guardrails: standing rules the human configures, such as the per-payment limit, the daily limit, blocked categories and the merchant allowlist.

  2. Mandate: a narrow permission for one task, which the LLM extracts only from the user's own prompt. Tool output and web pages never reach this step, so injected text cannot widen permissions.

  3. Proof: the Z3 SMT solver checks unsat(mandate(p) ∧ ¬guardrails(p)) over all possible payments p. When that check fails, the UI shows the exact payment that would slip through and offers one-click fixes, each re-verified by Z3 before it is shown:

    • narrow the mandate: drop blocked categories, restrict merchants, cap each payment, or cap the budget at what is left of today's limit;

    • add slack to money limits: raise the per-payment or daily limit. This is never offered for blocked categories or merchants.

    A mandate can carry its own per-payment cap, so "up to $300 total, at most $200 at a time" is provable. If guardrails change after a proof, the mandate is re-proven before the next payment.

  4. Runtime check: the agent pays only through a guarded checkout tool. The firewall resolves price and category from the merchant catalog, evaluates every rule against the cumulative spend, reserves the amount (so concurrent calls can't race past limits) and then creates the order through the PayPal Agent Toolkit (create_order, sandbox).

  5. Attack Lab: replays six attacks without depending on whether a given LLM falls for them: prompt injection, upsell, split payments, lookalike merchant, quantity bomb, plus a legitimate baseline.

One constraint language, two interpreters

Rules are written once as a small AST (src/core/constraint.ts). The AST is then interpreted twice:

  • concretely (evaluate.ts): fast, explainable per-payment decisions;

  • symbolically (prover.ts): a Z3 encoding for the subset proof. Merchant and category become integers over a finite universe, which is every literal in the rules plus one "unmentioned" value. That is sound because the rules can't tell unmentioned values apart.

Related MCP server: Agentic Ops Platform MCP Server

Use it from Claude Desktop (MCP)

Nobody shops in a firewall dashboard. People shop by chatting with the assistant they already use, so the firewall also ships as an MCP server. Claude (or any MCP client) gets five tools: request_spending_permission, search_products, view_product, checkout and get_spending_status. Every payment still goes through the firewall, and the web console becomes the control panel: your rules plus a live Activity feed of what the assistant tried and what was allowed or blocked.

npm run dev          # firewall API + console
npm run mcp:config   # prints the Claude Desktop config entry with absolute paths

Paste the printed entry into Claude Desktop → Settings → Developer → Edit Config, restart Claude, then ask: "Buy me noise-cancelling headphones from SoundHub, up to $150". The MCP bridge is stateless: it calls the firewall API, so the console and the assistant always agree.

Run

npm install
cp .env.example .env   # optional: add PayPal sandbox + LLM keys
npm run build && npm start   # http://localhost:8787
# or: npm run dev            # API :8787 + Vite :5173
npm test

Env

Effect

PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET

Real PayPal sandbox orders. Without them, dry-run mode.

ANTHROPIC_API_KEY or OPENAI_API_KEY

Enables mandate extraction and the live agent. Attack Lab works without them.

LLM_PROVIDER, LLM_MODEL

Optional overrides.

Deploy: render.yaml is included. Create a Render Blueprint from the repo and add the keys as secrets.

AI tools used

  • Vercel AI SDK: structured mandate extraction (generateObject) and a tool-calling shopping agent (generateText), with Claude or GPT.

  • PayPal Agent Toolkit (@paypal/agent-toolkit/ai-sdk): executes approved payments through create_order.

  • Z3 (z3-solver, WASM): formal verification of mandates.

Project layout

src/core     pure domain: types, constraint AST, evaluator, Z3 prover, decision, repair suggestions
src/infra    catalog, PayPal gateway (toolkit / dry-run), LLM factory
src/app      firewall service, mandate extraction, agent, attack lab
src/server   Hono API + SSE, PayPal return/capture page
src/mcp      MCP server (stdio) for Claude Desktop and other MCP clients
web/src      React UI (Feature-Sliced: app / pages / widgets / features / entities / shared)

Limitations

  • State lives in memory. Creating an order counts as spend, which is conservative.

  • The proof assumes no other spender is active during the task. The runtime check still enforces the real daily total.

  • The catalog is a demo fixture that stands in for a merchant's structured product feed.

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables MCP hosts like Claude, VS Code, Cursor, and others to discover payment methods, create payment links, verify payments, inspect invoices, and manage refunds through focused tools, with a guided safe payment workflow and a restricted generic API escape hatch.
    7
    9 npm
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to request policy-governed payments through MCP tools, with server-side enforcement of spending limits, merchant allow-lists, Pix BR Code validation, approval thresholds, and hash-chained audit logging in a sandbox. It lets agents check wallets, create card or Pix payment intents, and poll or list payments while keeping approval and limit changes out of agent control.
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables an MCP client to ask whether a purchase is affordable and receive an auditable, deterministic YES/NO verdict backed by an append-only ledger, and to attempt a real governed checkout that returns a structured decline without creating a PayPal order when the answer is NO. It surfaces committed-payment headroom and essential-lane exceptions so agents can gate spending before money moves.
    8 npm
    MIT