x402 MCP Demo
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
x402 MCP tool demo — a real 402, a real rejection, and a real settlement
A minimal demo of the x402 payment protocol protecting an MCP-style
tool endpoint, run against the real x402==2.16.0 Python package and its default public
facilitator (https://x402.org/facilitator) on Base Sepolia testnet. Nothing here is
hand-written protocol JSON — every response in captured_responses/ came out of the
library, unedited.
Companion to: How to Charge for an MCP Tool: A Working x402 Endpoint in Under an Hour.
What's here
File | What it does |
| FastAPI endpoint ( |
| Generates two throwaway EOAs — a receiving address and a paying address. Zero funds, testnet only, never reuse these keys. |
| Acts as the paying agent: gets the real 402, signs a real payment payload with the zero-balance account, and shows the facilitator's real rejection |
| The three response bodies this produced, verbatim — the 402 demand, the insufficient-balance rejection, and the settled 200 |
Related MCP server: 402-mcp
Run it
pip install -r requirements.txt
python gen_wallets.py # writes wallets.json (gitignored) -- two fresh, empty keys
python server.py # starts on 127.0.0.1:8402
python client_probe.py # in a second terminalWhat you'll see
Round 1 — no payment. A 402 with a payment-required header (base64 JSON): scheme,
network, asset contract, amount in the token's smallest unit, and the address to pay.
Round 2 — a real signed payment, zero balance. The client builds and signs an actual
EIP-3009 authorization with the throwaway key, attaches it as X-PAYMENT, and the
facilitator checks it against the real Base Sepolia chain state. It comes back:
{ "error": "invalid_exact_evm_insufficient_balance" }That string is the facilitator's real error code, not a guess — it is what you get when the protocol works exactly as designed and the payer simply doesn't have the money.
Round 3 — funded, settled for real. The agent_address was funded with 20 testnet USDC
from Circle's public faucet, then client_probe.py was run
again against the same server. This time round 2 comes back 200:
{
"url": "https://example.com/mcp",
"recommendation": "expose as a priced x402 tool at $0.01/call",
"paid": true
}with a payment-response header that decodes to:
{ "success": true, "payer": "0x3214cB6C...E0E9", "transaction": "0x9530b663...0dd86", "network": "eip155:84532" }That transaction hash is real and independently verifiable —
view it on Base Sepolia Blockscout:
status ok, sent to the USDC contract, method transferWithAuthorization — the exact
EIP-3009 gasless-transfer pattern the payer signed. Anyone can check this without trusting
this README.
Why the manual round trip in client_probe.py
x402 2.16.0 ships PaymentRoundTripper, but it's a callback (handle_response(...)) meant
to be wired into a custom httpx/requests transport — it is not a drop-in transport by
itself, despite what the docstring implies. client_probe.py calls the same three
primitives it calls internally (get_payment_required_response →
create_payment_payload → encode_payment_signature_header) directly, which is fewer
moving parts for a demo and produces identical wire output.
Safety notes
gen_wallets.pycreates keys witheth_account.Account.create()— cryptographically random, never funded, never touching mainnet in this demo.wallets.jsonis gitignored.wallets.example.jsonshows the shape with a well-known burn address so the repo is runnable from a clean clone without secrets in git history.The facilitator URL, network, and asset contract are the library's own testnet defaults — nothing here talks to Base mainnet or moves real value.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
HTTP 402 and x402 billing for APIs and MCP servers. Agents pay your own wallet in USDC, 0% fee.
Pay-per-action access to APIs and MCP tools over Lightning L402 and Base USDC x402.
Monetize any MCP server: x402 paywall, pay-per-call billing in USDC on Base, agent marketplace.
Paid Account Abstraction API via x402. Unpaid tool calls return 402.
Related MCP Servers
- AlicenseBqualityDmaintenanceProduction-ready MCP server template for consuming X402-protected APIs with gasless micropayments. Enables AI agents like Claude to make micropayment-based API calls seamlessly using EIP-712 signatures and USDC transfers.3MIT
- AlicenseAqualityBmaintenanceL402 + x402 client MCP. AI agents discover, pay for, and consume any payment-gated API autonomously. Supports Lightning (NWC), Cashu ecash, stablecoins, and human-in-the-loop payments.14383 npmMIT
- AlicenseNot gradedqualityDmaintenanceMinimal MCP server demonstrating L402 pay-per-call with Depth-of-Identity reputation gating, providing a bitcoin data tool that fetches BTC price and mempool fees.MIT
- AlicenseAqualityDmaintenanceAn MCP server that lets your AI coding agent (Claude Code, OpenClaw, Codex, Cursor, etc.) discover and pay on-chain agents registered on ERC-8004, using Coinbase's official x402 protocol. No smart account. No bundler. No relay. Just your EOA, an HTTPS request, and an automatic 402 → sign → retry flow.36MIT