X402 Starter
FreeNot checkedEnables AI agents to pay-per-call for Cloudflare Worker APIs using USDC micropayments, with automatic MCP tool discovery and Bazaar listing.
About
Enables AI agents to pay-per-call for Cloudflare Worker APIs using USDC micropayments, with automatic MCP tool discovery and Bazaar listing.
README
Paywall your Cloudflare Worker for AI agents in 5 minutes.
Drop-in x402 starter. Agents pay per call in USDC — no signup, no API keys, no human in the loop. Comes with Coinbase x402 Bazaar discoverability and an MCP manifest pre-wired so Coinbase-connected agents can find your API automatically.
What you get out of the box
- A Cloudflare Worker that returns HTTP 402 Payment Required for paid routes until the caller settles a USDC micropayment
- Bazaar-discoverable routes (the non-obvious bit — without
discoverable: true+ schemas, even settled payments never list) - A
/mcpmanifest so MCP clients and Coinbase AgentKit auto-discover your tools - One example paid endpoint (
GET /api/echo) you replace with your real API - HTTPS-forced redirects, JSON-or-HTML root discovery, health check
5-minute quick start
git clone <this repo> my-paid-api
cd my-paid-api
npm install
npm run dev # paywall OFF by default — iterate locally
Hit http://localhost:8787/api/echo?msg=hi — you'll get a 200 with the echo. That's your free dev loop.
Flip the paywall on (testnet)
- Edit
wrangler.jsonc:"X402_ENABLED": "true", "X402_NETWORK": "base-sepolia", "PAY_TO": "0xYOUR_TESTNET_WALLET", "PRICE_PER_CALL": "$0.01" npm run deploy- Hit
/api/echo— you'll get HTTP 402 with the payment challenge.
base-sepolia uses the default public facilitator. No keys needed. This is the right setup for development and demos.
Flip to mainnet (real USDC)
- Get a Coinbase CDP Secret API key at portal.cdp.coinbase.com.
- Set the two secrets:
npx wrangler secret put CDP_API_KEY_ID # paste the key id when prompted npx wrangler secret put CDP_API_KEY_SECRET # paste the secret when prompted - Set
X402_NETWORKto"base"inwrangler.jsonc, setPAY_TOto your real Base wallet, and redeploy.
Without the CDP keys on mainnet, the 402 challenge still issues but payments cannot settle. Set both secrets before going live.
Adding your own paid endpoints
Two places to edit src/index.ts:
The handler — add a route under
/api/*:app.get("/api/wash", async (c) => { // your logic return c.json({ ... }); });The paywall config — add the same path to
routesinapplyPaywall()so it gets paywalled AND Bazaar-discoverable:"/api/wash": { price: env.PRICE_PER_CALL, network: env.X402_NETWORK, config: { discoverable: true, description: "Wash/sybil screen for any Base address", inputSchema: { queryParams: { address: { type: "string" } } }, outputSchema: { type: "object", properties: { sybil_score: { type: "number" } } }, }, },The MCP manifest — add a
tools[]entry with the samename/endpoint/price_usdso MCP clients see it.
That's it. The middleware path matcher (/api/*) catches everything under /api, so only step 1 is structurally required — but skipping steps 2 and 3 means agents won't find your endpoint, which is most of the value.
Going beyond echo
This template is intentionally minimal — one example endpoint, no business logic. The patterns it shows (Bazaar config, MCP manifest, free landing + JSON discovery, HTTPS forcing, lazy app build) are the load-bearing parts. Wire in your D1 / KV / Workers AI / Durable Objects as needed.
Pricing
x402-hono accepts dollar-formatted strings: "$0.01", "$0.05", "$1.00". Internally x402 settles in micro-USDC (six decimals), so "$0.01" becomes 10000 units. Different routes can charge different prices — set them per-route in the routes config.
License
MIT. Use it, fork it, ship it.
Installing X402 Starter
This server has no published package — it is built from source. Open the repository and follow its README.
▸ github.com/Viraltbh/x402-starterFAQ
Is X402 Starter MCP free?
Yes, X402 Starter MCP is free — one-click install via Unyly at no cost.
Does X402 Starter need an API key?
No, X402 Starter runs without API keys or environment variables.
Is X402 Starter hosted or self-hosted?
A hosted option is available: Unyly runs the server in the cloud, no local setup required.
How do I install X402 Starter in Claude Desktop, Claude Code or Cursor?
Open X402 Starter on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
Fetch
Web content fetching and conversion for efficient LLM usage.
AWS KB Retrieval
Retrieval from AWS Knowledge Base using Bedrock Agent Runtime.
by modelcontextprotocolSpring AI MCP Server
Provides auto-configuration for setting up an MCP server in Spring Boot applications.
llm-analysis-assistant
A very streamlined mcp client that supports calling and monitoring stdio/sse/streamableHttp, and can also view request responses through the /logs page. It also
by xuzexin-hzCompare X402 Starter with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All ai MCPs
