The loop over MCP
The full wire-level detail lives in the x402 Foundation’s MCP transport spec; this is the short version:- The client calls your tool with no payment attached.
- Your server returns a tool result with
isError: trueand aPaymentRequiredpayload — MCP’s equivalent of an HTTP 402 status andPAYMENT-REQUIREDheader. - The client builds a payment payload and retries the same tool call, this time with it attached
at
_meta["x402/payment"]— MCP’s equivalent ofPAYMENT-SIGNATURE. - Your server verifies and settles the payment, then returns the tool’s real result with
settlement info attached at
_meta["x402/payment-response"]— MCP’s equivalent ofPAYMENT-RESPONSE.
Charging for tool calls
Wrap individual tool handlers with verify-and-settle logic, and route settlement through the CDP Facilitator so there’s no facilitator infrastructure of your own to run.payTo / pay_to is
any address that can receive the asset — a Coinbase Business, Prime, or CDP custodial wallet deposit
address, a self-custody wallet, or an API Key Wallet. A
wallet secret is only needed if you provision that API Key Wallet; see
Pay-to address.
- TypeScript
- Python
x402ResourceServer (from @x402/core/server) paired with createPaymentWrapper (from
@x402/mcp) wraps tool handlers; createCdpFacilitatorClient() from the CDP SDK is the
drop-in facilitator. The CDP SDK’s createX402Server is HTTP-only, so it isn’t a fit here —
build the resource server directly and swap in the CDP facilitator and wallet, same as below.servers/mcp/server.ts.