x402-mcp
Calls an x402-paid HTTP API and automatically handles payment when a 402 Payment Required response is received.
README
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:
seo402agent-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
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)
- easiest: Coinbase x402 example server (
Setup
pnpm install
cp .env.example .env
Edit .env:
EVM_PRIVATE_KEY=0x...RESOURCE_SERVER_URL=http://localhost:4021ENDPOINT_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:
-
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
-
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
-
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).
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.