@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/dist/tools.js ADDED
@@ -0,0 +1,335 @@
1
+ import { z } from "zod";
2
+ import { fileURLToPath } from "node:url";
3
+ import { sep } from "node:path";
4
+ import { Payer } from "./pay.js";
5
+ import { Chain } from "./chain.js";
6
+ import { cached, getJson } from "./http.js";
7
+ import { loadGuides, searchGuides } from "./docs.js";
8
+ const ok = (v) => ({
9
+ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v, null, 2) }],
10
+ });
11
+ const fail = (msg) => ({ content: [{ type: "text", text: msg }], isError: true });
12
+ // Turns a thrown error into a tool error the model can read.
13
+ const guard = (fn) => async (a) => {
14
+ try {
15
+ return await fn(a);
16
+ }
17
+ catch (e) {
18
+ return fail(e?.message || String(e));
19
+ }
20
+ };
21
+ // How this copy is run: `npx` once published, this file's own node and path when
22
+ // run from a clone. Used for the MCP entry `install` writes into an agent's
23
+ // config, and for every command we tell the user to run, so a clone points at
24
+ // itself and not at the published package.
25
+ const ENTRY = fileURLToPath(new URL("index.js", import.meta.url));
26
+ export const SERVER = ENTRY.includes(`${sep}node_modules${sep}`)
27
+ ? { command: "npx", args: ["-y", "@telegraphprotocol/telegraph-protocol-mcp"] }
28
+ : { command: process.execPath, args: [ENTRY] };
29
+ export const RUN = `${SERVER.command} ${SERVER.args.join(" ")}`;
30
+ const NO_KEY = `Paying needs a Telegraph wallet, and this server has none yet. Ask the user to run \`${RUN} setup\` in a ` +
31
+ "terminal (it creates or imports a wallet and funds it, with their approval at each step), then restart this " +
32
+ "MCP server. The free tools (find intents, miners, ranking, docs) work without one.";
33
+ const trim = (s, n) => {
34
+ const t = String(s ?? "").replace(/\s+/g, " ").trim();
35
+ return t.length > n ? t.slice(0, n - 1) + "…" : t;
36
+ };
37
+ const round = (x, d = 4) => Math.round(x * 10 ** d) / 10 ** d;
38
+ const name = (s) => s.trim().toUpperCase();
39
+ export function registerTools(server, cfg) {
40
+ const payer = cfg.privateKey ? new Payer(cfg, cfg.privateKey) : undefined;
41
+ const chain = new Chain(cfg);
42
+ const intents = cached(() => getJson(`${cfg.url}/engine/v1/intents`).then((d) => d.intents));
43
+ const miners = cached(() => getJson(`${cfg.url}/engine/v1/miners`, 60_000).then((d) => d.miners));
44
+ const guides = loadGuides();
45
+ const askShape = {
46
+ question: z.string().optional().describe("The question, in plain words."),
47
+ intent: z
48
+ .string()
49
+ .optional()
50
+ .describe("Optional exact intent, e.g. CRYPTO_PRICE_USD (see telegraph_find_intents). Only that intent's miners answer."),
51
+ params: z
52
+ .record(z.any())
53
+ .optional()
54
+ .describe('Optional params for the intent, as telegraph_intent lists them, e.g. {"location": "Lahore"}. Needs intent.'),
55
+ };
56
+ const askBody = (a) => {
57
+ if (a.params && !a.intent)
58
+ throw new Error("params need an intent.");
59
+ if (!a.question && !a.params)
60
+ throw new Error("Give a question, or an intent with params.");
61
+ return {
62
+ ...(a.question ? { query: a.question } : {}),
63
+ ...(a.intent ? { intent: name(a.intent) } : {}),
64
+ ...(a.params ? { params: a.params } : {}),
65
+ };
66
+ };
67
+ const paid = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
68
+ const free = { readOnlyHint: true, openWorldHint: true };
69
+ server.registerTool("telegraph_ask", {
70
+ title: "Ask Telegraph",
71
+ description: "Ask the Telegraph network a question: live prices, FX, weather, web and academic search, security, code " +
72
+ "review, compliance and 100+ other intents. The node routes it to the best-ranked live miner and returns " +
73
+ "its answer in the intent's fields. Costs about $0.01, paid automatically from the Telegraph escrow balance " +
74
+ "(a failed ask is never billed; repeating the same ask within a minute is not paid twice).",
75
+ inputSchema: askShape,
76
+ annotations: paid,
77
+ }, guard(async (a) => (payer ? answer(await payer.post("/engine/v1/ask", askBody(a))) : fail(NO_KEY))));
78
+ server.registerTool("telegraph_ask_miner", {
79
+ title: "Ask one miner",
80
+ description: "Ask one specific miner (by id or slug from telegraph_find_miners) instead of letting the node pick. Send " +
81
+ "a question (with intent when the miner serves several), or call one of its endpoints directly with " +
82
+ "endpoint, method and payload (the raw answer comes back). No fallback miner is tried. Paid like " +
83
+ "telegraph_ask, at that miner's price.",
84
+ inputSchema: {
85
+ miner: z.string().describe("Miner id or slug."),
86
+ ...askShape,
87
+ endpoint: z.string().optional().describe("Direct call: the miner's endpoint path, e.g. /query (telegraph_find_miners lists them)."),
88
+ method: z.enum(["GET", "POST"]).optional().describe("Direct call: HTTP method (default GET)."),
89
+ payload: z.record(z.any()).optional().describe("Direct call: the body or query fields the endpoint takes."),
90
+ },
91
+ annotations: paid,
92
+ }, guard(async (a) => {
93
+ if (!payer)
94
+ return fail(NO_KEY);
95
+ const body = a.endpoint ? { method: a.method || "GET", endpoint: a.endpoint, payload: a.payload || {} } : askBody(a);
96
+ // The node's direct-call form finds a miner by id only, so a slug is looked up first.
97
+ const id = (await miners().catch(() => [])).find((m) => m.slug === a.miner)?.id ?? a.miner;
98
+ return answer(await payer.post(`/engine/v1/ask/${encodeURIComponent(id)}`, body), true);
99
+ }));
100
+ server.registerTool("telegraph_find_intents", {
101
+ title: "Find intents",
102
+ description: "Search the intents (kinds of question) the network answers, with how many miners serve each. Free. " +
103
+ "Without search, lists every intent name.",
104
+ inputSchema: {
105
+ search: z.string().optional().describe("Words to look for, e.g. 'weather', 'bitcoin price', 'code review'."),
106
+ limit: z.number().int().min(1).max(200).optional().describe("Most results to return (default 10)."),
107
+ },
108
+ annotations: free,
109
+ }, guard(async ({ search, limit }) => {
110
+ const all = await intents();
111
+ if (!search)
112
+ return ok({ count: all.length, intents: all.map((i) => `${i.intent_name} (${i.miner_count} miners)`) });
113
+ const words = search.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
114
+ const found = all
115
+ .map((i) => {
116
+ // A word scores 3 when it starts a part of the name, 1 when it starts a word of the description.
117
+ const parts = String(i.intent_name).toLowerCase().split("_");
118
+ const d = ` ${String(i.description || "").toLowerCase().replace(/[^a-z0-9]+/g, " ")}`;
119
+ const score = words.reduce((s, w) => s + (parts.some((p) => p.startsWith(w)) ? 3 : 0) + (d.includes(` ${w}`) ? 1 : 0), 0);
120
+ return { i, score };
121
+ })
122
+ .filter((x) => x.score > 0)
123
+ .sort((a, b) => b.score - a.score || b.i.miner_count - a.i.miner_count)
124
+ .slice(0, limit ?? 10)
125
+ .map(({ i }) => ({ intent: i.intent_name, miners: i.miner_count, description: trim(i.description, 240) }));
126
+ return ok(found.length ? found : `No intent matches "${search}". Try other words, or call without search.`);
127
+ }));
128
+ server.registerTool("telegraph_intent", {
129
+ title: "Intent details",
130
+ description: "One intent: its kind (deterministic, hybrid or judgment), the params an ask can send, the fields the answer " +
131
+ "comes back in, and its top-ranked miners. Free.",
132
+ inputSchema: { intent: z.string().describe("Intent name, e.g. WEATHER_CHECK_TEMPERATURE.") },
133
+ annotations: free,
134
+ }, guard(async ({ intent }) => {
135
+ const id = name(intent);
136
+ const [d, board, list] = await Promise.all([
137
+ getJson(`${cfg.url}/engine/v1/intents/${encodeURIComponent(id)}`),
138
+ getJson(`${cfg.url}/leaderboard/miners?intent=${encodeURIComponent(id)}&limit=5`).catch(() => undefined),
139
+ intents().catch(() => []),
140
+ ]);
141
+ const top = rankingRows(board, id);
142
+ return ok({
143
+ intent: d.intent_name,
144
+ kind: d.class,
145
+ description: list.find((i) => i.intent_name === id)?.description,
146
+ miners: d.miner_count,
147
+ params: (d.request?.params || []).map((p) => ({
148
+ name: p.name, type: p.type, required: p.required, description: p.description, allowed: p.allowed,
149
+ })),
150
+ answer_fields: (d.response?.fields || []).map((f) => ({
151
+ name: f.name, type: f.type, unit: f.unit, description: f.user_description || f.description,
152
+ })),
153
+ top_ranked: top.length ? top : "Not ranked yet: an ask goes to a miner the node's LLM picks.",
154
+ });
155
+ }));
156
+ server.registerTool("telegraph_find_miners", {
157
+ title: "Find miners",
158
+ description: "Miners for an intent, best-ranked first, with status, price and rank; or miners whose name or description " +
159
+ "match some words. Free.",
160
+ inputSchema: {
161
+ intent: z.string().optional().describe("Intent name; lists that intent's miners with their rank."),
162
+ search: z.string().optional().describe("Words every listed miner must match (slug, name, description)."),
163
+ limit: z.number().int().min(1).max(100).optional().describe("Most miners to return (default 20)."),
164
+ },
165
+ annotations: free,
166
+ }, guard(async ({ intent, search, limit }) => {
167
+ const words = (search || "").toLowerCase().split(/\s+/).filter(Boolean);
168
+ const hit = (m) => words.every((w) => `${m.slug} ${m.name} ${m.description}`.toLowerCase().includes(w));
169
+ const n = limit ?? 20;
170
+ if (intent) {
171
+ const id = name(intent);
172
+ const rows = await getJson(`${cfg.url}/api/miners?intent=${encodeURIComponent(id)}&limit=500`, 60_000);
173
+ const out = rows
174
+ .filter(hit)
175
+ .map((m) => {
176
+ const s = (m.scores || []).find((x) => x.intent_id === id);
177
+ return {
178
+ id: m.id, slug: m.slug, name: m.name, status: m.activation_status,
179
+ price_usd: m.min_price_usdc != null ? m.min_price_usdc / 1e6 : undefined,
180
+ rank: s?.rank, score: s ? round(s.score) : undefined, requests_served: m.total_requests_served,
181
+ endpoints: (m.endpoints || []).slice(0, 8).map((e) => `${e.method} ${e.path}`),
182
+ description: trim(m.description, 160),
183
+ };
184
+ })
185
+ .sort((a, b) => (a.rank ?? 1e9) - (b.rank ?? 1e9) || (b.requests_served ?? 0) - (a.requests_served ?? 0));
186
+ return ok({ intent: id, count: out.length, miners: out.slice(0, n) });
187
+ }
188
+ if (!words.length)
189
+ return fail("Give an intent, or words to search the miners for.");
190
+ const out = (await miners()).filter(hit);
191
+ return ok({
192
+ count: out.length,
193
+ miners: out.slice(0, n).map((m) => ({
194
+ id: m.id, slug: m.slug, name: m.name, intents: m.capabilities, description: trim(m.description, 160),
195
+ })),
196
+ });
197
+ }));
198
+ server.registerTool("telegraph_ranking", {
199
+ title: "Miner ranking",
200
+ description: "The latest epoch's miner ranking (scores from the network's own checks), for one intent or the top few of " +
201
+ "every intent. Asks go to the top live miner. Free.",
202
+ inputSchema: {
203
+ intent: z.string().optional().describe("Intent name. Empty: every ranked intent."),
204
+ limit: z.number().int().min(1).max(50).optional().describe("Miners per intent (default 10 for one intent, 3 for all)."),
205
+ },
206
+ annotations: free,
207
+ }, guard(async ({ intent, limit }) => {
208
+ const q = intent ? `intent=${encodeURIComponent(name(intent))}&limit=${limit ?? 10}` : `limit=${limit ?? 3}`;
209
+ const [board, epoch] = await Promise.all([
210
+ getJson(`${cfg.url}/leaderboard/miners?${q}`),
211
+ getJson(`${cfg.url}/api/epoch`).catch(() => undefined),
212
+ ]);
213
+ const ranked = Object.fromEntries(Object.keys(board.intents || {}).map((k) => [k, rankingRows(board, k)]));
214
+ return ok({
215
+ epoch: board.epoch,
216
+ next_ranking_in: epoch?.time_until_next_epoch,
217
+ intents: Object.keys(ranked).length ? ranked : "Not ranked yet: an ask goes to a miner the node's LLM picks.",
218
+ });
219
+ }));
220
+ server.registerTool("telegraph_account", {
221
+ title: "Account",
222
+ description: "This server's wallet (or any address): its address and network, wallet USDC and ETH, the Telegraph escrow " +
223
+ "balance that pays for asks (spendable, deposited, debt, pending withdrawal), the spending limits, and how " +
224
+ "to top up. Free.",
225
+ inputSchema: { address: z.string().optional().describe("Address to look up. Default: this server's wallet.") },
226
+ annotations: free,
227
+ }, guard(async ({ address }) => {
228
+ const who = address || payer?.account.address;
229
+ if (!who)
230
+ return fail(NO_KEY);
231
+ if (!/^0x[0-9a-fA-F]{40}$/.test(who))
232
+ return fail(`Not an address: ${who}`);
233
+ const acct = await chain.account(who);
234
+ if (who !== payer?.account.address)
235
+ return ok(acct);
236
+ return ok({
237
+ ...acct,
238
+ payment_mode: cfg.payment,
239
+ limits: { max_per_ask_usd: cfg.maxAskUsd, daily_usd: cfg.dailyLimitUsd, spent_today_usd: payer.spent.today() },
240
+ top_up: `Asks are paid from escrow automatically. To add more, the user runs \`${RUN} fund\` in a terminal and confirms the amount.`,
241
+ });
242
+ }));
243
+ if (cfg.agentDeposit)
244
+ server.registerTool("telegraph_deposit", {
245
+ title: "Deposit to escrow",
246
+ description: "Move USDC from this server's wallet into its Telegraph escrow balance (approve, then depositUSDC on chain; " +
247
+ "needs a little ETH for gas). Escrow then pays for asks. Only offered when TELEGRAPH_ALLOW_AGENT_DEPOSIT is " +
248
+ "set; confirm the amount with the user first. Withdrawing is explained in telegraph_docs topic payments.",
249
+ inputSchema: { amount_usd: z.number().positive().max(10_000).describe("USDC to deposit, e.g. 1 or 5.") },
250
+ annotations: paid,
251
+ }, guard(async ({ amount_usd }) => {
252
+ if (!payer)
253
+ return fail(NO_KEY);
254
+ const result = await chain.deposit(payer.account, amount_usd);
255
+ payer.escrowFunded();
256
+ return ok(result);
257
+ }));
258
+ const topics = guides.map((g) => g.name);
259
+ server.registerTool("telegraph_docs", {
260
+ title: "Telegraph docs",
261
+ description: "How Telegraph works: getting started, payments, intents and ranking, errors. Free.",
262
+ inputSchema: {
263
+ topic: z.enum(topics).optional().describe("A topic to read in full."),
264
+ search: z.string().optional().describe("Words to look up across the docs."),
265
+ },
266
+ annotations: { readOnlyHint: true, openWorldHint: false },
267
+ }, guard(async ({ topic, search }) => {
268
+ if (topic)
269
+ return ok(guides.find((g) => g.name === topic).text);
270
+ if (search)
271
+ return ok(searchGuides(guides, search) || `Nothing found for "${search}". Topics: ${topics.join(", ")}.`);
272
+ return ok({ topics: guides.map((g) => ({ topic: g.name, title: g.title, about: g.summary })) });
273
+ }));
274
+ for (const g of guides) {
275
+ server.registerResource(g.name, `telegraph://docs/${g.name}`, { title: g.title, description: g.summary, mimeType: "text/markdown" }, async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: g.text }] }));
276
+ }
277
+ return payer;
278
+ }
279
+ function rankingRows(board, intent) {
280
+ return (board?.intents?.[intent] || []).map((r) => ({
281
+ rank: r.rank, miner: r.miner_slug, score: round(r.score), status: r.activation_status,
282
+ }));
283
+ }
284
+ function answer(r, oneMiner = false) {
285
+ const b = r.body && typeof r.body === "object" ? r.body : { error: r.body };
286
+ const payment = r.rail
287
+ ? {
288
+ rail: r.rail,
289
+ price_usd: r.priceUsd,
290
+ receipt: r.receipt,
291
+ ...(r.escrowRefused ? { escrow: r.escrowRefused } : {}),
292
+ ...(r.repeated ? { repeated: "Same ask as a moment ago: this is that answer, not paid again." } : {}),
293
+ }
294
+ : undefined;
295
+ if (r.status >= 200 && r.status < 300) {
296
+ return ok({
297
+ answer: b.result,
298
+ intent: b.intent,
299
+ miner: b.miner_name ? `${b.miner_name} (id ${b.miner_id})` : b.miner_id,
300
+ result_shape: b.result_shape,
301
+ field_status: b.field_status,
302
+ cost_usd: b.cost_usd,
303
+ payment,
304
+ warnings: b.warnings,
305
+ });
306
+ }
307
+ return fail(JSON.stringify({ status: r.status, error: b.error, reason: b.reason, message: b.message, hint: hintFor(r.status, b, oneMiner), node_payment_notice: b.payment, payment }, null, 2));
308
+ }
309
+ function hintFor(status, b, oneMiner) {
310
+ const err = String(b?.error || "");
311
+ if (oneMiner && err === "no_compatible_miner")
312
+ return "This miner can't take that request. Ask it with a question only, or use telegraph_ask.";
313
+ if (err === "no_compatible_miner")
314
+ return "No live miner serves that intent now. Ask without intent, or pick another (telegraph_find_intents).";
315
+ if (err === "invalid_params")
316
+ return "The params don't fit the intent. telegraph_intent lists the params it takes.";
317
+ if (err === "no_input_schema")
318
+ return "This intent takes no params. Send only a question.";
319
+ if (status === 429)
320
+ return "Too many new questions this minute. Wait a minute, then retry.";
321
+ if (status === 402) {
322
+ // The node refuses for more than a short balance: an agent over its charge
323
+ // limit, or one whose deliveries are suspended until its debt is repaid.
324
+ // Pass its own words through instead of guessing which it was.
325
+ const why = String(b?.reason || b?.error || "").trim();
326
+ return (`Payment from escrow refused${why ? ` (the node says: ${why})` : ""}, and nothing was charged. telegraph_account ` +
327
+ `shows the balance and anything owed; the user fixes it by running \`${RUN} fund\` in a terminal and confirming the amount.`);
328
+ }
329
+ if (status === 503)
330
+ return "The node could not route this now. Nothing was charged; try again shortly.";
331
+ if (status >= 500)
332
+ return "The miner or node failed. Escrow never bills a failed ask; an x402 payment is credited to escrow.";
333
+ return undefined;
334
+ }
335
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MA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AAO,qGAAqG,CAAC;IAChJ,IAAI,GAAG,KAAK,gBAAgB;QAAE,OAAO,8EAA8E,CAAC;IACpH,IAAI,GAAG,KAAK,iBAAiB;QAAE,OAAO,oDAAoD,CAAC;IAC3F,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,gEAAgE,CAAC;IAC5F,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,2EAA2E;QAC3E,yEAAyE;QACzE,+DAA+D;QAC/D,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,CACL,8BAA8B,GAAG,CAAC,CAAC,CAAC,oBAAoB,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,+CAA+C;YAClH,uEAAuE,GAAG,kDAAkD,CAC7H,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,4EAA4E,CAAC;IACxG,IAAI,MAAM,IAAI,GAAG;QAAE,OAAO,mGAAmG,CAAC;IAC9H,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { generatePrivateKey } from "viem/accounts";
2
+ export declare const walletPath: (home: string) => string;
3
+ export declare function readWalletKey(home: string): string | undefined;
4
+ export declare const walletUnreadable: (home: string) => boolean;
5
+ export declare function saveWallet(home: string, key: `0x${string}`): `0x${string}`;
6
+ export declare const newKey: typeof generatePrivateKey;
7
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAuB,MAAM,eAAe,CAAC;AAKxE,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAA8B,CAAC;AAKtE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS9D;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,YAAsE,CAAC;AAGpH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE,CAU1E;AAED,eAAO,MAAM,MAAM,2BAAqB,CAAC"}
package/dist/wallet.js ADDED
@@ -0,0 +1,38 @@
1
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
4
+ // The wallet that pays for asks lives in its own file, mode 0600, read only by
5
+ // this MCP server. No agent config, tool result or log ever holds the key.
6
+ export const walletPath = (home) => join(home, "wallet.json");
7
+ // A file that cannot be read gives no key rather than throwing, so a damaged
8
+ // wallet never stops the server for the free tools. `walletUnreadable` tells
9
+ // the person why they are being asked to set up again.
10
+ export function readWalletKey(home) {
11
+ const file = walletPath(home);
12
+ if (!existsSync(file))
13
+ return undefined;
14
+ try {
15
+ const key = JSON.parse(readFileSync(file, "utf8")).privateKey;
16
+ return typeof key === "string" && /^0x[0-9a-fA-F]{64}$/.test(key.trim()) ? key.trim() : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ export const walletUnreadable = (home) => existsSync(walletPath(home)) && readWalletKey(home) === undefined;
23
+ // Refuses to replace a wallet that already exists: it may hold funds.
24
+ export function saveWallet(home, key) {
25
+ if (!/^0x[0-9a-fA-F]{64}$/.test(key))
26
+ throw new Error("A private key is 0x and 64 hex characters.");
27
+ const file = walletPath(home);
28
+ if (existsSync(file))
29
+ throw new Error(`A wallet already exists at ${file}. Move it away first to replace it.`);
30
+ mkdirSync(home, { recursive: true, mode: 0o700 });
31
+ chmodSync(home, 0o700);
32
+ const address = privateKeyToAccount(key).address;
33
+ writeFileSync(file, JSON.stringify({ address, privateKey: key, createdAt: new Date().toISOString() }, null, 2) + "\n", { mode: 0o600 });
34
+ chmodSync(file, 0o600);
35
+ return address;
36
+ }
37
+ export const newKey = generatePrivateKey;
38
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAExE,+EAA+E;AAC/E,2EAA2E;AAE3E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AAEtE,6EAA6E;AAC7E,6EAA6E;AAC7E,uDAAuD;AACvD,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;QAC9D,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACpG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AAEpH,sEAAsE;AACtE,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,GAAkB;IACzD,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACpG,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,qCAAqC,CAAC,CAAC;IAC/G,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAClD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IACjD,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACxI,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,42 @@
1
+ # Getting started
2
+
3
+ Telegraph answers questions through a network of miners: APIs and models run by different people, each serving some intents (kinds of question). The network checks the miners every epoch and ranks them, and every ask goes to the best-ranked live miner for its intent.
4
+
5
+ ## Setup
6
+
7
+ The free tools work with no setup at all. To ask questions, the user runs this once in a terminal:
8
+
9
+ ```bash
10
+ npx -y @telegraphprotocol/telegraph-protocol-mcp setup
11
+ ```
12
+
13
+ It creates (or imports) a wallet just for Telegraph, funds its escrow after they confirm, and adds the server to their agent app. No setting or key goes in the app's config.
14
+
15
+ Optional settings:
16
+
17
+ - `TELEGRAPH_URL`: the node to use. Default: Telegraph beta 2, `https://devnode.telegraphprotocol.com`.
18
+ - `TELEGRAPH_PAYMENT`: `escrow` (default), `auto` (escrow, then x402) or `x402`.
19
+ - `TELEGRAPH_MAX_ASK_USD`, `TELEGRAPH_DAILY_LIMIT_USD`: spending limits (default $0.50 per ask, $5 a day).
20
+ - `TELEGRAPH_RPC_URL`, `TELEGRAPH_DIAMOND`, `TELEGRAPH_CHAIN_ID`: the chain behind the node. The defaults match beta 2.
21
+
22
+ ## The network today
23
+
24
+ Beta 2 runs on Ethereum Sepolia, a test network, so it costs no real money. Its USDC is Telegraph's own test token at `0xcc194e1a843B658526D0D5C431f670028582Ae17`, not Circle's: escrow takes that one and no other, and `telegraph_account` names it.
25
+
26
+ Get it from the faucet at <https://anjoman.ai/dashboard/faucet>: sign in, send it to your Telegraph wallet, 1 USDC per account every 24 hours. The `fund` command points you there. Transactions need a little Sepolia ETH for gas, which public Sepolia faucets give out.
27
+
28
+ ## First steps
29
+
30
+ 1. `telegraph_find_intents` with a few words, for example "weather" or "bitcoin price".
31
+ 2. `telegraph_intent` on the one you want: the params it takes and the fields the answer has.
32
+ 3. `telegraph_ask` with a question, or with the intent and its params.
33
+ 4. `telegraph_account` shows the balances and how to top up; the user tops up with `npx -y @telegraphprotocol/telegraph-protocol-mcp fund`.
34
+
35
+ ## Tools
36
+
37
+ - `telegraph_ask`: ask a question; the node picks the miner. Paid.
38
+ - `telegraph_ask_miner`: ask one miner you choose. Paid.
39
+ - `telegraph_find_intents`, `telegraph_intent`: what can be asked, and how. Free.
40
+ - `telegraph_find_miners`, `telegraph_ranking`: who answers, and how well they rank. Free.
41
+ - `telegraph_account`: balances, limits and how to top up. (`telegraph_deposit` only with `TELEGRAPH_ALLOW_AGENT_DEPOSIT`.)
42
+ - `telegraph_docs`: these guides.
@@ -0,0 +1,39 @@
1
+ # Payments
2
+
3
+ Each ask costs the price of the miner endpoint that answers, usually $0.01 in USDC. The server pays from your Telegraph escrow, on its own.
4
+
5
+ ## Escrow (the default)
6
+
7
+ You deposit USDC into your Telegraph escrow once: run `npx -y @telegraphprotocol/telegraph-protocol-mcp fund` in a terminal and confirm. Each ask then carries a signature the server makes for you. It proves you asked, but it can't move your funds. The node checks your balance, and the epoch's asks are deducted together when the epoch closes. A failed ask is never billed.
8
+
9
+ When escrow can't cover an ask, the ask is refused with the balances and how to top up. Nothing is charged, and the wallet is never paid from instead unless you turn x402 on.
10
+
11
+ ## Limits and retries
12
+
13
+ The server won't pay more than `TELEGRAPH_MAX_ASK_USD` for one ask (default $0.50) or `TELEGRAPH_DAILY_LIMIT_USD` in a UTC day (default $5). An identical ask while one is running, or within a minute of one that succeeded, gets that answer back without paying again.
14
+
15
+ ## x402 (only if you turn it on)
16
+
17
+ With `TELEGRAPH_PAYMENT=auto`, when escrow is empty the server pays per ask from the wallet's USDC with x402 (an EIP-3009 transfer signed by the wallet). The payment settles before the miner is called. If the ask then fails, the amount is credited to your Telegraph escrow, so it pays for later asks or can be withdrawn. The error the node returns says so in its `payment` field, when the node is new enough to send it.
18
+
19
+ ## Debt
20
+
21
+ If an epoch charges more than your escrow holds, the rest becomes debt. While you have debt, the node serves no asks on any rail. Any deposit, or x402 credit, pays the debt first; only the rest becomes spendable. `telegraph_account` shows `debt_usdc`.
22
+
23
+ ## Withdrawing
24
+
25
+ Run `withdraw` and confirm the amount. It stops paying for asks at once, and what you already owe is still settled
26
+ from it before it is paid out. It unlocks once the network settles two more blocks, or after the fallback delay the
27
+ contract sets, whichever comes first; run `withdraw` again then and it is sent to your wallet.
28
+
29
+ ```bash
30
+ npx -y @telegraphprotocol/telegraph-protocol-mcp withdraw 2 # request it
31
+ npx -y @telegraphprotocol/telegraph-protocol-mcp withdraw # collect it once unlocked
32
+ ```
33
+
34
+ A new request replaces the pending one. Under the hood this is `requestWithdraw(amount)` then `executeWithdraw()` on
35
+ the Telegraph diamond, which you can also call yourself.
36
+
37
+ ## Choosing a mode
38
+
39
+ `TELEGRAPH_PAYMENT=escrow` (default) pays only from escrow. `auto` tries escrow, then x402. `x402` never uses escrow.
@@ -0,0 +1,29 @@
1
+ # Intents, miners and ranking
2
+
3
+ ## Intents
4
+
5
+ An intent is one kind of question, such as `CRYPTO_PRICE_USD`, `WEATHER_CHECK_TEMPERATURE` or `CODE_REVIEW_GENERAL`. Every miner declares the intents it serves. `telegraph_find_intents` searches them.
6
+
7
+ Intents come in families: a family name (a prefix such as `WEATHER_CHECK`) groups the intents that extend it with `_`. You ask an intent, never a family.
8
+
9
+ ## Kinds
10
+
11
+ Each intent has a kind, which decides how its miners are checked:
12
+
13
+ - **deterministic**: one correct answer the network can confirm from public sources (a price, a rate, a temperature). Miners are compared with that answer.
14
+ - **hybrid**: a checkable fact plus a judged part.
15
+ - **judgment**: no single correct answer (a review, an analysis). A trained model scores the answers.
16
+
17
+ ## Asking well
18
+
19
+ A plain question works: the node reads the intent and its params from it. To be exact, send `intent` and `params` as `telegraph_intent` lists them, for example `{"intent": "WEATHER_CHECK_TEMPERATURE", "params": {"location": "Lahore"}}`. With an intent, only that intent's miners answer; if none is live, the ask is refused before payment.
20
+
21
+ The answer comes back in the intent's fields (`answer` in the tool result), with `field_status` saying which fields were found. When the fields can't be read, `result_shape` is `raw` and the answer is the miner's own reply.
22
+
23
+ ## Ranking
24
+
25
+ Every epoch (one hour on beta 2) the network asks each intent's miners questions and scores the answers. `telegraph_ranking` shows the result. An ask goes to the top live miner, with the next one as a fallback. A miner that stops answering is taken out of routing.
26
+
27
+ ## Intents without a ranking
28
+
29
+ Some intents are not ranked yet: deterministic ones need reference answers from several independent sources, and judgment ones need a trained model. An ask for such an intent goes to a miner the node's language model picks, which is less reliable. `telegraph_intent` says when an intent has no ranking.
@@ -0,0 +1,41 @@
1
+ # Errors and fixes
2
+
3
+ ## 503 could not route this question now
4
+
5
+ No miner could take the question at that moment. Nothing was charged. Retry, or ask with a specific intent.
6
+
7
+ ## 503 no_compatible_miner
8
+
9
+ You named an intent that no live miner serves now. Nothing was charged. Ask without the intent, or pick another with `telegraph_find_intents`.
10
+
11
+ ## 400 invalid_params
12
+
13
+ The params don't fit the intent's schema: missing, wrong type, or not allowed. `telegraph_intent` lists the params and types.
14
+
15
+ ## 400 no_input_schema
16
+
17
+ That intent takes no params. Send a question only.
18
+
19
+ ## 429 too many requests
20
+
21
+ Too many new questions in one minute. Wait a minute.
22
+
23
+ ## 402 escrow balance too low
24
+
25
+ The escrow can't cover the ask. Nothing was charged. The user runs `npx -y @telegraphprotocol/telegraph-protocol-mcp fund` in a terminal, then asks again. (Only with `TELEGRAPH_PAYMENT=auto` would the server pay from the wallet by x402 instead.)
26
+
27
+ ## Over a spending limit
28
+
29
+ The ask would cost more than `TELEGRAPH_MAX_ASK_USD`, or today's asks would pass `TELEGRAPH_DAILY_LIMIT_USD`. Nothing was signed or paid. Raise the limit in the server's settings, or wait for the next UTC day.
30
+
31
+ ## 402 after paying by x402 (x402 turned on)
32
+
33
+ The wallet may lack USDC, or the payment was refused. `telegraph_account` shows the wallet balance.
34
+
35
+ ## 500 or 502 after payment
36
+
37
+ The miner failed. On escrow nothing is billed. An x402 payment is credited to your escrow, so it stays yours.
38
+
39
+ ## Paying needs a wallet
40
+
41
+ The server found no wallet. The user runs `npx -y @telegraphprotocol/telegraph-protocol-mcp setup`, then restarts the agent app.