Skip to content

Commit d352e63

Browse files
JkLondonJkLondon
andauthored
[kimiko] MCP finisher (0.0.2) (#19487)
## Summary - Add standalone MCP binary (`cmd/mcp`) with three connection modes: JSON-RPC proxy, direct datadir access (rpcdaemon-style), and auto-discovery - Add `StandaloneMCPServer` that proxies MCP tool calls via JSON-RPC HTTP (no in-process Go API dependency) - Fix datadir mode: set `DBReadConcurrency` (was 0 → semaphore deadlock), `TxPoolApiAddr` (was empty → gRPC error), `cfg.API` (was nil → empty API list) - Fix stdio shutdown: add `ServeContext(ctx)` to propagate parent context instead of `ServeStdio()` which creates a competing signal handler - Replace `MustDecode`/`MustDecodeBig` with error-returning variants in embedded MCP handlers to prevent panics on malformed input - Extract `Version` constant (0.0.2) shared by both server variants - Add `README.md` with usage, Claude Desktop config, and full tool list ## Changes | File | What | |------|------| | `cmd/mcp/main.go` | New standalone binary: cobra CLI, 3 connection modes, signal handling | | `cmd/mcp/README.md` | Documentation with examples and Claude Desktop config | | `rpc/mcp/standalone.go` | New `StandaloneMCPServer` — JSON-RPC proxy variant with tools, prompts, resources | | `rpc/mcp/mcp.go` | `MCPTransport` interface, `ServeContext()`, `Version` const, error handling fixes | | `Makefile` | `mcp` build target | --------- Co-authored-by: JkLondon <me@ilyamikheev.com>
1 parent 450a110 commit d352e63

File tree

5 files changed

+2224
-14
lines changed

5 files changed

+2224
-14
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ COMMANDS += evm
189189
COMMANDS += caplin
190190
COMMANDS += snapshots
191191
COMMANDS += diag
192+
COMMANDS += mcp
192193

193194
# build each command using %.cmd rule
194195
$(COMMANDS): %: %.cmd

cmd/mcp/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Erigon MCP Server
2+
3+
The Erigon MCP (Model Context Protocol) server exposes Ethereum blockchain data
4+
to AI assistants like Claude Desktop via the MCP standard.
5+
6+
## Two Server Variants
7+
8+
### 1. Embedded (inside Erigon)
9+
10+
The MCP server runs inside the Erigon process with direct access to APIs.
11+
Enabled with `--mcp.addr` and `--mcp.port` flags.
12+
13+
```bash
14+
./build/bin/erigon --datadir=./data --mcp.addr=127.0.0.1 --mcp.port=8553
15+
```
16+
17+
This mode uses SSE transport and provides full access to all tools including
18+
in-process Prometheus metrics.
19+
20+
### 2. Standalone (`cmd/mcp`)
21+
22+
A separate binary that connects to Erigon via JSON-RPC or direct DB access.
23+
Supports stdio transport (for Claude Desktop) and SSE.
24+
25+
```bash
26+
make mcp
27+
./build/bin/mcp --help
28+
```
29+
30+
## Connection Modes
31+
32+
### Mode 1: JSON-RPC Proxy (recommended)
33+
34+
Connect to a running Erigon node via its HTTP JSON-RPC endpoint:
35+
36+
```bash
37+
# Explicit URL:
38+
./build/bin/mcp --rpc.url http://127.0.0.1:8545
39+
40+
# Shorthand for localhost:
41+
./build/bin/mcp --port 8545
42+
43+
# With log access:
44+
./build/bin/mcp --port 8545 --log.dir /data/erigon/logs
45+
```
46+
47+
### Mode 2: Direct Datadir Access
48+
49+
Open Erigon's MDBX database directly (like an external rpcdaemon).
50+
Requires either a running Erigon with gRPC private API, or read-only DB access.
51+
52+
```bash
53+
# Connect to Erigon's gRPC API + read DB directly:
54+
./build/bin/mcp --datadir /data/erigon --private.api.addr 127.0.0.1:9090
55+
56+
# Default private API address is 127.0.0.1:9090
57+
./build/bin/mcp --datadir /data/erigon
58+
```
59+
60+
### Mode 3: Auto-Discovery
61+
62+
When no flags are provided, the server probes localhost ports 8545-8547
63+
for a running JSON-RPC endpoint:
64+
65+
```bash
66+
./build/bin/mcp
67+
```
68+
69+
## Transport Modes
70+
71+
### stdio (default)
72+
73+
Reads MCP protocol messages from stdin and writes to stdout.
74+
This is the standard transport for Claude Desktop and similar tools.
75+
76+
```bash
77+
./build/bin/mcp --port 8545
78+
```
79+
80+
### SSE (Server-Sent Events)
81+
82+
Serves MCP over HTTP with SSE transport:
83+
84+
```bash
85+
./build/bin/mcp --port 8545 --transport sse --sse.addr 127.0.0.1:8553
86+
```
87+
88+
## Claude Desktop Configuration
89+
90+
Add to `~/.config/claude-desktop/config.json`:
91+
92+
```json
93+
{
94+
"mcpServers": {
95+
"erigon": {
96+
"command": "/path/to/build/bin/mcp",
97+
"args": ["--port", "8545", "--log.dir", "/data/erigon/logs"]
98+
}
99+
}
100+
}
101+
```
102+
103+
or
104+
105+
```json
106+
{
107+
"mcpServers": {
108+
"erigon": {
109+
"command": "/path/to/build/bin/mcp",
110+
"args": ["--datadir", "path/to/erigon/data"]
111+
}
112+
}
113+
}
114+
```
115+
116+
for datadir mode.
117+
118+
## Available Tools
119+
120+
### Ethereum Standard (eth_*)
121+
`eth_blockNumber`, `eth_getBlockByNumber`, `eth_getBlockByHash`,
122+
`eth_getBalance`, `eth_getTransactionByHash`, `eth_getTransactionReceipt`,
123+
`eth_getBlockReceipts`, `eth_getLogs`, `eth_getCode`, `eth_getStorageAt`,
124+
`eth_getTransactionCount`, `eth_call`, `eth_estimateGas`, `eth_gasPrice`,
125+
`eth_chainId`, `eth_syncing`, `eth_getProof`, and more.
126+
127+
### Erigon-Specific (erigon_*)
128+
`erigon_forks`, `erigon_blockNumber`, `erigon_getHeaderByNumber`,
129+
`erigon_getHeaderByHash`, `erigon_getBlockByTimestamp`,
130+
`erigon_getBalanceChangesInBlock`, `erigon_getLogsByHash`,
131+
`erigon_getLogs`, `erigon_getBlockReceiptsByBlockHash`, `erigon_nodeInfo`.
132+
133+
### Otterscan (ots_*)
134+
`ots_getApiLevel`, `ots_getInternalOperations`,
135+
`ots_searchTransactionsBefore`, `ots_searchTransactionsAfter`,
136+
`ots_getBlockDetails`, `ots_getBlockTransactions`, `ots_hasCode`,
137+
`ots_traceTransaction`, `ots_getTransactionError`,
138+
`ots_getTransactionBySenderAndNonce`, `ots_getContractCreator`.
139+
140+
### Log Analysis
141+
`logs_tail`, `logs_head`, `logs_grep`, `logs_stats` — requires `--log.dir`
142+
or `--datadir` to locate Erigon/torrent log files.
143+
144+
### Metrics
145+
`metrics_list`, `metrics_get` — only available in embedded mode (inside Erigon).
146+
In standalone mode, these return an informational message.
147+
148+
## Flags
149+
150+
| Flag | Default | Description |
151+
|------|---------|-------------|
152+
| `--rpc.url` | `http://127.0.0.1:8545` | Erigon JSON-RPC endpoint URL |
153+
| `--port` | 0 | JSON-RPC port shorthand |
154+
| `--datadir` | | Erigon data directory (enables direct DB mode) |
155+
| `--private.api.addr` | `127.0.0.1:9090` | gRPC private API (with --datadir) |
156+
| `--transport` | `stdio` | Transport: `stdio` or `sse` |
157+
| `--sse.addr` | `127.0.0.1:8553` | SSE listen address |
158+
| `--log.dir` | | Log directory (overrides datadir detection) |

0 commit comments

Comments
 (0)