Skip to main content
Glama
x402-mcp
by clawfred

x402-mcp

Minimal MCP server that calls an x402-paid HTTP API and automatically pays when it receives an HTTP 402 Payment Required.

This is basically the official guide implemented as a standalone repo so we can reuse it as context for:

  • seo402

  • agent-casino

  • any other x402-enabled project

What this does

  • Exposes an MCP tool: get-data-from-resource-server

  • Tool calls GET ${ENDPOINT_PATH} against ${RESOURCE_SERVER_URL}

  • If the API responds with 402 + PAYMENT-REQUIRED, the x402 axios wrapper:

    • parses requirements

    • signs a payment with your wallet

    • retries the request with the payment signature

Related MCP server: x402 Stellar MCP Server

Prerequisites

  • Node.js 20+

  • pnpm 10+

  • An EVM wallet with USDC on Base Sepolia (recommended for testing)

  • An x402-compatible server to call

    • easiest: Coinbase x402 example server (servers/express)

Setup

pnpm install
cp .env.example .env

Edit .env:

  • EVM_PRIVATE_KEY=0x...

  • RESOURCE_SERVER_URL=http://localhost:4021

  • ENDPOINT_PATH=/weather

Run (MCP server)

pnpm dev

This runs an MCP server over stdio (what Claude Desktop expects).

Run (x402 example resource server)

In another terminal (separate repo):

git clone https://github.com/coinbase/x402.git
cd x402/examples/typescript
pnpm install && pnpm build
cd servers/express
pnpm dev

Claude Desktop config

Add this to your Claude Desktop config (exact file location depends on OS):

{
  "mcpServers": {
    "x402": {
      "command": "pnpm",
      "args": [
        "--silent",
        "-C",
        "<ABS_PATH_TO>/x402-mcp",
        "dev"
      ],
      "env": {
        "EVM_PRIVATE_KEY": "0x...",
        "RESOURCE_SERVER_URL": "http://localhost:4021",
        "ENDPOINT_PATH": "/weather"
      }
    }
  }
}

Restart Claude Desktop.

Then ask Claude to call the tool get-data-from-resource-server.


How do non-crypto people / agents pay?

x402 always needs a signer somewhere. There are basically 3 viable UX models:

  1. Power-user model (today): the human running the agent sets EVM_PRIVATE_KEY (or a wallet connector) and pre-funds it with USDC.

    • simple, works now

    • best for builders

  2. Custodial / hosted wallet (most mainstream): the app generates a wallet for the user and stores the key server-side (or in an HSM).

    • the agent never touches keys

    • user pays with Stripe / card → we top up their USDC balance behind the scenes

    • best UX, but adds legal/ops complexity

  3. Delegated spender / allowance model: user keeps their own wallet, but grants allowance to a payer service.

    • payer service signs x402 payments up to limits

    • better than full custody, but still more complex than (1)

For MVP, we should assume (1). For real distribution, we probably evolve toward (2) or (3).

Available Tools

1 tool
get-data-from-resource-serverB

Fetch from paid API via x402 (GET /weather)

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 1 tool

    Disambiguation4/5

    With only one tool, there is no risk of selecting the wrong tool or confusing it with another. However, the name 'get-data-from-resource-server' is broad while the description narrows it to GET /weather, leaving some ambiguity about whether other resources are supported.

    Naming Consistency4/5

    The single tool uses a readable snake_case, verb-led name. There is no inconsistency to assess, though one name cannot establish a strong pattern across a set.

    Tool Count2/5

    A single tool is very thin for an MCP server that appears intended to wrap x402 paid-API access. It likely needs additional operations or a more generic fetch interface to earn its place as a server.

    Completeness2/5

    The surface only exposes a GET-style fetch for /weather, with no support for other HTTP methods, resource discovery, payment status, or generic endpoint selection. This is a significant gap for the apparent x402 domain.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      L402 + x402 client MCP. AI agents discover, pay for, and consume any payment-gated API autonomously. Supports Lightning (NWC), Cashu ecash, stablecoins, and human-in-the-loop payments.
      14
      383 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables testing webhook endpoints by sending HTTP requests with custom headers, method, and body, measuring latency and TLS info, with pay-per-call via x402 micropayments.
      MIT