Build a paid MCP server with x402 micropayments
Roman V's tutorial on Dev.to walks through building an MCP server that charges AI agents $0.01 per tool call in USDC using the x402 protocol and `mcp-billing-gateway`, with no API keys or subscriptions required.
Score breakdown
MCP server authors can use this pattern to monetize tools instantly — no payment infrastructure, API key management, or subscription logic needed, just drop `mcp-billing-gateway` in front of any existing server.
- 01The tutorial uses the x402 protocol, which revives HTTP's 402 Payment Required status code for machine-to-machine micropayments.
- 02Payments are made in USDC on the Base L2 network, settling in seconds with gas costs of fractions of a cent.
- 03The example MCP server charges $0.01 per tool call.
Roman V's tutorial on Dev.to demonstrates how to build an MCP server with per-call monetization using the `x402` protocol — a revival of HTTP's long-dormant 402 Payment Required status code. The payment flow works as follows: an agent sends a request, the server responds with a `402` and payment details, the agent pays in USDC on the Base network, then retries with a payment proof header. The `mcp-billing-gateway` reverse proxy sits in front of the actual MCP server, validating x402 claims, tracking usage per caller, and optionally splitting revenue — all transparently, so the upstream server contains zero billing logic.\n\nThe tutorial builds a financial data MCP server in TypeScript using `@modelcontextprotocol/sdk`, `express`, and `zod`. It exposes two tools — `get_stock_quote` (fetching price and daily change from Yahoo Finance) and `get_market_summary` (pulling S&P 500, Dow Jones, and NASDAQ data) — and uses `StreamableHTTPServerTransport` for session management. The server is priced at $0.01 per tool call. The three-component architecture (AI agent → `mcp-billing-gateway` → MCP server) is designed for agent-to-agent services where the "customer" is an AI agent with a crypto wallet rather than a human with a credit card.\n\nBase L2 is used for its fast settlement times and negligible gas fees, making sub-cent micropayments economically viable. The pattern is notable because it requires no API key issuance, no invoicing infrastructure, and no subscription management — the payment protocol handles access control entirely.
Key facts
- 01The tutorial uses the x402 protocol, which revives HTTP's 402 Payment Required status code for machine-to-machine micropayments.
- 02Payments are made in USDC on the Base L2 network, settling in seconds with gas costs of fractions of a cent.
- 03The example MCP server charges $0.01 per tool call.
- 04`mcp-billing-gateway` acts as a reverse proxy that validates payments, tracks usage, and splits revenue — the upstream MCP server contains no billing code.
- 05The server is built with TypeScript, `@modelcontextprotocol/sdk`, `express`, and `zod`.
- 06Two tools are implemented: `get_stock_quote` and `get_market_summary`, both sourcing data from Yahoo Finance.
- 07The model targets agent-to-agent services where the consumer is an AI agent with a crypto wallet, not a human with a credit card.