Quickstart
Add usage billing to your tool in 3 lines of code. Demo mode is the default — no signup, no card, no env vars required.
1 · Install
npm install @lemon-cake/mcp-sdk # or pnpm / yarn / bun — works with all of them
MIT licensed, ~12kB gzipped, zero runtime dependencies. Source at github.com/evidai/agent-payment-mcp.
2 · Wrap your tool
Import the SDK, create a client, wrap each tool handler with lc.charge(). That's the entire integration.
import { createLemonCakeSDK } from "@lemon-cake/mcp-sdk";
const lc = createLemonCakeSDK(); // demo mode without env vars
server.tool(
"search",
lc.charge({ price: 0.02 }), // ← the one line you add
async ({ query }) => {
return await myActualSearch(query);
},
);The wrapper handles: pre-flight budget check, charge recording, idempotency, and error formatting. If the buyer's budget is exhausted, the handler never runs — no compute wasted on uncollectable calls.
3 · Run it
$ node server.js [lemoncake] demo mode — charges logged to stderr, no real USDC [lemoncake] search $0.02 [lemoncake] summarize $0.05 [lemoncake] → set LEMONCAKE_SELLER_KEY to go live
That's it. The server is now metering every call. Demo mode is local-only — no telemetry leaves your machine.
4 · Go live (when ready)
- Grab a seller key at /start/free (3 fields, no card, manual provisioning within 24h while inbound is small).
- Export the key as an env var:
export LEMONCAKE_SELLER_KEY="lc_seller_..."
- Restart your server. The SDK auto-detects the key and switches to live mode. Real charges, paid out as USDC on Base.
Complete working example
A full runnable MCP server with 2 paid tools lives at examples/mcp-monetization-starter:
git clone https://github.com/evidai/agent-payment-mcp cd agent-payment-mcp/examples/mcp-monetization-starter npm install && npm start # → boots a working MCP server with billing in demo mode
Not an MCP server? HTTP works too
For regular HTTP APIs (Express, Hono, Next.js Route Handlers, Cloudflare Workers, etc.), use @lemon-cake/x402-server:
import { paymentMiddleware } from "@lemon-cake/x402-server";
app.use("/api/search", paymentMiddleware({ pricePerCallUsdc: 0.02 }));
app.get("/api/search", async (req, res) => {
return res.json(await myActualSearch(req.query.q));
});x402-compatible — any agent that speaks the x402 protocol (Coinbase Bazaar, AWS Bedrock AgentCore, Anthropic Connectors) can pay your endpoint directly.
What to read next
- Pricing — free tier limits, Pro tier rates, Enterprise terms
- ERC-2612 permit primer — how the on-chain hard cap actually works (only matters if you care)
- x402 hybrid mode — auto-listing on Coinbase Bazaar + AgentCore directories
- Migrating from Coinbase x402 — drop-in middleware swap
- Coexisting with Stripe MPP — when to route which way
SDK source · MIT · github.com/evidai/agent-payment-mcp · Questions: contact@aievid.com
