rpc402-mcp
# rpc402-mcp
MCP server (stdio) for [RPC402](https://rpc.zero-orbit.online) — composed
on-chain reads, paid per call in USDC via the [x402](https://www.x402.org)
protocol. One tool call replaces 3–61 raw RPC calls: you get a whole answer
(a wallet's full balance sheet, a chain's status bundle, a transaction with
its receipt), not a raw passthrough.
**Price: $0.002 USDC per tool call**, settled on Base, Solana or Polygon
(your choice, see `RPC402_PAY_NETWORK`). No accounts, no API keys — payment
*is* the auth. Read chains: `ethereum`, `solana`, `base`.
## Tools
| Tool | Arguments | Returns |
|---|---|---|
| `token_balance` | `chain, wallet, token` | One token balance: raw balance, decimals, symbol, formatted |
| `wallet_balances` | `chain, wallet, tokens[]?` (≤20) | Native + all token balances in one call; per-token failures marked `partial` |
| `chain_status` | `chain` | Block/slot, chain id, gas price, epoch/blockhash/health bundle |
| `tx_lookup` | `chain, hash` | Tx + receipt composed: found, status, success, confirmations, fees |
| `event_logs` | `chain, address, fromBlock?, toBlock?, topics?, limit?` | EVM `eth_getLogs` (≤2,000-block range, ≤1,000 results) or Solana signatures for the account |
## Install & run
```bash
cd rpc402-mcp
npm install
node src/index.js # stdio MCP server; logs go to stderr
```
Requires Node ≥ 20.
## Configuration
| Env var | Required | Meaning |
|---|---|---|
| `RPC402_KEYFILE` | paid mode | Payer keyfile path. Formats: `0x…` EVM private-key text file, Solana CLI keypair JSON, or base58 secret-key text file. The key never leaves your machine; it only signs the x402 payment authorization locally. |
| `RPC402_PAY_NETWORK` | no | Settlement network preference: `base` (default), `solana`, or `polygon`. Must match the keyfile type (EVM key → base/polygon, Solana key → solana). |
| `RPC402_BASE_URL` | no | API base URL. Default `https://rpc.zero-orbit.online`. |
| `MCP_DEMO` | no | `1` = demo mode: no keyfile, no payment; calls send `X-PAYMENT: demo`. Only works against a local RPC402 instance running with `DEMO_MODE=1`. |
| `SOLANA_RPC_URL` | no | Custom Solana RPC used to build the payment transaction. |
Fund the payer wallet with a little USDC on your chosen settlement network
(EVM payments are EIP-3009 signatures — gasless for the payer; the
facilitator submits. On Solana the facilitator's feePayer covers the network
fee).
## Client configs
### Claude Desktop (`claude_desktop_config.json`)
```json
{
"mcpServers": {
"rpc402": {
"command": "node",
"args": ["/absolute/path/to/rpc402-mcp/src/index.js"],
"env": {
"RPC402_KEYFILE": "/absolute/path/to/payer-keyfile",
"RPC402_PAY_NETWORK": "base"
}
}
}
}
```
### Cursor (`.cursor/mcp.json`)
Same shape as Claude Desktop above.
### Generic MCP client
Launch `node /absolute/path/to/rpc402-mcp/src/index.js` as a stdio
subprocess with the env vars above set.
### Demo mode (no wallet)
```json
"env": { "MCP_DEMO": "1", "RPC402_BASE_URL": "http://127.0.0.1:3000" }
```
…against a locally started RPC402 with `DEMO_MODE=1`. Demo calls serve real
live reads; only the payment is simulated.
## Notes
- Input validation happens server-side *before* payment verification, so a
malformed call is a 400, never a charge.
- If a payment settles and the read then fails (502), the error body carries
a single-use `compensatingCredit` for one free identical retry within 24h.
TDQS
Scored across 5 tools
Each tool targets a clearly distinct on-chain read concern: chain status, single-token balance, whole-wallet balances, transaction lookup, and event logs. The overlap between token_balance and wallet_balances is resolved by explicit scope differences in the descriptions.
All names use consistent snake_case and are concise resource-oriented identifiers. There are minor pattern variations (singular token_balance vs plural wallet_balances; noun phrases like tx_lookup/event_logs) but nothing confusing.
Five tools is well-scoped for a focused read-only RPC402 server, and each tool corresponds to a meaningful composite RPC operation. No obvious filler or missing tool-count pressure.
The surface covers the core read workflows: chain status, token balances, wallet snapshot, transaction lookup, and event logs. Some adjacent RPC capabilities such as block lookup, nonce/account metadata, or fee estimation are absent, but major workflows are covered.