The agent economy has a discovery layer (MCP) and a payment layer (x402), but
almost nobody ships them on the same edge. This post builds an MCP server on
Cloudflare Workers where every paid tool call is an HTTP 402 that settles in
USDC. The result: eleven tools with per-call pricing, an operator tier for
rebalancing, and zero payment infrastructure beyond the Worker itself.
Start with Hono and the x402-hono middleware. Each paid tool is a GET mirror plus a
/resources/:toolPOST /mcp route. The mirror announces the
tool and its price; the MCP route runs the tool and returns the revenue receipt.
import { Hono } from "hono";
import { x402 } from "x402-hono";
const app = new Hono();
app.get("/resources/:tool", (c) => {
return c.json({ tool: c.req.param("tool"), priceUsdc: 0.01, 402: true });
});
app.post(
"/mcp",
x402({ verify: { clientId: "p31-capital-machine" } }),
async (c) => {
const { method, params } = await c.req.json();
if (method === "tools/list") return c.json({ tools: [/* ... */] });
if (method === "tools/call") return c.json({ result: runTool(params) });
}
);
Register discoverable:true and expose .well-known/mcp so any MCP client can
find the tool list without an API key. The 402 mirror also tells LLM agents the
exact price before they spend: an agent can decide a $0.01 look-up is cheap
and a $0.25 execution needs approval.
The server is an OAuth 2.1 / RFC 8707 resource server, so the payment itself is
the access grant. Public metadata lives at .well-known/mcp-pricing,
.well-known/oauth-authorization-server, and .well-known/llms.txt. No
fragile custom auth; just HTTP semantics agents already understand.
Live reference: https://p31-capital-machine-mcp.trimtab-signal.workers.dev
with health (free) and revenue.getSummary ($0.02) as the two easiest
tools to test first.
Top comments (0)