Skip to main content
Charging for an MCP tool call runs the same request/price/pay/settle loop as x402 over HTTP, just carried in MCP’s wire format instead of HTTP headers. If you’ve read How x402 works, this is that same loop applied to a tool handler instead of an HTTP route.

The loop over MCP

The full wire-level detail lives in the x402 Foundation’s MCP transport spec; this is the short version:
  1. The client calls your tool with no payment attached.
  2. Your server returns a tool result with isError: true and a PaymentRequired payload — MCP’s equivalent of an HTTP 402 status and PAYMENT-REQUIRED header.
  3. The client builds a payment payload and retries the same tool call, this time with it attached at _meta["x402/payment"] — MCP’s equivalent of PAYMENT-SIGNATURE.
  4. 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 of PAYMENT-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.
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.
Full runnable version, including a CDP-managed receiver wallet: servers/mcp/server.ts.

Reference

For exact signatures and every configuration option, see the generated SDK reference. Want to test the buyer side? Discover and pay over MCP shows how an agent finds, pays for, and calls paid MCP tools. Learn more about the service settling these payments in CDP Facilitator. Want your paid tool to be discoverable? See Get discovered. Questions about the protocol, pricing, or anything else not covered here? See the FAQ.