Pay-per-use MCP tools with x402
Charge per tool call using crypto micropayments
HTTP 402 Payment Required has been in the spec since 1999, reserved for future use. 25 years later, Coinbase built x402: a protocol that finally gives it a purpose.
MCP tools can now charge per request using crypto micropayments. No subscriptions, no license keys, no accounts. Just pay and use.
Why crypto for payments
Traditional monetization requires setup. Users create accounts, enter payment methods, manage subscriptions. That friction makes sense for SaaS products, but not for API calls that cost fractions of a cent.
With x402, a client sends a signed payment, the server verifies it, the tool executes. No accounts, no payment processors, no recurring billing.
How x402 works
x402 implements HTTP 402 using USDC on Base. When a client calls a paid tool:
- The server responds with payment requirements
- The client signs a payment authorization
- The request continues with proof of payment
- Payment settles on-chain after execution
The payment requirements include everything the client needs to construct a valid payment:
The amount is in atomic units (6 decimals for USDC), so 50000 equals $0.05. The client signs an authorization, attaches it to the retry request, and the server verifies it with a facilitator before executing the tool.
No accounts. No API keys. No subscriptions. Just pay-per-use.
Enabling agentic commerce
It's not crazy to think that in the near future, agents will have their own wallets and budgets. They'll discover tools at runtime, decide if the price is worth it, and pay on the spot.
One agent needs a capability it doesn't have. It finds another that does, pays for the call, and moves on. No human approving each transaction. That future needs payment infrastructure that works at machine speed. x402 is a step in that direction.
How xmcp handles payments
We built an x402 plugin that handles all of this at the transport layer. You don't need to think about payment verification, signature validation, or settlement. Just wrap your tools.
That's it. The middleware intercepts requests, validates payments, and settles transactions. Your tool code stays clean.
Per-tool pricing
Not every tool costs the same. Some are simple lookups, others call expensive APIs or run heavy compute.
Tools without paid() stay free. Mix and match as needed.
Why stablecoins
Micropayments need stable value. Charging $0.01 for a tool call doesn't work if the currency swings 10% overnight. USDC is pegged to USD, so prices stay predictable for both sides.
Base keeps fees low enough that charging fractions of a cent makes sense. For testing, use base-sepolia. For production, use base.
Testing the integration
You can test your paid tools using the x402 AI Starter, a Next.js client that consumes paid tools.
- Clone the repo
- Sign into the Coinbase CDP portal
- Following
.env.example, set the following environment variables in.env.local:CDP_API_KEY_IDCDP_API_KEY_SECRETCDP_WALLET_SECRET
- Get an OIDC token by running
vc linkthenvc env pull. An API key can be obtained from the AI Gateway dashboard. - Connect your MCP server in
api/chat/route - Run
pnpm dev
The template runs on base-sepolia by default, so you can test with fake currency before going to production.
Looking forward
Micropayments don’t need new business models, they need fewer obstacles. Low-cost L2s removed the cost barrier, and x402 removes the integration barrier, making paid tools and agent-to-agent compensation easy to build and deploy.
If you're building MCP servers that charge per request, check out our monetization guide or join us on Discord.