Skip to main content
X4

x402

v0.1.3API Key

HTTP-native micropayments by Coinbase. USDC on Base and Solana. Machine-to-machine payments with HTTP 402.

10 tools1 env vars🌐 GLOBALstable on npm

What your agent can do

x402 gives your agent 10 tools it calls directly β€” pick the ones it needs, in Claude, Cursor, or any MCP client.

  • pay_request β€” Pay for a 402-protected resource. Sends USDC payment via x402 protocol and returns the resource content. The agent automatically handles the 402 handshake.
  • verify_payment β€” Verify if a x402 payment was received and settled on-chain
  • create_paywall β€” Create a x402 paywall configuration for an endpoint. When requests hit this endpoint, they receive HTTP 402 with payment instructions.
Example call
// Your agent calls a tool directly β€” no glue code.
// CodeSpar's managed tier handles OAuth2, token rotation and rate limits.
const result = await session.call("pay_request", { /* ... */ });

Install

terminal
$ npm install @codespar/mcp-x402

Quickstart

Add this entry to your claude_desktop_config.json (or any MCP-compatible client config).

claude_desktop_config.json
{
  "mcpServers": {
    "x402": {
      "command": "npx",
      "args": [
        "-y",
        "@codespar/mcp-x402"
      ],
      "env": {
        "X402_API_KEY": "<your_x402_api_key>"
      }
    }
  }
}

After restart, your agent can call any of the 10 tools below β€” try pay_request first.

Environment variables Β· 1

Required to authenticate the server. Stored encrypted when using CodeSpar managed hosting.

X402_API_KEY
requiredsecret

API key for x402

Available tools Β· 10

Each tool is independent β€” your agent loads only what it needs to reduce context and response time.

WRITEpay_request
Pay for a 402-protected resource. Sends USDC payment via x402 protocol and returns the resource content. The agent automatically handles the 402 handshake.
WRITEverify_payment
Verify if a x402 payment was received and settled on-chain
WRITEcreate_paywall
Create a x402 paywall configuration for an endpoint. When requests hit this endpoint, they receive HTTP 402 with payment instructions.
WRITEget_paywall
Get paywall configuration for a specific URL
WRITElist_paywalls
List all configured x402 paywalls
DELETEdelete_paywall
Remove a x402 paywall from an endpoint
READget_balance
Get available USDC balance for x402 payments
WRITElist_payments
List x402 payment history with optional filters

Compatible frameworks

MCP is a protocol β€” any framework that speaks it can mount this server.

Claude Agent SDKAnthropic
OpenAI AgentsOpenAI
Vercel AI SDKVercel
LangChainLangChain
LlamaIndexLlamaIndex
CrewAICrewAI
MastraMastra
Any MCP clientProtocol

Frequently asked questions

Run `npx -y @codespar/mcp-x402` and add the config block above to your MCP client β€” Claude, Cursor, VS Code, or any MCP-compatible client. No build step, no SDK required. Prefer hosted? CodeSpar's managed tier runs it for you with auth handled.
x402 β€” MCP server Β· 10 tools | CodeSpar