Skip to main content

x402-mcp

PyPI CI Python 3.11+ License: MIT

Give your AI agent a wallet. It pays for APIs automatically.

x402-mcp is an MCP server that adds HTTP request tools with automatic x402 micropayments to any AI agent. When a request hits a 402-gated endpoint, payment happens automatically — no API keys, no accounts, no billing dashboards.

Works with any x402-enabled service. Not locked to a single provider.

How it works

Agent calls x402_fetch("https://some-api.com/data")
    → Server responds 402 Payment Required
    → x402-mcp returns payment details (amount, network, recipient)
    → Agent shows details to user, user approves
    → Agent calls x402_fetch(url, confirm_payment=True)
    → x402-mcp signs a gasless EIP-712 payment authorization
    → Agent gets the response ✓

By default, your agent confirms payments with the user before paying. Set X402_CONFIRM_PAYMENTS=false to auto-pay without confirmation (original behavior).

Quick start

# Install and run the setup wizard
uvx x402-mcp-setup

The wizard will:

  1. Generate a fresh EVM wallet (or use your existing key with --key)
  2. Show a QR code for your wallet address
  3. Print funding instructions (testnet USDC is free)
  4. Offer to write the MCP config directly to ~/.claude/mcp.json (press Enter to accept)
  5. Offer to watch for your first USDC deposit and confirm when it arrives

Then restart Claude Code or Cursor — the server loads automatically.

Manual config (if you skip the auto-write)

Paste into ~/.claude/mcp.json (Claude Code) or your Cursor MCP settings:

{
  "mcpServers": {
    "x402-mcp": {
      "command": "uvx",
      "args": ["x402-mcp"],
      "env": {
        "EVM_PRIVATE_KEY": "0xYourPrivateKey",
        "X402_CONFIRM_PAYMENTS": "true"
      }
    }
  }
}

Your agent now has two tools:

Tool Description
x402_fetch HTTP requests to any URL — shows payment details for confirmation, then pays on approval
wallet_info Returns your wallet's public address and ETH/USDC balances on Base mainnet and Base Sepolia

Usage examples

Fetch from an x402-gated API (with payment confirmation):

# Step 1: Agent makes request, gets payment details
x402_fetch(url="https://api.example.com/data")
# → Returns: {payment_required: True, human_readable: {amount: "1000000", ...}}

# Step 2: After user approves, agent confirms payment
x402_fetch(url="https://api.example.com/data", confirm_payment=True)
# → Returns: {status: 200, body: "..."}

POST with JSON body:

x402_fetch(
    url="https://api.example.com/submit",
    method="POST",
    headers={"Content-Type": "application/json"},
    body='{"query": "hello"}'
)

Check your wallet address and balances:

wallet_info()
# → Returns: {address: "0x...", balances: {Base: {ETH: "0.001000", USDC: "5.000000", ...}, ...}}

Architecture

src/x402_mcp/
├── mcp_server.py   # FastMCP server — x402_fetch + wallet_info tools
└── setup.py        # Wallet generation wizard, prints MCP config JSON

Two entry points:

  • x402-mcp — MCP stdio server (what your agent connects to)
  • x402-mcp-setup — Interactive setup wizard

The server lazy-initializes an x402HttpxClient on first tool call. Payments are gasless EIP-712 signed authorizations — no on-chain transaction per request. Binary responses (images, etc.) are returned as base64-encoded data.

Development

uv sync --extra dev    # Install deps
uv run ruff check src/ # Lint
uv run pytest tests/ -v # Test

E2E test against a real x402 endpoint:

EVM_PRIVATE_KEY=0x... X402_TEST_URL=https://some-x402-api.com/endpoint \
  uv run python scripts/test_e2e.py

License

MIT

Metadata

Release files for x402-mcp 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for x402-mcp 0.5.0
File Size Uploaded Provenance Actions
x402_mcp-0.5.0.tar.gz 182.9 kB With provenance Details for x402_mcp-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for x402-mcp 0.5.0
File Interpreter ABI Platform Actions
x402_mcp-0.5.0-py3-none-any.whl Python 3 none any Details for x402_mcp-0.5.0-py3-none-any.whl

Total release size: 195.0 kB

Release files / x402_mcp-0.5.0.tar.gz

Download URL x402_mcp-0.5.0.tar.gz
Size 182.9 kB
Tags Source
SHA-256 checksum
How to use checksums
89b2199bb51f6027e72edc22e2b420ea5ab48c5ed950ddf3a4821c0f911abdc7
BLAKE2b-256 checksum
How to use checksums
62ebb6b10a6490f13fd7d5268c9db9c099ded2c0d37a52b0a7f78092bd792ed3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.

Transparency log

Release files / x402_mcp-0.5.0-py3-none-any.whl

Download URL x402_mcp-0.5.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
916483aa26a6b15b79c0af4f64091a76e8ec8dbaca4c92855158405c8f3c8c05
BLAKE2b-256 checksum
How to use checksums
5f8c3a400b9755905efb91f50df27ccd0d9e639bd7f80a1b9188a0983bccddec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.

Transparency log

Security for x402-mcp 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for x402_mcp-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page