x402 MCP Proxy

x402 MCP Proxy

A local MCP proxy that connects to remote MCP servers and automatically handles x402 payments, signing USDC on-chain when a tool returns HTTP 402.

Category
访问服务器

README

x402 MCP Proxy

A local MCP (Model Context Protocol) proxy that connects to remote MCP servers and automatically handles x402 payments. When a remote MCP tool triggers an HTTP 402 response, the proxy signs a USDC payment on-chain and retries — transparently, with no changes needed on the client side.

How It Works

┌─────────────┐      stdio       ┌──────────────┐    HTTP + x402     ┌──────────────┐
│  AI Client   │ ◄──────────────► │  x402 Proxy  │ ◄────────────────► │ Remote MCP A │
│ (Claude, etc)│                  │  (this repo)  │                   ├──────────────┤
└─────────────┘                  │              │ ◄────────────────► │ Remote MCP B │
                                  └──────────────┘                   └──────────────┘
  1. The proxy connects to one or more remote MCP servers (via Streamable HTTP or SSE).
  2. It discovers their tools and re-exposes them to the AI client over stdio, prefixed by server name (e.g. cmc_get_quotes).
  3. When a tool call returns HTTP 402, the proxy intercepts it, signs an EIP-3009 transferWithAuthorization (USDC on Base), and retries automatically.

Quick Start

1. Install

git clone https://github.com/coinmarketcap-official/x402-mcp-proxy.git
cd x402-mcp-proxy
pnpm install

2. Configure Remote MCPs

Create x402-mcps.json in the project root (see x402-mcps.example.json):

{
  "x402mcpServers": [
    {
      "url": "https://pro.coinmarketcap.com/x402/mcp",
      "prefix": "cmc"
    },
    {
      "url": "https://other-mcp.example.com/mcp",
      "prefix": "other",
      "headers": {
        "Authorization": "Bearer your_token"
      }
    }
  ]
}

Or pass it as an environment variable (prefix, url pairs):

export X402_REMOTE_MCPS="cmc,https://pro.coinmarketcap.com/x402/mcp"

3. Configure Wallet

Copy .env.example to .env and add at least one private key:

cp .env.example .env
EVM_PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE

The EVM wallet needs USDC on Base for x402 payments. Solana (SVM) is also supported.

4. Run

pnpm dev    # development (tsx)
pnpm build && pnpm start  # production

5. Connect from an AI Client

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "x402": {
      "command": "npx",
      "args": ["tsx", "/path/to/x402-mcp-proxy/src/index.ts"],
      "env": {
        "EVM_PRIVATE_KEY": "0x...",
        "X402_REMOTE_MCPS": ["cmc", "https://pro.coinmarketcap.com/x402/mcp"]
      }
    }
  }
}

Cursor (.cursor/mcp.json):

{
  "mcpServers": {
    "x402": {
      "command": "npx",
      "args": ["tsx", "/path/to/x402-mcp-proxy/src/index.ts"],
      "env": {
        "EVM_PRIVATE_KEY": "0x...",
        "X402_REMOTE_MCPS": ["cmc", "https://pro.coinmarketcap.com/x402/mcp"]
      }
    }
  }
}

You can also point to a config file for more advanced options (custom headers, etc.):

"X402_CONFIG": "/path/to/x402-mcps.json"

Configuration Reference

Remote MCP Servers

Source Description
X402_REMOTE_MCPS env Flat pair list: ["prefix","url",…] or "prefix,url,…" (takes priority)
X402_CONFIG env Custom path to a JSON config file
x402-mcps.json Default config file in project root

Env var format — prefix/url pairs, no headers support:

["cmc", "https://pro.coinmarketcap.com/x402/mcp"]

Config file format — full control with headers:

{
  "x402mcpServers": [
    {
      "prefix": "cmc",
      "url": "https://pro.coinmarketcap.com/x402/mcp"
    },
    {
      "prefix": "other",
      "url": "https://other.example.com/mcp",
      "headers": { "Authorization": "Bearer xxx" }
    }
  ]
}

Wallet Keys

Env Variable Description
EVM_PRIVATE_KEY EVM private key (0x-prefixed hex). Used for USDC payments on Base.
SVM_PRIVATE_KEY Solana private key (base58-encoded). Used for USDC payments on Solana.

At least one key is required for x402 payment handling.

Payment Safety Limits

The proxy validates every 402 payment request before signing. All limits are configurable via environment variables:

Env Variable Default Description
X402_MAX_PAYMENT 100000 (0.10 USDC) Maximum amount per single request (in asset smallest unit)
X402_MAX_SPEND_PER_SESSION 1000000 (1.00 USDC) Maximum cumulative spend per proxy session
X402_ALLOWED_NETWORKS eip155:8453,solana:5eykt… Comma-separated allowlist of CAIP-2 network IDs
X402_ALLOWED_ASSETS Base USDC, Solana USDC Comma-separated allowlist of asset contract addresses

If a 402 response requests an amount, network, or asset outside these limits, the proxy rejects the payment and returns the raw 402 to the client without signing anything. Session spend resets when the proxy process restarts.

What is x402?

x402 is an open protocol by Coinbase that enables instant, pay-per-request API access using stablecoin payments over HTTP. When an API returns HTTP 402, the client signs a USDC transfer authorization, and the server's facilitator executes the on-chain payment only after successfully delivering the response.

Key properties:

  • No subscription needed — pay per request with USDC
  • Pay only on success — if the server fails to return data, the signed authorization expires unused and no payment is deducted
  • Works on Base (EVM) and Solana

Project Structure

x402-mcp-proxy/
├── src/index.ts           # Proxy entry point
├── x402-mcps.example.json # Example remote MCP config
├── .env.example           # Example environment variables
├── package.json
├── tsconfig.json
└── LICENSE                # MIT

Security Considerations

Trust Model

This proxy is designed to run locally on your own machine as a stdio-based MCP server. The AI client (Claude, Cursor, etc.) communicates with it over stdin/stdout — there is no network listener. Authentication between the client and the proxy is therefore handled by OS-level process isolation.

If you deploy this proxy in a shared or multi-user environment (e.g., a server accessed by multiple users), you should add an authentication layer in front of it. The default stdio transport is not designed for that use case.

Private Key Storage

Private keys are loaded from environment variables (typically a .env file). For personal / development use this is acceptable, but for production or high-value wallets consider:

  • OS keychain integration (macOS Keychain, Linux secret-service)
  • Hardware wallets or cloud KMS (AWS KMS, GCP Cloud KMS)
  • Encrypted env files with a passphrase

Never commit .env files containing real private keys to version control.

Built-in Protections

The proxy ships with several safety checks enabled by default:

  • Per-request amount cap — rejects 402 responses that request more than the configured limit
  • Session spending cap — stops signing once cumulative spend reaches the threshold
  • Network & asset allowlists — only pays on explicitly permitted chains and tokens
  • HTTPS enforcement — warns at startup if any remote MCP URL uses an insecure protocol (non-localhost HTTP)
  • Sanitised error output — internal error details are not leaked to clients
  • Structured payment audit log — every signed payment is logged to stderr with amount, network, asset, recipient, and target URL

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选