← Docs

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)

  1. Grab a seller key at /start/free (3 fields, no card, manual provisioning within 24h while inbound is small).
  2. Export the key as an env var:
    export LEMONCAKE_SELLER_KEY="lc_seller_..."
  3. 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


SDK source · MIT · github.com/evidai/agent-payment-mcp · Questions: contact@aievid.com