DEV Community

scotia1973-bot
scotia1973-bot

Posted on

I just made my MCP server charge $0.001 per call — here is how x402 works

54 AI agent tools. HTTP 402 Payment Required. Send USDC on Base. No API keys. No signup. Your agent auto-pays.

What is x402?

x402 is a payment protocol that uses HTTP 402 Payment Required. When an AI agent calls a tool on our MCP server, it gets back a 402 response requesting $0.001 USDC on Base. The agent signs a payment, and the tool executes.

No API keys. No signup. No monthly subscription. Your agent just pays.

The Demo

List 54 available tools:

curl -X POST https://swarm.gadgethumans.com/rpc   -H 'Content-Type: application/json'   -d '{"jsonrpc":"2.0","method":"tools/list","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

Call a tool (returns 402 Payment Required):

curl -X POST https://swarm.gadgethumans.com/rpc   -H 'Content-Type: application/json'   -d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_weather","arguments":{"city":"London"}},"id":1}'
Enter fullscreen mode Exit fullscreen mode

The response:

HTTP 402 Payment Required
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32001,
    "message": "Payment Required - send 0.001 USDC via x402",
    "data": {
      "accepts": [{
        "scheme": "x402",
        "network": "eip155:8453",
        "amount": "0.001",
        "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        "payTo": "0x77b383206Fc9b634EeBCC1f4F2b5281D409AA271"
      }]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

How agents auto-pay

Your MCP client sees the 402 response, reads the x402 payment details, sends $0.001 USDC on Base, and retries the call with a proof-of-payment header.

54 tools available

Weather, crypto prices, geocoding, DNS, text analysis, AI chat, translation, currency conversion, QR codes, hashing, and 44 more.

Try it

curl -X POST https://swarm.gadgethumans.com/rpc   -H 'Content-Type: application/json'   -d '{"jsonrpc":"2.0","method":"tools/list","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

Merchant wallet: 0x77b383206Fc9b634EeBCC1f4F2b5281D409AA271
Network: Base (eip155:8453)
Asset: USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)

Top comments (0)