Payment Middleware for MCP Servers
Model Context Protocol (MCP) servers expose tools that AI agents call directly. mcp-x402-xrpl adds a payment layer to that call path: createPaymentGate issues 402 challenges on the server side, createX402Middleware auto-pays them on the client/agent side, and wrapMcpServer combines both into a ready-to-run MCP server with per-tool pricing.
Quick facts
- Server-side:
createPaymentGate({ destination, amountDrops, currency, description })as Express middleware on any route. - Client-side:
createX402Middleware({ walletSeed, network, maxPaymentDrops })auto-fulfills 402 challenges. - All-in-one:
wrapMcpServer({ x402, tools })returns{ app, listen }for a complete gated MCP server. - Low-level:
XrplFacilitatorexposes direct.pay()/.verify()for custom integrations.
Frequently asked questions
Can I gate just one tool and leave others free?
Yes — createPaymentGate is applied per-route, so you can mix free and paid tools on the same MCP server.
What does wrapMcpServer do that the individual middlewares don't?
It spins up a complete MCP-compatible Express server in one call, with per-tool pricing declared inline in the tools array — no manual Express wiring required.
Does this work with any MCP client, or only ScriptMasterLabs agents?
Any MCP-compatible agent or client can call a server built this way — the payment gate is just an extra HTTP round-trip (402 → pay → retry) that any HTTP-capable agent can perform.