@telegraphprotocol/telegraph-protocol-mcp 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.agents/skills/telegraph/SKILL.md +47 -129
  2. package/README.md +66 -366
  3. package/dist/chain.d.ts +60 -0
  4. package/dist/chain.d.ts.map +1 -0
  5. package/dist/chain.js +122 -0
  6. package/dist/chain.js.map +1 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +264 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/config.d.ts +14 -2
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +43 -20
  14. package/dist/config.js.map +1 -1
  15. package/dist/docs.d.ts +9 -0
  16. package/dist/docs.d.ts.map +1 -0
  17. package/dist/docs.js +35 -0
  18. package/dist/docs.js.map +1 -0
  19. package/dist/http.d.ts +3 -0
  20. package/dist/http.d.ts.map +1 -0
  21. package/dist/http.js +20 -0
  22. package/dist/http.js.map +1 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +20 -50
  26. package/dist/index.js.map +1 -1
  27. package/dist/limits.d.ts +20 -0
  28. package/dist/limits.d.ts.map +1 -0
  29. package/dist/limits.js +82 -0
  30. package/dist/limits.js.map +1 -0
  31. package/dist/pay.d.ts +27 -0
  32. package/dist/pay.d.ts.map +1 -0
  33. package/dist/pay.js +159 -0
  34. package/dist/pay.js.map +1 -0
  35. package/dist/tools.d.ts +10 -0
  36. package/dist/tools.d.ts.map +1 -0
  37. package/dist/tools.js +335 -0
  38. package/dist/tools.js.map +1 -0
  39. package/dist/wallet.d.ts +7 -0
  40. package/dist/wallet.d.ts.map +1 -0
  41. package/dist/wallet.js +38 -0
  42. package/dist/wallet.js.map +1 -0
  43. package/guides/1-getting-started.md +42 -0
  44. package/guides/2-payments.md +39 -0
  45. package/guides/3-intents-and-ranking.md +29 -0
  46. package/guides/4-troubleshooting.md +41 -0
  47. package/package.json +11 -14
  48. package/dist/client.d.ts +0 -6
  49. package/dist/client.d.ts.map +0 -1
  50. package/dist/client.js +0 -116
  51. package/dist/client.js.map +0 -1
  52. package/dist/discovery.d.ts +0 -3
  53. package/dist/discovery.d.ts.map +0 -1
  54. package/dist/discovery.js +0 -16
  55. package/dist/discovery.js.map +0 -1
  56. package/dist/schema.d.ts +0 -3
  57. package/dist/schema.d.ts.map +0 -1
  58. package/dist/schema.js +0 -84
  59. package/dist/schema.js.map +0 -1
  60. package/dist/tools/daemon.d.ts +0 -4
  61. package/dist/tools/daemon.d.ts.map +0 -1
  62. package/dist/tools/daemon.js +0 -82
  63. package/dist/tools/daemon.js.map +0 -1
  64. package/dist/tools/engine.d.ts +0 -5
  65. package/dist/tools/engine.d.ts.map +0 -1
  66. package/dist/tools/engine.js +0 -83
  67. package/dist/tools/engine.js.map +0 -1
  68. package/dist/tools/node.d.ts +0 -4
  69. package/dist/tools/node.d.ts.map +0 -1
  70. package/dist/tools/node.js +0 -88
  71. package/dist/tools/node.js.map +0 -1
  72. package/dist/tools/subnets.d.ts +0 -10
  73. package/dist/tools/subnets.d.ts.map +0 -1
  74. package/dist/tools/subnets.js +0 -114
  75. package/dist/tools/subnets.js.map +0 -1
  76. package/dist/transport.d.ts +0 -4
  77. package/dist/transport.d.ts.map +0 -1
  78. package/dist/transport.js +0 -17
  79. package/dist/transport.js.map +0 -1
  80. package/dist/types.d.ts +0 -71
  81. package/dist/types.d.ts.map +0 -1
  82. package/dist/types.js +0 -2
  83. package/dist/types.js.map +0 -1
  84. package/dist/x402.d.ts +0 -3
  85. package/dist/x402.d.ts.map +0 -1
  86. package/dist/x402.js +0 -61
  87. package/dist/x402.js.map +0 -1
package/README.md CHANGED
@@ -1,399 +1,99 @@
1
- # @telegraph/mcp-server
1
+ # Telegraph MCP server
2
2
 
3
- MCP server exposing [Telegraph Protocol](https://github.com/telegraphprotocol/Telegraph) AI inference APIs as tools with automatic x402 micropayments.
3
+ Gives any MCP agent (Claude Desktop, Claude Code, Cursor, Continue, Goose, OpenClaw, LangChain, ElizaOS, ...) the Telegraph network, on your own computer. Ask a question and the best-ranked miner answers. Payment comes from your Telegraph escrow automatically: no keys, signatures or blockchain steps for you or your agent.
4
4
 
5
- Connects any MCP-compatible agent (Claude Desktop, Cursor, ElizaOS, LangChain, OpenClaw, Goose, etc.) to Telegraph's network of AI miners — weather forecasting, deepfake detection, LLM inference, AI-text detection, signal monitoring — with zero crypto code in the agent. The MCP server handles private key custody, payment signing, and transaction settlement internally.
5
+ ## Start in three steps
6
6
 
7
- > Miners can be Bittensor subnets, hosted models, or any private API integrated via YAML. Some tool and field names still say `subnet` for legacy reasons — read it as "miner".
7
+ You need Node 20 or later.
8
8
 
9
- ## Quick Start
10
-
11
- ### Option A — npx (no clone, recommended once published)
12
-
13
- ```bash
14
- TELEGRAPH_NODE_URL=http://13.237.89.59:7044 \
15
- TELEGRAPH_ENGINE_URL=http://13.237.89.59:8080 \
16
- TELEGRAPH_DAEMON_URL=http://13.237.89.59:8081 \
17
- TELEGRAPH_EVM_PRIVATE_KEY=0xyour_key_here \
18
- npx -y telegraph-protocol-mcp
19
- ```
20
-
21
- ### Option B — from source
22
-
23
- ```bash
24
- # 1. Clone and enter
25
- git clone https://github.com/telegraphprotocol/telegraph-mcp
26
- cd telegraph-mcp
27
-
28
- # 2. Copy and edit .env
29
- cp .env.example .env
30
- # Edit: set TELEGRAPH_EVM_PRIVATE_KEY=0xyour_key_here
31
-
32
- # 3. Install and build
33
- npm install && npm run build
34
-
35
- # 4. Run
36
- npm start
37
- ```
38
-
39
- > Published to npm as [`telegraph-protocol-mcp`](https://www.npmjs.com/package/telegraph-protocol-mcp) and listed on the [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.telegraphprotocol/telegraph`. Maintainers: see [PUBLISHING.md](./PUBLISHING.md).
40
-
41
- ## Architecture
42
-
43
- ```
44
- Agent (Claude / Cursor / Eliza / etc.)
45
- │
46
- │ MCP protocol (JSON-RPC over stdio)
47
- │
48
- ┌──────▼─────────────────────────────────────────┐
49
- │ Telegraph MCP Server (runs locally) │
50
- │ │
51
- │ ┌─────────┐ ┌──────────┐ ┌───────────────┐ │
52
- │ │ Node │ │ Engine │ │ Daemon │ │
53
- │ │ :7044 │ │ :8080 │ │ :8081 │ │
54
- │ ├─────────┤ ├──────────┤ ├───────────────┤ │
55
- │ │ Status │ │ Subnets │ │ Health │ │
56
- │ │ Health │ │ Ask │ │ Categories │ │
57
- │ │ Subnets │ │ Direct │ │ Questions │ │
58
- │ │ Dynamic │ │ │ │ │ │
59
- │ └─────────┘ └──────────┘ └───────────────┘ │
60
- │ │
61
- │ X402 payment handled transparently: │
62
- │ request → 402 → sign EIP-3009 → retry │
63
- └─────────────────────────────────────────────────┘
64
- ```
65
-
66
- ## Configuration
67
-
68
- All via environment variables (`.env` file or inline):
69
-
70
- | Variable | Required | Default | Description |
71
- |----------|----------|---------|-------------|
72
- | `TELEGRAPH_NODE_URL` | Yes | `http://localhost:7044` | Telegraph node URL |
73
- | `TELEGRAPH_ENGINE_URL` | Yes | `http://localhost:8080` | Engine server URL |
74
- | `TELEGRAPH_DAEMON_URL` | Yes | `http://localhost:8081` | Daemon API URL |
75
- | `TELEGRAPH_EVM_PRIVATE_KEY` | Yes* | — | EVM private key (`0x`-prefixed hex) |
76
- | `TELEGRAPH_SOLANA_PRIVATE_KEY` | No* | — | Solana private key (base58) |
77
- | `EVM_NETWORK` | No | `eip155:*` | EVM CAIP-2 network |
78
- | `SVM_NETWORK` | No | `solana:*` | Solana CAIP-2 network |
79
- | `REFRESH_INTERVAL_MS` | No | `300000` | Miner-tool refresh interval (ms). 0 to disable. |
80
-
81
- *At least one private key required.
82
-
83
- ## Available Tools
84
-
85
- ### Node Tools (no payment)
86
- | Tool | Description |
87
- |------|-------------|
88
- | `tg_node_status` | Node status, public key, chain info |
89
- | `tg_node_subnets_health` | Miner integration health check |
90
- | `tg_node_list_subnets` | Full miner catalog with metadata, schemas, endpoints |
91
-
92
- ### Engine Tools
93
- | Tool | Payment | Description |
94
- |------|---------|-------------|
95
- | `tg_engine_list_subnets` | Free | List the miners the Engine can route to |
96
- | `tg_engine_ask` | x402 | Auto-routed inference (LLM picks the best miner for your query) |
97
- | `tg_engine_ask_subnet` | x402 | Direct inference through a specific miner by ID |
98
-
99
- ### Daemon Tools (no payment)
100
- | Tool | Description |
101
- |------|-------------|
102
- | `tg_daemon_health` | Daemon health check |
103
- | `tg_daemon_categories` | Signal categories (POLITICS, ECONOMICS, TECHNOLOGY, CLIMATE, HEALTH, CRYPTO, SPORTS, …) |
104
- | `tg_daemon_questions` | Query collected signals with filters (category, source, time, interest) |
105
-
106
- ### Dynamic Miner Tools (auto-discovered, x402 payment)
107
- Tools for each miner endpoint are auto-generated from the Telegraph node's live integration registry. The live set changes on-chain, so treat this as a snapshot, not the source of truth (call `tg_node_list_subnets` for the current catalog):
108
-
109
- | Miner | Tools |
110
- |--------|-------|
111
- | **Zeus (18)** — Weather | `tg_zeus_predict` |
112
- | **ItsAI (32)** — AI text detection | `tg_itsai_text_detector_detect` |
113
- | **Sapling (33)** — AI content detection | `tg_sapling_ai_detector_detect` |
114
- | **BitMind (34)** — Deepfake | `tg_bitmind_detect_image`, `tg_bitmind_detect_video`, `tg_bitmind_preprocess_video`, `tg_bitmind_get_video_upload_url` |
115
- | **OpenAI (102)** — LLM / images | `tg_openai_chat`, `tg_openai_responses`, `tg_openai_embed`, `tg_openai_images_generate`, `tg_openai_moderate` |
116
-
117
- **These update automatically.** New miners registered on-chain appear within 5 minutes. Deregistered miners are cleaned up. The agent always sees only currently valid tools.
118
-
119
- > Some tool and field names contain `subnet` for legacy reasons — Telegraph began by integrating Bittensor subnets. Today a **miner** is any provider integrated via YAML, subnet or not.
120
-
121
- ## How x402 Payments Work
122
-
123
- When an agent calls a paid tool (e.g., `tg_engine_ask`):
124
-
125
- 1. MCP server sends request to Telegraph
126
- 2. Telegraph returns HTTP 402 with payment requirements in response header
127
- 3. `@x402/fetch` intercepts the 402, signs an EIP-3009 `TransferWithAuthorization` using your private key, attaches the signature as a `PAYMENT` header, and retries
128
- 4. Telegraph verifies the payment on-chain via the PayAI facilitator and returns the result
129
-
130
- **The agent and LLM never see the payment flow, private key, or blockchain transaction.** It's fully transparent — the agent just sees a tool that returns results.
131
-
132
- ## Integration Guides
133
-
134
- ### Claude Desktop
135
-
136
- Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows).
137
-
138
- Using npx (simplest — no clone or build):
139
-
140
- ```json
141
- {
142
- "mcpServers": {
143
- "telegraph": {
144
- "command": "npx",
145
- "args": ["-y", "telegraph-protocol-mcp"],
146
- "env": {
147
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
148
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
149
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
150
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
151
- }
152
- }
153
- }
154
- }
155
- ```
156
-
157
- Or pointing at a local build:
158
-
159
- ```json
160
- {
161
- "mcpServers": {
162
- "telegraph": {
163
- "command": "node",
164
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
165
- "env": {
166
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
167
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
168
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
169
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
170
- }
171
- }
172
- }
173
- }
174
- ```
175
-
176
- Restart Claude Desktop. The Telegraph tools will appear in the tool list. Try asking *"What's the weather in Lahore?"* or *"Use the Telegraph engine to explain what Bitcoin is."*
177
-
178
- ### Cursor
179
-
180
- Add to Cursor Settings → MCP → Add new MCP server:
181
-
182
- ```json
183
- {
184
- "mcpServers": {
185
- "telegraph": {
186
- "command": "node",
187
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
188
- "env": {
189
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
190
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
191
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
192
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
193
- }
194
- }
195
- }
196
- }
197
- ```
198
-
199
- ### ElizaOS
200
-
201
- In your Eliza character file or MCP plugin config:
202
-
203
- ```json
204
- {
205
- "mcp": {
206
- "telegraph": {
207
- "command": "node",
208
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
209
- "env": {
210
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
211
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
212
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
213
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
214
- }
215
- }
216
- }
217
- }
218
- ```
219
-
220
- ElizaOS v0.25+ supports MCP via the `@elizaos/plugin-mcp` package. Enable it in your character's plugin list:
221
-
222
- ```json
223
- {
224
- "plugins": ["@elizaos/plugin-mcp"]
225
- }
226
- ```
227
-
228
- ### LangChain / LangGraph
229
-
230
- LangChain supports MCP through `langchain-mcp-adapters`:
9
+ **1. Set up once.** In a terminal:
231
10
 
232
11
  ```bash
233
- pip install langchain-mcp-adapters
12
+ npx -y @telegraphprotocol/telegraph-protocol-mcp setup
234
13
  ```
235
14
 
236
- ```python
237
- from langchain_mcp_adapters.client import MultiServerMCPClient
15
+ It checks the network and creates a wallet just for Telegraph. You can import a key instead. The wallet is saved to `~/.telegraph/wallet.json`, readable only by you. Setup then shows the address and balances, moves the USDC you choose into escrow after you confirm, and offers to add Telegraph to your agent app.
238
16
 
239
- client = MultiServerMCPClient({
240
- "telegraph": {
241
- "command": "node",
242
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
243
- "env": {
244
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
245
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
246
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
247
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here",
248
- },
249
- "transport": "stdio",
250
- }
251
- })
17
+ **2. Restart your agent app.**
252
18
 
253
- tools = client.get_tools()
254
- # Use tools with your LangChain agent
255
- ```
19
+ **3. Ask it something:** "What is the BTC price? Use Telegraph." Every ask after that is paid from escrow on its own.
256
20
 
257
- TypeScript/Node.js:
21
+ Top up any time with `npx -y @telegraphprotocol/telegraph-protocol-mcp fund`. Check balances with `... status`.
22
+ Take USDC back out with `... withdraw`: it requests the amount, and you run it again to collect once the network has settled it.
258
23
 
259
- ```bash
260
- npm install @langchain/mcp-adapters
261
- ```
24
+ Back up `~/.telegraph/wallet.json`. It is the only copy of the key, and the escrow balance goes with it.
262
25
 
263
- ```typescript
264
- import { MultiServerMCPClient } from "@langchain/mcp-adapters";
26
+ ## Adding it to an app by hand
265
27
 
266
- const client = new MultiServerMCPClient({
267
- telegraph: {
268
- command: "node",
269
- args: ["/path/to/telegraph-mcp/dist/index.js"],
270
- env: {
271
- TELEGRAPH_NODE_URL: "http://13.237.89.59:7044",
272
- TELEGRAPH_ENGINE_URL: "http://13.237.89.59:8080",
273
- TELEGRAPH_DAEMON_URL: "http://13.237.89.59:8081",
274
- TELEGRAPH_EVM_PRIVATE_KEY: "0xyour_key_here",
275
- },
276
- transport: "stdio",
277
- },
278
- });
28
+ No setting or key is needed: the server uses the wallet from setup. `setup` and `install <app>` write these for you where they can.
279
29
 
280
- const tools = await client.getTools();
281
- ```
30
+ | App | How |
31
+ |---|---|
32
+ | Claude Code | `claude mcp add --scope user telegraph -- npx -y @telegraphprotocol/telegraph-protocol-mcp` |
33
+ | Claude Desktop, Cursor, any other MCP client | Add to `mcpServers`: `{"telegraph": {"command": "npx", "args": ["-y", "@telegraphprotocol/telegraph-protocol-mcp"]}}` |
34
+ | OpenClaw | `openclaw mcp add telegraph --command npx --arg=-y --arg @telegraphprotocol/telegraph-protocol-mcp` |
35
+ | Continue, Goose, LangChain, ElizaOS | Ready files in [examples/](examples/) |
282
36
 
283
- ### OpenClaw
37
+ ## How paying works
284
38
 
285
- OpenClaw natively supports MCP via configuration. Add to `openclaw.config.json`:
39
+ - **The MCP server is your wallet.** It runs on your machine, loads the key from `~/.telegraph/wallet.json` (or `TELEGRAPH_PRIVATE_KEY`), and calls the node's `/engine/v1/ask` itself. When the node asks for payment, the server signs the escrow authorization with that key and sends the ask again. The agent never sees the key or the signature.
40
+ - **Escrow, always, by default.** You deposit USDC once. The escrow signature proves you asked, but it can't move funds. Asks are deducted at the epoch close, and **a failed ask is never billed**.
41
+ - **When escrow runs low,** the ask is refused with a message saying how much is left and how to top up. Nothing is charged, and the wallet is never paid from silently.
42
+ - **No double charges.** Repeating the same ask within a minute, or while it's still running, returns that answer, not a second charge.
43
+ - **Limits.** The server won't pay more than $0.50 for one ask or $5 a day. Change them with the settings below.
44
+ - **x402** (paying each ask straight from the wallet's USDC) is still there, but only if you turn it on: `TELEGRAPH_PAYMENT=auto` for escrow then x402, or `x402` for x402 only.
286
45
 
287
- ```json
288
- {
289
- "mcpServers": {
290
- "telegraph": {
291
- "type": "stdio",
292
- "command": "node",
293
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
294
- "env": {
295
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
296
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
297
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
298
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
299
- }
300
- }
301
- }
302
- }
303
- ```
46
+ Details, debt and withdrawing: [guides/2-payments.md](guides/2-payments.md).
304
47
 
305
- ### Goose
48
+ ## Settings
306
49
 
307
- Goose supports MCP servers through its extensions system. Configuration in `~/.config/goose/config.yaml`:
50
+ All optional.
308
51
 
309
- ```yaml
310
- extensions:
311
- telegraph:
312
- type: mcp
313
- command: node
314
- args:
315
- - /path/to/telegraph-mcp/dist/index.js
316
- env:
317
- TELEGRAPH_NODE_URL: http://13.237.89.59:7044
318
- TELEGRAPH_ENGINE_URL: http://13.237.89.59:8080
319
- TELEGRAPH_DAEMON_URL: http://13.237.89.59:8081
320
- TELEGRAPH_EVM_PRIVATE_KEY: 0xyour_key_here
321
- ```
52
+ | Variable | Default | What it is |
53
+ |---|---|---|
54
+ | `TELEGRAPH_PAYMENT` | `escrow` | `escrow`; `auto` (escrow, then x402); `x402` |
55
+ | `TELEGRAPH_MAX_ASK_USD` | `0.5` | The most one ask may cost. `0` means no limit |
56
+ | `TELEGRAPH_DAILY_LIMIT_USD` | `5` | The most all asks may cost in a UTC day. `0` means no limit |
57
+ | `TELEGRAPH_HOME` | `~/.telegraph` | Where the wallet and the day's spending are kept |
58
+ | `TELEGRAPH_PRIVATE_KEY` | none | Use this key instead of the wallet file. For servers and CI. (`TELEGRAPH_EVM_PRIVATE_KEY`, the v1 name, also works.) |
59
+ | `TELEGRAPH_ALLOW_AGENT_DEPOSIT` | off | Also give the agent a `telegraph_deposit` tool |
60
+ | `TELEGRAPH_URL` | `https://devnode.telegraphprotocol.com` | The node (Telegraph beta 2) |
61
+ | `TELEGRAPH_RPC_URL`, `TELEGRAPH_DIAMOND`, `TELEGRAPH_CHAIN_ID` | beta 2's | The chain and the contract that holds escrow |
322
62
 
323
- ### VS Code / Continue
63
+ ## Tools
324
64
 
325
- In Continue's `config.json`:
65
+ | Tool | Cost | What it does |
66
+ |---|---|---|
67
+ | `telegraph_ask` | ~$0.01 | Ask a question, optionally with an exact intent and params. The node routes it to the top live miner |
68
+ | `telegraph_ask_miner` | the miner's price | Ask one miner you choose, or call one of its endpoints directly |
69
+ | `telegraph_find_intents` | free | Search the 130+ intents (kinds of question) |
70
+ | `telegraph_intent` | free | One intent's kind, params, answer fields and top miners |
71
+ | `telegraph_find_miners` | free | An intent's miners with rank, score, price and endpoints, or a word search over all miners |
72
+ | `telegraph_ranking` | free | The latest epoch's ranking, per intent |
73
+ | `telegraph_account` | free | Address, network, wallet and escrow balances, limits, spending today, and how to top up |
74
+ | `telegraph_docs` | free | Built-in guides, also served as MCP resources (`telegraph://docs/...`) |
75
+ | `telegraph_deposit` | gas | Only with `TELEGRAPH_ALLOW_AGENT_DEPOSIT`: move wallet USDC into escrow |
326
76
 
327
- ```json
328
- {
329
- "experimental": {
330
- "modelContextProtocolServers": [
331
- {
332
- "transport": {
333
- "type": "stdio",
334
- "command": "node",
335
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
336
- "env": {
337
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
338
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
339
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
340
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
341
- }
342
- }
343
- }
344
- ]
345
- }
346
- }
347
- ```
77
+ ## Test funds (beta 2)
348
78
 
349
- ### Generic / Any MCP Client
350
-
351
- The server uses **MCP stdio transport** — the standard for local MCP servers. Any client that supports the MCP protocol over stdio can use it:
352
-
353
- ```json
354
- {
355
- "mcpServers": {
356
- "telegraph": {
357
- "command": "node",
358
- "args": ["/path/to/telegraph-mcp/dist/index.js"],
359
- "env": {
360
- "TELEGRAPH_NODE_URL": "http://13.237.89.59:7044",
361
- "TELEGRAPH_ENGINE_URL": "http://13.237.89.59:8080",
362
- "TELEGRAPH_DAEMON_URL": "http://13.237.89.59:8081",
363
- "TELEGRAPH_EVM_PRIVATE_KEY": "0xyour_key_here"
364
- }
365
- }
366
- }
367
- }
368
- ```
369
-
370
- ## Dynamic Tool Discovery
371
-
372
- Subnet tools are **not hardcoded**. On startup and every 5 minutes:
373
-
374
- 1. Fetches live integrations from `GET /miner-dispatcher/integrations` on the Telegraph node
375
- 2. Diffs against currently registered tools
376
- 3. Adds new subnets → auto-registers tools
377
- 4. Removes stale subnets → deletes tools
378
- 5. Sends `notifications/tools/list_changed` to connected clients
379
-
380
- This means:
381
- - **New subnets** appear automatically within 5 minutes of on-chain registration — no MCP restart needed
382
- - **Removed subnets** are cleaned up — agents won't call non-existent tools
383
- - **Agents always have an accurate view** of what's available on the network
79
+ Beta 2 runs on Ethereum Sepolia, so there's no real money. Its USDC (`0xcc194e1a843B658526D0D5C431f670028582Ae17`) is Telegraph's own test token, not Circle's: the escrow takes that one and no other, and `telegraph_account` names it. Claim it at [anjoman.ai/dashboard/faucet](https://anjoman.ai/dashboard/faucet): sign in, send it to your Telegraph wallet, 1 USDC per account every 24 hours. `fund` points you there. Gas needs a little Sepolia ETH from a public faucet.
384
80
 
385
81
  ## Security
386
82
 
387
- - **Use a burner wallet.** Never use your main wallet. Fund with only the USDC needed for inference.
388
- - **The private key stays in the MCP process.** Never exposed to the agent or LLM.
389
- - **The MCP server runs locally** over stdio — no network exposure.
390
- - Payments are per-call: typically $0.01 per inference request.
83
+ - The key lives in `~/.telegraph/wallet.json` (mode 0600), or in `TELEGRAPH_PRIVATE_KEY` if you set one. It's never in an agent's config, a tool result or a log, so the agent and its model never see it through MCP.
84
+ - Use a wallet made for this, holding only what you plan to spend. The limits cap what the agent can spend.
85
+ - By default the agent gets no tool that moves funds: deposits and withdrawals happen in your terminal, after you confirm.
86
+ - That holds for the tools. An agent that can also run shell commands (Claude Code, Cursor, Goose) can read the wallet file or run `fund` itself, so the real protection is the dedicated wallet and the limits, not the tool list.
87
+ - The server runs locally over stdio and opens no port.
391
88
 
392
89
  ## Development
393
90
 
394
91
  ```bash
395
- npm install # Install deps
396
- npm run build # Compile TypeScript
397
- npm run dev # Dev mode with tsx (hot reload)
398
- npx @modelcontextprotocol/inspector dist/index.js # Inspect tools
92
+ npm install && npm run build && npm test
93
+ node scripts/smoke.mjs # free tools against the node
94
+ node scripts/smoke.mjs paid # plus three asks (~$0.03), using the setup wallet
95
+ node scripts/smoke.mjs call telegraph_intent '{"intent":"CRYPTO_PRICE_USD"}'
96
+ npx @modelcontextprotocol/inspector dist/index.js # browse the tools
399
97
  ```
98
+
99
+ Architecture: [docs/architecture.md](docs/architecture.md). Problems: [docs/troubleshooting.md](docs/troubleshooting.md).
@@ -0,0 +1,60 @@
1
+ import type { PrivateKeyAccount } from "viem/accounts";
2
+ import type { Config } from "./config.js";
3
+ export declare class Chain {
4
+ private cfg;
5
+ private chain;
6
+ private pub;
7
+ private usdc?;
8
+ constructor(cfg: Config);
9
+ private usdcAddress;
10
+ account(address: `0x${string}`): Promise<{
11
+ address: `0x${string}`;
12
+ network: string;
13
+ usdc_token: `0x${string}`;
14
+ escrow_contract: `0x${string}`;
15
+ wallet_usdc: number;
16
+ wallet_eth: number;
17
+ escrow: {
18
+ spendable_usdc: number;
19
+ deposited_usdc: number;
20
+ debt_usdc: number;
21
+ pending_withdrawal_usdc: number;
22
+ };
23
+ }>;
24
+ deposit(account: PrivateKeyAccount, amountUsd: number): Promise<{
25
+ amount_usdc: number;
26
+ transactions: string[];
27
+ escrow_now: {
28
+ spendable_usdc: number;
29
+ deposited_usdc: number;
30
+ debt_usdc: number;
31
+ pending_withdrawal_usdc: number;
32
+ };
33
+ }>;
34
+ withdrawalUnlock(address: `0x${string}`): Promise<{
35
+ unlockSequence: bigint;
36
+ unlockAt: Date;
37
+ unlocked: boolean;
38
+ }>;
39
+ requestWithdraw(account: PrivateKeyAccount, amountUsd: number): Promise<{
40
+ amount_usdc: number;
41
+ transaction: `0x${string}`;
42
+ unlock: {
43
+ unlockSequence: bigint;
44
+ unlockAt: Date;
45
+ unlocked: boolean;
46
+ };
47
+ }>;
48
+ executeWithdraw(account: PrivateKeyAccount): Promise<{
49
+ transaction: `0x${string}`;
50
+ wallet_usdc: number;
51
+ escrow_now: {
52
+ spendable_usdc: number;
53
+ deposited_usdc: number;
54
+ debt_usdc: number;
55
+ pending_withdrawal_usdc: number;
56
+ };
57
+ }>;
58
+ private waitOk;
59
+ }
60
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAuB1C,qBAAa,KAAK;IAKJ,OAAO,CAAC,GAAG;IAJvB,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,GAAG,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,CAAgB;gBAET,GAAG,EAAE,MAAM;YAUjB,WAAW;IAKnB,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE;;;;;;;;;;;;;;IA+B9B,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;IA0BrD,gBAAgB,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE;;;;;IAUvC,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;IAQ7D,eAAe,CAAC,OAAO,EAAE,iBAAiB;;;;;;;;;;YAQlC,MAAM;CAIrB"}
package/dist/chain.js ADDED
@@ -0,0 +1,122 @@
1
+ import { createPublicClient, createWalletClient, defineChain, formatUnits, http, parseAbi, parseUnits } from "viem";
2
+ const escrowAbi = parseAbi([
3
+ "function usdcToken() view returns (address)",
4
+ "function effectiveBalance(address user) view returns (uint256)",
5
+ "function escrowBalance(address user) view returns (uint256)",
6
+ "function agentDebt(address user) view returns (uint256)",
7
+ "function pendingWithdrawal(address user) view returns (uint256 amount, uint256 unlockTime)",
8
+ "function withdrawalUnlock(address user) view returns (uint256 unlockSequence, uint256 unlockTime, bool unlocked)",
9
+ "function depositUSDC(uint256 amount)",
10
+ "function requestWithdraw(uint256 amount)",
11
+ "function executeWithdraw()",
12
+ "function cancelWithdraw()",
13
+ ]);
14
+ const erc20Abi = parseAbi([
15
+ "function balanceOf(address owner) view returns (uint256)",
16
+ "function allowance(address owner, address spender) view returns (uint256)",
17
+ "function approve(address spender, uint256 amount) returns (bool)",
18
+ ]);
19
+ const usd = (v) => Number(formatUnits(v, 6));
20
+ export class Chain {
21
+ cfg;
22
+ chain;
23
+ pub;
24
+ usdc;
25
+ constructor(cfg) {
26
+ this.cfg = cfg;
27
+ this.chain = defineChain({
28
+ id: cfg.chainId,
29
+ name: `eip155:${cfg.chainId}`,
30
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
31
+ rpcUrls: { default: { http: [cfg.rpcUrl] } },
32
+ });
33
+ this.pub = createPublicClient({ chain: this.chain, transport: http(cfg.rpcUrl) });
34
+ }
35
+ async usdcAddress() {
36
+ this.usdc ??= await this.pub.readContract({ address: this.cfg.diamond, abi: escrowAbi, functionName: "usdcToken" });
37
+ return this.usdc;
38
+ }
39
+ async account(address) {
40
+ const usdc = await this.usdcAddress();
41
+ const read = (functionName) => this.pub.readContract({ address: this.cfg.diamond, abi: escrowAbi, functionName, args: [address] });
42
+ const [wallet, eth, spendable, deposited, debt, pending] = await Promise.all([
43
+ this.pub.readContract({ address: usdc, abi: erc20Abi, functionName: "balanceOf", args: [address] }),
44
+ this.pub.getBalance({ address }),
45
+ read("effectiveBalance"),
46
+ read("escrowBalance"),
47
+ read("agentDebt"),
48
+ this.pub.readContract({ address: this.cfg.diamond, abi: escrowAbi, functionName: "pendingWithdrawal", args: [address] }),
49
+ ]);
50
+ return {
51
+ address,
52
+ network: `eip155:${this.cfg.chainId}`,
53
+ // Which token is actually spent, and which contract holds the escrow:
54
+ // both read from the chain, so they follow the node's network.
55
+ usdc_token: usdc,
56
+ escrow_contract: this.cfg.diamond,
57
+ wallet_usdc: usd(wallet),
58
+ wallet_eth: Number(formatUnits(eth, 18)),
59
+ escrow: {
60
+ spendable_usdc: usd(spendable),
61
+ deposited_usdc: usd(deposited),
62
+ debt_usdc: usd(debt),
63
+ pending_withdrawal_usdc: usd(pending[0]),
64
+ },
65
+ };
66
+ }
67
+ // approve (when the allowance is short) then depositUSDC, waiting for each.
68
+ async deposit(account, amountUsd) {
69
+ const amount = parseUnits(amountUsd.toFixed(6), 6);
70
+ const usdc = await this.usdcAddress();
71
+ const have = await this.pub.readContract({ address: usdc, abi: erc20Abi, functionName: "balanceOf", args: [account.address] });
72
+ if (have < amount)
73
+ throw new Error(`The wallet holds ${usd(have)} USDC, less than ${amountUsd}.`);
74
+ const wallet = createWalletClient({ account, chain: this.chain, transport: http(this.cfg.rpcUrl) });
75
+ // Explicit nonces: some public RPCs hand back a stale pending nonce.
76
+ let nonce = await this.pub.getTransactionCount({ address: account.address, blockTag: "pending" });
77
+ const txs = [];
78
+ const allowance = await this.pub.readContract({
79
+ address: usdc, abi: erc20Abi, functionName: "allowance", args: [account.address, this.cfg.diamond],
80
+ });
81
+ if (allowance < amount) {
82
+ const hash = await wallet.writeContract({ address: usdc, abi: erc20Abi, functionName: "approve", args: [this.cfg.diamond, amount], nonce: nonce++ });
83
+ await this.waitOk(hash, "approve");
84
+ txs.push(hash);
85
+ }
86
+ const hash = await wallet.writeContract({ address: this.cfg.diamond, abi: escrowAbi, functionName: "depositUSDC", args: [amount], nonce });
87
+ await this.waitOk(hash, "depositUSDC");
88
+ txs.push(hash);
89
+ return { amount_usdc: amountUsd, transactions: txs, escrow_now: (await this.account(account.address)).escrow };
90
+ }
91
+ // When a pending withdrawal may be executed: once `withdrawBlocks` more
92
+ // settlement blocks pass, or at `unlockTime`, whichever comes first.
93
+ async withdrawalUnlock(address) {
94
+ const [unlockSequence, unlockTime, unlocked] = await this.pub.readContract({
95
+ address: this.cfg.diamond, abi: escrowAbi, functionName: "withdrawalUnlock", args: [address],
96
+ });
97
+ return { unlockSequence, unlockAt: new Date(Number(unlockTime) * 1000), unlocked };
98
+ }
99
+ // Taking money out is two steps on chain, with a wait between them: the
100
+ // amount leaves the spendable balance at once, and settlement still collects
101
+ // what the agent already owes from it.
102
+ async requestWithdraw(account, amountUsd) {
103
+ const amount = parseUnits(amountUsd.toFixed(6), 6);
104
+ const wallet = createWalletClient({ account, chain: this.chain, transport: http(this.cfg.rpcUrl) });
105
+ const hash = await wallet.writeContract({ address: this.cfg.diamond, abi: escrowAbi, functionName: "requestWithdraw", args: [amount] });
106
+ await this.waitOk(hash, "requestWithdraw");
107
+ return { amount_usdc: amountUsd, transaction: hash, unlock: await this.withdrawalUnlock(account.address) };
108
+ }
109
+ async executeWithdraw(account) {
110
+ const wallet = createWalletClient({ account, chain: this.chain, transport: http(this.cfg.rpcUrl) });
111
+ const hash = await wallet.writeContract({ address: this.cfg.diamond, abi: escrowAbi, functionName: "executeWithdraw" });
112
+ await this.waitOk(hash, "executeWithdraw");
113
+ const after = await this.account(account.address);
114
+ return { transaction: hash, wallet_usdc: after.wallet_usdc, escrow_now: after.escrow };
115
+ }
116
+ async waitOk(hash, what) {
117
+ const r = await this.pub.waitForTransactionReceipt({ hash, timeout: 180_000 });
118
+ if (r.status !== "success")
119
+ throw new Error(`${what} reverted (tx ${hash})`);
120
+ }
121
+ }
122
+ //# sourceMappingURL=chain.js.map