Skip to content
Dashboard

402-mcp enables x402 payments in MCP

Software Engineer
import { createPaidMcpHandler } from "x402-mcp";
import z from "zod";
const handler = createPaidMcpHandler(
(server) => {
server.paidTool(
"add_numbers",
{
// declare a price of $0.001
price: 0.001
},
{ a: z.number(), b: z.number() },
async (args) => {
// ...your tool call
}
);
},
{ recipient: process.env.WALLET_ADDRESS }
);
export { handler as GET, handler as POST };

import { experimental_createMCPClient as createMCPClient } from "ai";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { withPayment } from "x402-mcp";
const mcpClient = await createMCPClient({
transport: new StreamableHTTPClientTransport(url),
}).then((client) => withPayment(client, { account: process.env.PRIVATE_KEY }));
const tools = await mcpClient.tools();

x402 AI Starter

Fullstack AI demo of x402 with Next.js, AI SDK, AI Gateway, AI Elements and the Coinbase CDP

Deploy