Skip to main content
Most MCP clients (Claude Desktop, Cursor, etc.) don’t have x402 payment support built in. This recipe creates a local proxy that sits between your MCP client and a paywalled MCP server, automatically handling payments on each tool call.

How it works

The proxy intercepts outgoing requests and routes them along two paths:
  • Free path — protocol-level MCP methods (initialize, tools/list, prompts/list, resources/list) are forwarded directly using plain fetch. These are handshake/discovery calls that never cost anything.
  • Paid path — everything else (tools/call, prompts/get, resources/read, etc.) is sent through payer.fetch, which automatically detects a 402 Payment Required response, settles the x402 payment on-chain, and retries the request with proof of payment.

Installation

The proxy

mcp-proxy.ts

What each path looks like

The client discovers available tools — no payment involved:
The proxy uses plain fetch and passes the response straight through.

Running it

Point your MCP client to http://localhost:8402/mcp — the proxy handles payments transparently.

Claude Desktop configuration

Add the proxy as a custom MCP server in your Claude Desktop config: