> ## Documentation Index
> Fetch the complete documentation index at: https://routeme.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Server

`@routemesh/mcp` is a local MCP server that lets AI coding agents query blockchain data through RouteMesh. Configure it once and your agent gets cross-chain RPC tools — blocks, transactions, logs, balances, fees — live service pricing, plus optional tools to view your RouteMesh account balance, inspect usage, and manage your API keys.

* Query 1000+ EVM chains from one server — no per-chain endpoint config.
* Read-only on-chain tools, plus a generic `rpc_call` escape hatch for any JSON-RPC method.
* Automatic failover: requests retry against `lb2.routeme.sh` when `lb.routeme.sh` returns retryable errors.
* Every result carries the `X-Batch-Id` correlation id, so you can trace requests in the [Logs page](https://routeme.sh/app/consumer/logs).

## **How it works**

The server runs locally as a stdio process spawned by your MCP client (Cursor, Claude Desktop, VS Code, or any other stdio MCP client). It keeps no state and runs no background services:

* **RPC tools** send JSON-RPC to `POST /rpc/{chain_id}/{api_key}`, using your `ROUTEMESH_API_KEY` in the URL path.
* **Customer tools** (usage and API keys) call `https://api.routeme.sh` with a customer management token in the `X-Api-Key` header. They are only exposed when the `ROUTEMESH_MGMT_TOKEN` env var is set.
* On retryable failures (HTTP 429 or 5xx, timeouts, network errors), the server retries with exponential backoff, alternating between the primary and backup load balancers.

The dedicated on-chain query tools read blockchain data; `rpc_call` forwards the method you supply. The customer tools can create and update API keys, so use a dedicated management token for them.

## **Prerequisites**

* Node.js 20 or later
* A RouteMesh API key — see [Quick Start](https://routeme.sh/docs/intro/quick-start.md)
* A customer management token — optional, only needed for account balance, usage, and key management

## **Setup**

### **Configure your MCP client**

In **Cursor**, add the following to `~/.cursor/mcp.json`:

```json theme={null}
{
  "mcpServers": {
    "routemesh": {
      "command": "npx",
      "args": ["-y", "@routemesh/mcp"],
      "env": {
        "ROUTEMESH_API_KEY": "your_routemesh_api_key"
      }
    }
  }
}
```

Any stdio MCP client uses the same shape: command `npx`, args `-y @routemesh/mcp`, and the environment variables below. In Claude Desktop, this goes in `claude_desktop_config.json`.

### **Environment variables**

| Variable | Required | Default | Description |
| :- | :- | :- | :- |
| `ROUTEMESH_API_KEY` | yes | — | Your RouteMesh API key, used in the RPC URL path. |
| `ROUTEMESH_MGMT_TOKEN` | no | — | Customer management token. When set, the server also exposes the [customer tools](#customer-tools) and, for a provider-linked token, the [provider tools](#provider-tools). |
| `ROUTEMESH_API_SERVER_URL` | no | `https://api.routeme.sh` | Base URL for chain discovery and the customer tools. |
| `ROUTEMESH_BASE_URL` | no | `https://lb.routeme.sh` | Primary RPC router. |
| `ROUTEMESH_BACKUP_BASE_URL` | no | `https://lb2.routeme.sh` | Backup RPC router, used on retry. |
| `ROUTEMESH_TIMEOUT_MS` | no | `20000` | Per-request timeout in milliseconds (1000–120000). |
| `ROUTEMESH_RETRY_ATTEMPTS` | no | `2` | Extra retry attempts on retryable failures (0–5). |

The defaults work for all RouteMesh customers — in most setups you only need `ROUTEMESH_API_KEY`.

## **Tools**

### **Pricing tools**

> [!NOTE]
>
> The pricing MCP tools are included in the source for version 1.2.0; npm publication is pending. Until that release is available, use the public HTTP pricing endpoints below or build the MCP server from [source](https://github.com/routemesh/routemesh-mcp). Account balance, usage, and provider tools are already available in published releases.

These tools use public pricing endpoints and do not need a management token. The MCP process still needs the RPC API key in the setup above. Prices are in USD for the RouteMesh service, separate from blockchain gas fees.

| Tool | Parameters | Price unit |
| :- | :- | :- |
| `rpc_get_pricing` | Required numeric `chainId`; optional `method` and `routingStrategy` (`economy` or `performance`). Omit strategy to compare both. | Per million requests |
| `rpc_get_ws_pricing` | Required numeric `chainId`; optional `subscriptionType` such as `newHeads` or `logs`. | Per million notifications |

Results contain `currency`, `unit`, and `items`. An empty list means no matching published price; it does not mean free service. These are current published prices, not account-specific discount quotes. HTTP 429 and 503 are returned as tool errors. See [AI agents and automation](https://routeme.sh/docs/intro/agents.md) for direct HTTP examples.

### **RPC tools**

Always available. `chainId` is the numeric EVM chain ID (e.g. `1` for Ethereum mainnet, `8453` for Base). Use `rpc_list_chains` to discover chains by name or ID.

| Tool | Description | Key parameters |
| :- | :- | :- |
| `rpc_list_chains` | Discover chains supported by RouteMesh. | `query` (name substring), `chainId`, `limit` (default 50, max 500), `offset` (default 0) |
| `rpc_call` | Call any JSON-RPC method — the escape hatch. | `chainId`, `method`, `params` (array, default `[]`) |
| `rpc_get_block` | Fetch a block by number/tag or by hash. | `chainId`, `blockTag` (default `latest`), `blockHash`, `includeTransactions` (default `false`) |
| `rpc_get_transaction` | Fetch a transaction by hash. | `chainId`, `txHash` |
| `rpc_get_transaction_receipt` | Fetch a receipt by hash. | `chainId`, `txHash` |
| `rpc_get_logs` | Query logs with block range and topic filters. | `chainId`, `fromBlock` / `toBlock` (default `latest`), `address` (single or array), `topics` |
| `rpc_get_balance` | Native token balance for an address. | `chainId`, `address`, `blockTag` (default `latest`) |
| `rpc_call_contract` | Read-only `eth_call` with pre-encoded calldata. | `chainId`, `to`, `data`, optional `from` / `gas` / `gasPrice` / `value`, `blockTag` (default `latest`) |
| `rpc_estimate_gas` | `eth_estimateGas` for a transaction request. | `chainId`, `transaction` (standard tx fields, hex values) |
| `rpc_get_fee_data` | Current gas price, max priority fee, and a one-block fee history. | `chainId` |
| `rpc_trace_transaction` | Best-effort trace via `trace_transaction` or `debug_traceTransaction`. | `chainId`, `txHash`, `traceMethod` (default `trace_transaction`), `allowFallback` (default `true`) |

### **Customer tools**

Exposed only when `ROUTEMESH_MGMT_TOKEN` is set.

| Tool | Description |
| :- | :- |
| `get_usage` | Usage summary, balance, and breakdowns from the API server. See the [usage parameters](#get_usage-parameters) below. |
| `list_api_keys` | Metadata for all your API keys: id, name, active, allowed domains, routing strategy, timestamps. The secret key value is **never** returned. |
| `create_api_key` | Create a key with `allowed_domains` (required), `routing_strategy` (`performance` or `economy`, required), and an optional `name`. **The secret key is shown once in the response** — store it immediately; it cannot be retrieved again. |
| `update_api_key` | Partial update of an existing key, addressed by its numeric `id` from `list_api_keys`: `name`, `active`, and/or `allowed_domains`. |

#### **`get_usage` parameters**

* `from` / `to` — RFC3339 window (e.g. `2026-06-01T00:00:00Z`). Defaults: last 30 days up to now; max span 90 days.
* `include` — sections to return: `summary`, `balance`, `by_chain`, `by_api_key`, `by_api_key_chain`, `top_methods`, `time_series`, `by_scenario`. Default: `summary`, `balance`.
* `groupBy` — flat grouped rows instead of sections: `chain`, `api_key`, `api_key,chain`, `method`, `day`. Overrides `include`.
* `chainId` / `apiKeyId` — filter to one chain or one API key.
* `granularity` — `day` or `hour` for `time_series` (default `day`).
* `limit` — max rows for `top_methods` and `groupBy` (default 20, max 100).

## **Provider tools**

Exposed when `ROUTEMESH_MGMT_TOKEN` is set and the token's customer is **linked to a provider**. These tools mirror the provider management endpoints in the [API Reference](https://routeme.sh/docs/api-reference) and authenticate the same way, sending the token in the `X-Api-Key` header. Scoping matches the API endpoints: a token whose customer is not linked to a provider returns 403 (`provider not resolved`), and resources owned by another provider return 404 (existence is not leaked). Call them only with a provider-linked management token.

| Tool | Description |
| :- | :- |
| `provider_list_plans` | List the provider's pricing plans (`GET /provider/plans`). |
| `provider_get_plan_methods` | List the RPC methods configured for a plan (`GET /provider/plans/:planId/methods`). |
| `provider_get_node_status` | Get a node's sync status — `{ node_id, in_sync, status }` (`GET /provider/nodes/:nodeId/status`). |
| `provider_upsert_plan_methods` | Add 1-500 RPC method rows to a plan (`POST /provider/plans/:planId/methods`). |
| `provider_upsert_node` | Create or update an HTTP node on a plan (`PUT /provider/nodes`). URL must be a public http(s) endpoint; the node is screened before persisting. |
| `provider_upsert_ws_node` | Create or update a WebSocket node on a plan (`PUT /provider/nodes/ws`). URL must be a public wss\:// endpoint that accepts `eth_subscribe("newHeads")`; the server dials to verify. |
| `provider_set_node_status` | Enable, disable, or delete a node — `healthy`, `disabled by provider`, or `provider-deleted` (`POST /provider/nodes/status`). |

Node upserts screen endpoints before persisting: URLs must be public `http(s)` or `wss://` (loopback, private, and link-local hosts are rejected up front). A failed mandatory screening returns 400; a URL owned by another provider returns 404; a URL already registered to a different plan of the same provider returns 409. Endpoint-level behavior and error codes are in the [API Reference](https://routeme.sh/docs/api-reference).

## **Management tokens**

Customer tools authenticate with a customer management token. Create one in the dashboard:

1. Open [Mgmt Tokens](https://routeme.sh/app/consumer/mgmt-tokens).
2. Click **New Token** and give it a label (e.g. `mcp-cursor`).
3. Copy the secret — it is **shown only once**.

Customer management tokens are scoped to your account's management routes and, for a provider-linked token, the provider routes — and nothing else. Use a dedicated token for the MCP server so you can revoke it independently if it leaks.

Add `"ROUTEMESH_MGMT_TOKEN": "your_customer_management_token"` alongside `ROUTEMESH_API_KEY` in the MCP client environment, then restart the MCP server to expose customer tools.

## **Example prompts**

* "Compare economy and performance eth\_call prices on Base."
* "What is the price per million newHeads notifications on Ethereum?"
* "List chains that match `base` and show me their chain IDs."
* "Get the latest block on BSC and summarize the timestamp and transaction count."
* "Fetch the receipt for tx `0x...` on Ethereum and tell me if it succeeded."
* "Get logs for contract `0x...` on Arbitrum between blocks 1000000 and 1050000."
* "Estimate gas for calling this method on Base with these parameters."
* "Run `eth_getCode` for address `0x...` on Base (chain 8453)."
* "Show my RouteMesh usage for the last 7 days broken down by chain."
* "What is my current RouteMesh balance and request count this month?"

## **Errors and debugging**

* Tools return structured JSON. RPC errors from the router are passed through unchanged — interpret `error.code` with [RPC error codes](https://routeme.sh/docs/intro/rpc-error-codes.md).
* Retryable HTTP failures (429, 5xx, timeouts) are retried automatically up to `ROUTEMESH_RETRY_ATTEMPTS`.
* Every RPC result includes the `batchId` from the `X-Batch-Id` response header. Use it in the [Logs page](https://routeme.sh/app/consumer/logs) exactly as you would for direct RPC calls — see [Debugging](https://routeme.sh/docs/intro/debugging.md).
* [eth\_getLogs limits](https://routeme.sh/docs/intro/request-behavior.md#eth_getlogs-limits) apply to `rpc_get_logs` exactly as they do to direct requests.

## **Next steps**

* [Quick Start](https://routeme.sh/docs/intro/quick-start.md) — Get an API key and make your first request.
* [Request behavior](https://routeme.sh/docs/intro/request-behavior.md) — Cooldowns, 429s, and batch requests.
* [Debugging](https://routeme.sh/docs/intro/debugging.md) — Use `X-Batch-Id` and the Logs page when something goes wrong.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.