MCP tools for AI agents — HTTP requests with automatic x402 micropayments
Project description
x402-mcp
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:
- Generate a fresh EVM wallet (or use your existing key with
--key) - Show a QR code for your wallet address
- Print funding instructions (testnet USDC is free)
- Output the MCP config JSON, ready to paste
Add to your MCP client
Paste the config 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 for funding/verification |
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:
wallet_info()
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file x402_mcp-0.3.1.tar.gz.
File metadata
- Download URL: x402_mcp-0.3.1.tar.gz
- Upload date:
- Size: 179.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40fb11419e73e0996237bbe5f7f5e2db4ceb4a563cb344435b698ace3708f837
|
|
| MD5 |
026ff34d4226bfd2ba720a00a0d8cc73
|
|
| BLAKE2b-256 |
19d1827fa66c1265ca62da3a73d1db8930521cf182611228c968e1df2ebaf849
|
Provenance
The following attestation bundles were made for x402_mcp-0.3.1.tar.gz:
Publisher:
ci.yml on dsr-restyn/x402-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
x402_mcp-0.3.1.tar.gz -
Subject digest:
40fb11419e73e0996237bbe5f7f5e2db4ceb4a563cb344435b698ace3708f837 - Sigstore transparency entry: 939257632
- Sigstore integration time:
-
Permalink:
dsr-restyn/x402-mcp@47684822a4a9676ed7e4dc2c068f01e00a25b883 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/dsr-restyn
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@47684822a4a9676ed7e4dc2c068f01e00a25b883 -
Trigger Event:
push
-
Statement type:
File details
Details for the file x402_mcp-0.3.1-py3-none-any.whl.
File metadata
- Download URL: x402_mcp-0.3.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6e2fe1ce38e6d01f820d69c1f2cad676fe940c31a42131b20833868df59ee22
|
|
| MD5 |
0d439421e5494c4c0af9fc02a8ad59b9
|
|
| BLAKE2b-256 |
695ba8efb030a9e4267c39ac3fee2a0d6261a09ed9437cfc74739f9bfc4ca8ab
|
Provenance
The following attestation bundles were made for x402_mcp-0.3.1-py3-none-any.whl:
Publisher:
ci.yml on dsr-restyn/x402-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
x402_mcp-0.3.1-py3-none-any.whl -
Subject digest:
b6e2fe1ce38e6d01f820d69c1f2cad676fe940c31a42131b20833868df59ee22 - Sigstore transparency entry: 939257633
- Sigstore integration time:
-
Permalink:
dsr-restyn/x402-mcp@47684822a4a9676ed7e4dc2c068f01e00a25b883 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/dsr-restyn
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@47684822a4a9676ed7e4dc2c068f01e00a25b883 -
Trigger Event:
push
-
Statement type: