@telegraphprotocol/telegraph-protocol-mcp 1.0.0 → 2.1.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 (91) hide show
  1. package/.agents/skills/telegraph/SKILL.md +47 -129
  2. package/README.md +78 -358
  3. package/dist/api.d.ts +35 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +81 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/chain.d.ts +60 -0
  8. package/dist/chain.d.ts.map +1 -0
  9. package/dist/chain.js +122 -0
  10. package/dist/chain.js.map +1 -0
  11. package/dist/cli.d.ts +2 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +264 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/config.d.ts +16 -2
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +50 -20
  18. package/dist/config.js.map +1 -1
  19. package/dist/docs.d.ts +9 -0
  20. package/dist/docs.d.ts.map +1 -0
  21. package/dist/docs.js +35 -0
  22. package/dist/docs.js.map +1 -0
  23. package/dist/http.d.ts +3 -0
  24. package/dist/http.d.ts.map +1 -0
  25. package/dist/http.js +20 -0
  26. package/dist/http.js.map +1 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +24 -50
  30. package/dist/index.js.map +1 -1
  31. package/dist/limits.d.ts +20 -0
  32. package/dist/limits.d.ts.map +1 -0
  33. package/dist/limits.js +82 -0
  34. package/dist/limits.js.map +1 -0
  35. package/dist/pay.d.ts +27 -0
  36. package/dist/pay.d.ts.map +1 -0
  37. package/dist/pay.js +159 -0
  38. package/dist/pay.js.map +1 -0
  39. package/dist/tools.d.ts +20 -0
  40. package/dist/tools.d.ts.map +1 -0
  41. package/dist/tools.js +370 -0
  42. package/dist/tools.js.map +1 -0
  43. package/dist/wallet.d.ts +7 -0
  44. package/dist/wallet.d.ts.map +1 -0
  45. package/dist/wallet.js +38 -0
  46. package/dist/wallet.js.map +1 -0
  47. package/guides/1-getting-started.md +42 -0
  48. package/guides/2-payments.md +43 -0
  49. package/guides/3-intents-and-ranking.md +29 -0
  50. package/guides/4-troubleshooting.md +41 -0
  51. package/package.json +11 -14
  52. package/dist/client.d.ts +0 -6
  53. package/dist/client.d.ts.map +0 -1
  54. package/dist/client.js +0 -116
  55. package/dist/client.js.map +0 -1
  56. package/dist/discovery.d.ts +0 -3
  57. package/dist/discovery.d.ts.map +0 -1
  58. package/dist/discovery.js +0 -16
  59. package/dist/discovery.js.map +0 -1
  60. package/dist/schema.d.ts +0 -3
  61. package/dist/schema.d.ts.map +0 -1
  62. package/dist/schema.js +0 -84
  63. package/dist/schema.js.map +0 -1
  64. package/dist/tools/daemon.d.ts +0 -4
  65. package/dist/tools/daemon.d.ts.map +0 -1
  66. package/dist/tools/daemon.js +0 -82
  67. package/dist/tools/daemon.js.map +0 -1
  68. package/dist/tools/engine.d.ts +0 -5
  69. package/dist/tools/engine.d.ts.map +0 -1
  70. package/dist/tools/engine.js +0 -83
  71. package/dist/tools/engine.js.map +0 -1
  72. package/dist/tools/node.d.ts +0 -4
  73. package/dist/tools/node.d.ts.map +0 -1
  74. package/dist/tools/node.js +0 -88
  75. package/dist/tools/node.js.map +0 -1
  76. package/dist/tools/subnets.d.ts +0 -10
  77. package/dist/tools/subnets.d.ts.map +0 -1
  78. package/dist/tools/subnets.js +0 -114
  79. package/dist/tools/subnets.js.map +0 -1
  80. package/dist/transport.d.ts +0 -4
  81. package/dist/transport.d.ts.map +0 -1
  82. package/dist/transport.js +0 -17
  83. package/dist/transport.js.map +0 -1
  84. package/dist/types.d.ts +0 -71
  85. package/dist/types.d.ts.map +0 -1
  86. package/dist/types.js +0 -2
  87. package/dist/types.js.map +0 -1
  88. package/dist/x402.d.ts +0 -3
  89. package/dist/x402.d.ts.map +0 -1
  90. package/dist/x402.js +0 -61
  91. package/dist/x402.js.map +0 -1
package/README.md CHANGED
@@ -1,399 +1,119 @@
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
9
+ **1. Set up once.** In a terminal:
22
10
 
23
11
  ```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
- }
12
+ npx -y @telegraphprotocol/telegraph-protocol-mcp setup
174
13
  ```
175
14
 
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
- ```
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.
219
16
 
220
- ElizaOS v0.25+ supports MCP via the `@elizaos/plugin-mcp` package. Enable it in your character's plugin list:
17
+ **2. Restart your agent app.**
221
18
 
222
- ```json
223
- {
224
- "plugins": ["@elizaos/plugin-mcp"]
225
- }
226
- ```
19
+ **3. Ask it something:** "What is the BTC price? Use Telegraph." Every ask after that is paid from escrow on its own.
227
20
 
228
- ### LangChain / LangGraph
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.
229
23
 
230
- LangChain supports MCP through `langchain-mcp-adapters`:
24
+ Back up `~/.telegraph/wallet.json`. It is the only copy of the key, and the escrow balance goes with it.
231
25
 
232
- ```bash
233
- pip install langchain-mcp-adapters
234
- ```
26
+ ## Adding it to an app by hand
235
27
 
236
- ```python
237
- from langchain_mcp_adapters.client import MultiServerMCPClient
238
-
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
- })
252
-
253
- tools = client.get_tools()
254
- # Use tools with your LangChain agent
255
- ```
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.
256
29
 
257
- TypeScript/Node.js:
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/) |
258
36
 
259
- ```bash
260
- npm install @langchain/mcp-adapters
261
- ```
37
+ ## How paying works
262
38
 
263
- ```typescript
264
- import { MultiServerMCPClient } from "@langchain/mcp-adapters";
265
-
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
- });
279
-
280
- const tools = await client.getTools();
281
- ```
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.
282
45
 
283
- ### OpenClaw
46
+ Details, debt and withdrawing: [guides/2-payments.md](guides/2-payments.md).
284
47
 
285
- OpenClaw natively supports MCP via configuration. Add to `openclaw.config.json`:
48
+ ## Settings
286
49
 
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
- ```
50
+ All optional.
304
51
 
305
- ### Goose
306
-
307
- Goose supports MCP servers through its extensions system. Configuration in `~/.config/goose/config.yaml`:
308
-
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_API_KEY` | none | An Anjoman API key (`tgk_…`). Switches to [key mode](#using-an-api-key-instead-of-a-wallet): no wallet is used |
60
+ | `TELEGRAPH_API_URL` | `https://backend.telegraphprotocol.com` | Where the API key is used |
61
+ | `TELEGRAPH_ALLOW_AGENT_DEPOSIT` | off | Also give the agent a `telegraph_deposit` tool |
62
+ | `TELEGRAPH_URL` | `https://devnode.telegraphprotocol.com` | The node (Telegraph beta 2) |
63
+ | `TELEGRAPH_RPC_URL`, `TELEGRAPH_DIAMOND`, `TELEGRAPH_CHAIN_ID` | beta 2's | The chain and the contract that holds escrow |
322
64
 
323
- ### VS Code / Continue
65
+ ## Using an API key instead of a wallet
324
66
 
325
- In Continue's `config.json`:
67
+ If you have an Anjoman account, you can skip the wallet. Create a key on the **API keys** page (`https://anjoman.ai/dashboard/api-keys`), deposit into your account there, and set it in your agent's settings:
326
68
 
327
69
  ```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
- }
70
+ {"mcpServers": {"telegraph": {"command": "npx", "args": ["-y", "@telegraphprotocol/telegraph-protocol-mcp"], "env": {"TELEGRAPH_API_KEY": "tgk_your_key_here"}}}}
347
71
  ```
348
72
 
349
- ### Generic / Any MCP Client
73
+ No `setup` is needed. In key mode:
350
74
 
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:
75
+ - `telegraph_ask` goes through your Anjoman account, which picks the sources, can combine several for one question, and writes the answer. It is paid from the account's escrow balance. A question can take up to a minute.
76
+ - `telegraph_account` shows the account's escrow balance and what its last jobs cost. Top up in Anjoman: this server cannot deposit.
77
+ - `telegraph_ask_miner` and `telegraph_deposit` are not offered: a key cannot call one miner directly or move funds.
78
+ - The free tools (`telegraph_find_intents`, `telegraph_intent`, `telegraph_find_miners`, `telegraph_ranking`, `telegraph_docs`) work as before.
79
+ - The wallet, `TELEGRAPH_PAYMENT` and the per-ask and daily limits do not apply. The account's balance and the key's own limits (30 requests a minute, an optional expiry) do. Revoke the key in Anjoman to cut off an agent at once.
352
80
 
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
- ```
81
+ Treat the key like a password: it can spend your balance. Keep it in an agent's settings, not in a repository.
369
82
 
370
- ## Dynamic Tool Discovery
83
+ ## Tools
371
84
 
372
- Subnet tools are **not hardcoded**. On startup and every 5 minutes:
85
+ | Tool | Cost | What it does |
86
+ |---|---|---|
87
+ | `telegraph_ask` | ~$0.01 | Ask a question, optionally with an exact intent and params. The node routes it to the top live miner |
88
+ | `telegraph_ask_miner` | the miner's price | Ask one miner you choose, or call one of its endpoints directly |
89
+ | `telegraph_find_intents` | free | Search the 130+ intents (kinds of question) |
90
+ | `telegraph_intent` | free | One intent's kind, params, answer fields and top miners |
91
+ | `telegraph_find_miners` | free | An intent's miners with rank, score, price and endpoints, or a word search over all miners |
92
+ | `telegraph_ranking` | free | The latest epoch's ranking, per intent |
93
+ | `telegraph_account` | free | Address, network, wallet and escrow balances, limits, spending today, and how to top up |
94
+ | `telegraph_docs` | free | Built-in guides, also served as MCP resources (`telegraph://docs/...`) |
95
+ | `telegraph_deposit` | gas | Only with `TELEGRAPH_ALLOW_AGENT_DEPOSIT`: move wallet USDC into escrow |
373
96
 
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
97
+ ## Test funds (beta 2)
379
98
 
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
99
+ 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
100
 
385
101
  ## Security
386
102
 
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.
103
+ - 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.
104
+ - Use a wallet made for this, holding only what you plan to spend. The limits cap what the agent can spend.
105
+ - By default the agent gets no tool that moves funds: deposits and withdrawals happen in your terminal, after you confirm.
106
+ - 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.
107
+ - The server runs locally over stdio and opens no port.
391
108
 
392
109
  ## Development
393
110
 
394
111
  ```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
112
+ npm install && npm run build && npm test
113
+ node scripts/smoke.mjs # free tools against the node
114
+ node scripts/smoke.mjs paid # plus three asks (~$0.03), using the setup wallet
115
+ node scripts/smoke.mjs call telegraph_intent '{"intent":"CRYPTO_PRICE_USD"}'
116
+ npx @modelcontextprotocol/inspector dist/index.js # browse the tools
399
117
  ```
118
+
119
+ Architecture: [docs/architecture.md](docs/architecture.md). Problems: [docs/troubleshooting.md](docs/troubleshooting.md).
package/dist/api.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export interface AskArgs {
2
+ message: string;
3
+ intent?: string;
4
+ params?: Record<string, unknown>;
5
+ }
6
+ export interface AskResult {
7
+ status: string;
8
+ answer?: string;
9
+ sources?: unknown;
10
+ costUsd?: number | null;
11
+ conversationId?: string;
12
+ jobId?: string;
13
+ note?: string;
14
+ }
15
+ export declare class AnjomanApi {
16
+ private baseUrl;
17
+ private key;
18
+ constructor(baseUrl: string, key: string);
19
+ private request;
20
+ ask(args: AskArgs): Promise<AskResult>;
21
+ private follow;
22
+ private result;
23
+ account(): Promise<{
24
+ mode: string;
25
+ escrow: {
26
+ spendable_usd: any;
27
+ deposited_usd: any;
28
+ debt_usd: any;
29
+ };
30
+ totals: any;
31
+ recent_jobs: any;
32
+ top_up: string;
33
+ }>;
34
+ }
35
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAID,qBAAa,UAAU;IAEnB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,GAAG;gBADH,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM;YAIP,OAAO;IAqBf,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;YAO9B,MAAM;IAepB,OAAO,CAAC,MAAM;IAYR,OAAO;;;;;;;;;;;CAWd"}
package/dist/api.js ADDED
@@ -0,0 +1,81 @@
1
+ // Key mode: asks go through the user's Anjoman account (agent chat), which pays from the account's escrow itself.
2
+ // No wallet, signature or chain call happens in this process.
3
+ const ASK_WAIT_MS = 110_000; // the API answers at once or hands back a job within about 80 seconds
4
+ const POLL_EVERY_MS = 3_000;
5
+ const POLL_FOR_MS = 5 * 60_000; // how long a job handed back is followed before giving up (it keeps running)
6
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+ export class AnjomanApi {
8
+ baseUrl;
9
+ key;
10
+ constructor(baseUrl, key) {
11
+ this.baseUrl = baseUrl;
12
+ this.key = key;
13
+ }
14
+ // The API's own message is passed on, since it says what is wrong (revoked key, empty balance, rate limit).
15
+ async request(method, path, body, timeoutMs = 30_000) {
16
+ const res = await fetch(`${this.baseUrl}${path}`, {
17
+ method,
18
+ headers: { Authorization: `Bearer ${this.key}`, Accept: "application/json", ...(body === undefined ? {} : { "Content-Type": "application/json" }) },
19
+ body: body === undefined ? undefined : JSON.stringify(body),
20
+ signal: AbortSignal.timeout(timeoutMs),
21
+ });
22
+ const text = await res.text();
23
+ let parsed;
24
+ try {
25
+ parsed = text ? JSON.parse(text) : {};
26
+ }
27
+ catch {
28
+ parsed = { message: text.slice(0, 300) };
29
+ }
30
+ if (!res.ok) {
31
+ const message = Array.isArray(parsed.message) ? parsed.message.join(", ") : parsed.message || parsed.error || `status ${res.status}`;
32
+ throw new Error(`${res.status} from ${path}: ${message}`);
33
+ }
34
+ return { status: res.status, body: parsed };
35
+ }
36
+ async ask(args) {
37
+ const { status, body } = await this.request("POST", "/agent/chat", { ...args, stream: false }, ASK_WAIT_MS);
38
+ if (status !== 202)
39
+ return this.result(body);
40
+ return this.follow(body.jobId, body.conversationId);
41
+ }
42
+ // The turn outlived the wait: read its job until it ends.
43
+ async follow(jobId, conversationId) {
44
+ const until = Date.now() + POLL_FOR_MS;
45
+ while (Date.now() < until) {
46
+ await sleep(POLL_EVERY_MS);
47
+ const { body } = await this.request("GET", `/agent/jobs/${encodeURIComponent(jobId)}`);
48
+ if (body.status !== "running")
49
+ return this.result({ ...body, jobId, conversationId });
50
+ }
51
+ return {
52
+ status: "running",
53
+ jobId,
54
+ conversationId,
55
+ note: `Still running after ${POLL_FOR_MS / 60_000} minutes. It keeps going and is paid for only if it answers; read it later with GET /agent/jobs/${jobId}.`,
56
+ };
57
+ }
58
+ result(b) {
59
+ return {
60
+ status: b.status,
61
+ answer: b.answer,
62
+ sources: b.sources,
63
+ costUsd: b.costUsd ?? null,
64
+ conversationId: b.conversationId,
65
+ jobId: b.jobId ?? b.id,
66
+ };
67
+ }
68
+ // What is left to spend, and what the last few jobs cost.
69
+ async account() {
70
+ const [balance, spend] = await Promise.all([this.request("GET", "/engine/escrow/balance"), this.request("GET", "/agent/spend?limit=5")]);
71
+ const b = balance.body;
72
+ return {
73
+ mode: "Anjoman account, through an API key",
74
+ escrow: { spendable_usd: b.effectiveBalance, deposited_usd: b.escrowBalance, debt_usd: b.agentDebt },
75
+ totals: spend.body.totals,
76
+ recent_jobs: (spend.body.jobs || []).map((j) => ({ status: j.status, cost_usd: j.costUsd, at: j.startedAt })),
77
+ top_up: "Add funds in Anjoman: sign in, then use Deposit in the wallet menu. This server cannot deposit.",
78
+ };
79
+ }
80
+ }
81
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,8DAA8D;AAE9D,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,sEAAsE;AACnG,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,WAAW,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,6EAA6E;AAmB7G,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE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