How it works
- Free path — protocol-level MCP methods (
initialize,tools/list,prompts/list,resources/list) are forwarded directly using plainfetch. These are handshake/discovery calls that never cost anything. - Paid path — everything else (
tools/call,prompts/get,resources/read, etc.) is sent throughpayer.fetch, which automatically detects a402 Payment Requiredresponse, 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
- Free (tools/list)
- Paid (tools/call)
The client discovers available tools — no payment involved:The proxy uses plain
fetch and passes the response straight through.Running it
http://localhost:8402/mcp — the proxy handles payments transparently.