@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.
- package/.agents/skills/telegraph/SKILL.md +47 -129
- package/README.md +78 -358
- package/dist/api.d.ts +35 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +81 -0
- package/dist/api.js.map +1 -0
- package/dist/chain.d.ts +60 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +122 -0
- package/dist/chain.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +264 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +16 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +50 -20
- package/dist/config.js.map +1 -1
- package/dist/docs.d.ts +9 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +35 -0
- package/dist/docs.js.map +1 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +20 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -50
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +20 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +82 -0
- package/dist/limits.js.map +1 -0
- package/dist/pay.d.ts +27 -0
- package/dist/pay.d.ts.map +1 -0
- package/dist/pay.js +159 -0
- package/dist/pay.js.map +1 -0
- package/dist/tools.d.ts +20 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +370 -0
- package/dist/tools.js.map +1 -0
- package/dist/wallet.d.ts +7 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +38 -0
- package/dist/wallet.js.map +1 -0
- package/guides/1-getting-started.md +42 -0
- package/guides/2-payments.md +43 -0
- package/guides/3-intents-and-ranking.md +29 -0
- package/guides/4-troubleshooting.md +41 -0
- package/package.json +11 -14
- package/dist/client.d.ts +0 -6
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -116
- package/dist/client.js.map +0 -1
- package/dist/discovery.d.ts +0 -3
- package/dist/discovery.d.ts.map +0 -1
- package/dist/discovery.js +0 -16
- package/dist/discovery.js.map +0 -1
- package/dist/schema.d.ts +0 -3
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -84
- package/dist/schema.js.map +0 -1
- package/dist/tools/daemon.d.ts +0 -4
- package/dist/tools/daemon.d.ts.map +0 -1
- package/dist/tools/daemon.js +0 -82
- package/dist/tools/daemon.js.map +0 -1
- package/dist/tools/engine.d.ts +0 -5
- package/dist/tools/engine.d.ts.map +0 -1
- package/dist/tools/engine.js +0 -83
- package/dist/tools/engine.js.map +0 -1
- package/dist/tools/node.d.ts +0 -4
- package/dist/tools/node.d.ts.map +0 -1
- package/dist/tools/node.js +0 -88
- package/dist/tools/node.js.map +0 -1
- package/dist/tools/subnets.d.ts +0 -10
- package/dist/tools/subnets.d.ts.map +0 -1
- package/dist/tools/subnets.js +0 -114
- package/dist/tools/subnets.js.map +0 -1
- package/dist/transport.d.ts +0 -4
- package/dist/transport.d.ts.map +0 -1
- package/dist/transport.js +0 -17
- package/dist/transport.js.map +0 -1
- package/dist/types.d.ts +0 -71
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/x402.d.ts +0 -3
- package/dist/x402.d.ts.map +0 -1
- package/dist/x402.js +0 -61
- package/dist/x402.js.map +0 -1
package/dist/docs.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
// The guides ship in the package (guides/*.md), served as MCP resources and by
|
|
3
|
+
// the telegraph_docs tool. A file's number prefix only sets the order.
|
|
4
|
+
const DIR = new URL("../guides/", import.meta.url);
|
|
5
|
+
export function loadGuides() {
|
|
6
|
+
return readdirSync(DIR)
|
|
7
|
+
.filter((f) => f.endsWith(".md"))
|
|
8
|
+
.sort()
|
|
9
|
+
.map((f) => {
|
|
10
|
+
const text = readFileSync(new URL(f, DIR), "utf8");
|
|
11
|
+
const lines = text.split("\n");
|
|
12
|
+
const title = (lines.find((l) => l.startsWith("# ")) || f).replace(/^# /, "");
|
|
13
|
+
const summary = lines.find((l) => l.trim() && !l.startsWith("#")) || "";
|
|
14
|
+
return { name: f.replace(/^\d+-/, "").replace(/\.md$/, ""), title, summary, text };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
// The guide sections ("## ...") that match the most words of query, best first.
|
|
18
|
+
export function searchGuides(guides, query, max = 3) {
|
|
19
|
+
const words = query.toLowerCase().split(/\s+/).filter((w) => w.length > 1);
|
|
20
|
+
const hits = [];
|
|
21
|
+
for (const g of guides) {
|
|
22
|
+
for (const section of g.text.split(/\n(?=## )/)) {
|
|
23
|
+
const lower = section.toLowerCase();
|
|
24
|
+
const score = words.filter((w) => lower.includes(w)).length;
|
|
25
|
+
if (score > 0)
|
|
26
|
+
hits.push({ score, text: `From "${g.title}" (topic ${g.name}):\n\n${section.trim()}` });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return hits
|
|
30
|
+
.sort((a, b) => b.score - a.score)
|
|
31
|
+
.slice(0, max)
|
|
32
|
+
.map((h) => h.text)
|
|
33
|
+
.join("\n\n---\n\n");
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=docs.js.map
|
package/dist/docs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD,+EAA+E;AAC/E,uEAAuE;AACvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AASnD,MAAM,UAAU,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|
|
|
1
|
+
export async function getJson(url, timeoutMs = 30_000) {
|
|
2
|
+
const res = await fetch(url, { headers: { Accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
|
|
3
|
+
const text = await res.text();
|
|
4
|
+
if (!res.ok)
|
|
5
|
+
throw new Error(`${res.status} from ${new URL(url).pathname}: ${text.slice(0, 300)}`);
|
|
6
|
+
return JSON.parse(text);
|
|
7
|
+
}
|
|
8
|
+
// Caches a slow, rarely changing GET for ttlMs.
|
|
9
|
+
export function cached(load, ttlMs = 5 * 60_000) {
|
|
10
|
+
let value;
|
|
11
|
+
let at = 0;
|
|
12
|
+
return async () => {
|
|
13
|
+
if (value === undefined || Date.now() - at > ttlMs) {
|
|
14
|
+
value = await load();
|
|
15
|
+
at = Date.now();
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAW,EAAE,SAAS,GAAG,MAAM;IAC3D,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAClH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,MAAM,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACnG,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,MAAM,CAAI,IAAsB,EAAE,KAAK,GAAG,CAAC,GAAG,MAAM;IAClE,IAAI,KAAoB,CAAC;IACzB,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,OAAO,KAAK,IAAI,EAAE;QAChB,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;YACnD,KAAK,GAAG,MAAM,IAAI,EAAE,CAAC;YACrB,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAClB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
5
|
import { loadConfig } from "./config.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import { registerTools } from "./tools.js";
|
|
7
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
8
|
+
const INSTRUCTIONS = "Telegraph is a network of miners (APIs and models) that answer questions by intent, ranked every epoch by the " +
|
|
9
|
+
"network's own checks. Use telegraph_ask for live facts (prices, FX, weather, search) and specialist answers " +
|
|
10
|
+
"(security, code review, compliance); payment from the user's Telegraph escrow is automatic. " +
|
|
11
|
+
"telegraph_find_intents, telegraph_intent, telegraph_find_miners and telegraph_ranking are free. " +
|
|
12
|
+
"telegraph_account shows the balances and how the user tops up; telegraph_docs explains payments and errors. " +
|
|
13
|
+
"When TELEGRAPH_API_KEY is set, telegraph_ask goes through the user's Anjoman account (no wallet), and " +
|
|
14
|
+
"telegraph_ask_miner and telegraph_deposit are not offered.";
|
|
12
15
|
async function main() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.error(`[telegraph-mcp] Transport: ${config.transport}`);
|
|
19
|
-
const fetchWithPayment = await createPaymentAwareFetch(config);
|
|
20
|
-
const server = new McpServer({
|
|
21
|
-
name: "telegraph",
|
|
22
|
-
version: "1.0.0",
|
|
23
|
-
});
|
|
24
|
-
console.error("[telegraph-mcp] Registering node tools...");
|
|
25
|
-
registerNodeTools(server, config);
|
|
26
|
-
registerEngineTools(server, config, fetchWithPayment);
|
|
27
|
-
registerDaemonTools(server, config);
|
|
28
|
-
console.error("[telegraph-mcp] Node/engine/daemon tools registered");
|
|
29
|
-
async function refreshSubnetTools() {
|
|
30
|
-
try {
|
|
31
|
-
console.error("[telegraph-mcp] Refreshing subnet integrations...");
|
|
32
|
-
const integrations = await discoverSubnets(config.nodeUrl);
|
|
33
|
-
console.error(`[telegraph-mcp] Found ${integrations.length} integrations`);
|
|
34
|
-
const result = syncSubnetTools(server, integrations, config, fetchWithPayment);
|
|
35
|
-
console.error(`[telegraph-mcp] Sync: +${result.added} new, -${result.removed} removed, ${result.kept} unchanged`);
|
|
36
|
-
if (result.added > 0 || result.removed > 0) {
|
|
37
|
-
try {
|
|
38
|
-
server.sendToolListChanged();
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
console.error("[telegraph-mcp] Tool list change notification sent");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
console.error(`[telegraph-mcp] Refresh failed: ${err.message}`);
|
|
47
|
-
}
|
|
16
|
+
// A person running a command (setup, fund, status, install); with none, an MCP client is starting the server.
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
if (args.length || process.stdin.isTTY) {
|
|
19
|
+
const { runCli } = await import("./cli.js");
|
|
20
|
+
process.exit(await runCli(args));
|
|
48
21
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
22
|
+
const cfg = loadConfig();
|
|
23
|
+
const server = new McpServer({ name: "telegraph", version }, { instructions: INSTRUCTIONS });
|
|
24
|
+
const payer = registerTools(server, cfg);
|
|
25
|
+
await server.connect(new StdioServerTransport());
|
|
26
|
+
console.error(cfg.apiKey
|
|
27
|
+
? `[telegraph-mcp] v${version} on ${cfg.url}; API key ${cfg.apiKey.slice(0, 12)}… through ${cfg.apiUrl}; no wallet used`
|
|
28
|
+
: `[telegraph-mcp] v${version} on ${cfg.url}; wallet ${payer?.account.address ?? "none (free tools only)"}; payment ${cfg.payment}`);
|
|
55
29
|
}
|
|
56
30
|
main().catch((err) => {
|
|
57
|
-
console.error(`[telegraph-mcp]
|
|
31
|
+
console.error(`[telegraph-mcp] ${err?.message || err}`);
|
|
58
32
|
process.exit(1);
|
|
59
33
|
});
|
|
60
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC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OAAO,OAAO,GAAG,CAAC,GAAG,YAAY,KAAK,EAAE,OAAO,CAAC,OAAO,IAAI,wBAAwB,aAAa,GAAG,CAAC,OAAO,EAAE,CACtI,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,EAAE,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/limits.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class SpendLog {
|
|
2
|
+
private file;
|
|
3
|
+
constructor(home: string);
|
|
4
|
+
private read;
|
|
5
|
+
today(): number;
|
|
6
|
+
add(usd: number): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class Dedupe<T> {
|
|
9
|
+
private windowMs;
|
|
10
|
+
private inflight;
|
|
11
|
+
private recent;
|
|
12
|
+
constructor(windowMs: number);
|
|
13
|
+
get size(): number;
|
|
14
|
+
run(key: string, paid: (value: T) => boolean, fn: () => Promise<T>): Promise<{
|
|
15
|
+
value: T;
|
|
16
|
+
repeated: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export declare const requestKey: (path: string, body: unknown) => string;
|
|
20
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAWA,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAS;gBAET,IAAI,EAAE,MAAM;IAIxB,OAAO,CAAC,IAAI;IAQZ,KAAK,IAAI,MAAM;IAMf,GAAG,CAAC,GAAG,EAAE,MAAM;CAShB;AAID,qBAAa,MAAM,CAAC,CAAC;IAIP,OAAO,CAAC,QAAQ;IAH5B,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,MAAM,CAA+C;gBAEzC,QAAQ,EAAE,MAAM;IAGpC,IAAI,IAAI,WAEP;IAEK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;CAoBpH;AAGD,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,MAAM,OAAO,WAQpC,CAAC"}
|
package/dist/limits.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
const day = (offset = 0) => new Date(Date.now() + offset * 86_400_000).toISOString().slice(0, 10);
|
|
5
|
+
// What this wallet's asks have cost today (UTC), in a file, so a restart does
|
|
6
|
+
// not reset the daily limit. A cost is recorded before the payment is signed
|
|
7
|
+
// and given back if nothing was charged, so asks running at the same time
|
|
8
|
+
// cannot all pass the check. The count is per server process: two apps sharing
|
|
9
|
+
// one wallet each keep their own, so the daily limit holds per app.
|
|
10
|
+
export class SpendLog {
|
|
11
|
+
file;
|
|
12
|
+
constructor(home) {
|
|
13
|
+
this.file = join(home, "spend.json");
|
|
14
|
+
}
|
|
15
|
+
read() {
|
|
16
|
+
try {
|
|
17
|
+
return existsSync(this.file) ? JSON.parse(readFileSync(this.file, "utf8")) : {};
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
today() {
|
|
24
|
+
return this.read()[day()] ?? 0;
|
|
25
|
+
}
|
|
26
|
+
// Negative gives a reservation back. Written to a temporary file and renamed,
|
|
27
|
+
// which is atomic, so a crash or a second process leaves a whole file.
|
|
28
|
+
add(usd) {
|
|
29
|
+
// Keep a week, so the file stays small.
|
|
30
|
+
const all = Object.fromEntries(Object.entries(this.read()).filter(([k]) => k >= day(-7)));
|
|
31
|
+
all[day()] = Math.max(0, Math.round(((all[day()] ?? 0) + usd) * 1e6) / 1e6);
|
|
32
|
+
mkdirSync(dirname(this.file), { recursive: true, mode: 0o700 });
|
|
33
|
+
const tmp = join(dirname(this.file), `spend.${process.pid}.tmp`);
|
|
34
|
+
writeFileSync(tmp, JSON.stringify(all) + "\n", { mode: 0o600 });
|
|
35
|
+
renameSync(tmp, this.file);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Answers an identical ask from the one in flight, or from the last successful
|
|
39
|
+
// one, so an agent that retries is not charged twice.
|
|
40
|
+
export class Dedupe {
|
|
41
|
+
windowMs;
|
|
42
|
+
inflight = new Map();
|
|
43
|
+
recent = new Map();
|
|
44
|
+
constructor(windowMs) {
|
|
45
|
+
this.windowMs = windowMs;
|
|
46
|
+
}
|
|
47
|
+
// How many answers are held: 0 once the window has passed.
|
|
48
|
+
get size() {
|
|
49
|
+
return this.recent.size;
|
|
50
|
+
}
|
|
51
|
+
async run(key, paid, fn) {
|
|
52
|
+
const hit = this.recent.get(key);
|
|
53
|
+
if (hit && Date.now() - hit.at < this.windowMs)
|
|
54
|
+
return { value: hit.value, repeated: true };
|
|
55
|
+
const running = this.inflight.get(key);
|
|
56
|
+
if (running)
|
|
57
|
+
return { value: await running, repeated: true };
|
|
58
|
+
const p = fn();
|
|
59
|
+
this.inflight.set(key, p);
|
|
60
|
+
try {
|
|
61
|
+
const value = await p;
|
|
62
|
+
if (paid(value)) {
|
|
63
|
+
// Drop answers past the window, so a long-running server does not hold
|
|
64
|
+
// every answer it has ever given.
|
|
65
|
+
for (const [k, v] of this.recent)
|
|
66
|
+
if (Date.now() - v.at >= this.windowMs)
|
|
67
|
+
this.recent.delete(k);
|
|
68
|
+
this.recent.set(key, { at: Date.now(), value });
|
|
69
|
+
}
|
|
70
|
+
return { value, repeated: false };
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
this.inflight.delete(key);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// The same ask gives the same key, whatever order the model sent the fields in.
|
|
78
|
+
export const requestKey = (path, body) => createHash("sha256")
|
|
79
|
+
.update(path)
|
|
80
|
+
.update(JSON.stringify(body, (_k, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort()) : v) ?? "")
|
|
81
|
+
.digest("hex");
|
|
82
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,GAAG,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAElG,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,+EAA+E;AAC/E,oEAAoE;AACpE,MAAM,OAAO,QAAQ;IACX,IAAI,CAAS;IAErB,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IACvC,CAAC;IAEO,IAAI;QACV,IAAI,CAAC;YACH,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,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AC,QAAQ;wBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAChG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACpC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,IAAa,EAAE,EAAE,CACxD,UAAU,CAAC,QAAQ,CAAC;KACjB,MAAM,CAAC,IAAI,CAAC;KACZ,MAAM,CACL,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAC7B,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACnG,IAAI,EAAE,CACR;KACA,MAAM,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/pay.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type PrivateKeyAccount } from "viem/accounts";
|
|
2
|
+
import type { Config } from "./config.js";
|
|
3
|
+
import { SpendLog } from "./limits.js";
|
|
4
|
+
export interface PaidResponse {
|
|
5
|
+
status: number;
|
|
6
|
+
body: any;
|
|
7
|
+
rail?: "escrow" | "x402";
|
|
8
|
+
receipt?: unknown;
|
|
9
|
+
escrowRefused?: string;
|
|
10
|
+
priceUsd?: number;
|
|
11
|
+
repeated?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class Payer {
|
|
14
|
+
private cfg;
|
|
15
|
+
readonly account: PrivateKeyAccount;
|
|
16
|
+
private http;
|
|
17
|
+
private escrowEmptyUntil;
|
|
18
|
+
readonly spent: SpendLog;
|
|
19
|
+
private dedupe;
|
|
20
|
+
constructor(cfg: Config, key: `0x${string}`);
|
|
21
|
+
escrowFunded(): void;
|
|
22
|
+
post(path: string, body: unknown): Promise<PaidResponse>;
|
|
23
|
+
private reserve;
|
|
24
|
+
private pay;
|
|
25
|
+
private escrowHeader;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=pay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay.d.ts","sourceRoot":"","sources":["../src/pay.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAU,QAAQ,EAAc,MAAM,aAAa,CAAC;AAE3D,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAQD,qBAAa,KAAK;IAOJ,OAAO,CAAC,GAAG;IANvB,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,gBAAgB,CAAK;IAC7B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,OAAO,CAAC,MAAM,CAAuB;gBAEjB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,MAAM,EAAE;IAUnD,YAAY;IAMN,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAS9D,OAAO,CAAC,OAAO;YAaD,GAAG;YA6DH,YAAY;CAsB3B"}
|
package/dist/pay.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { x402Client, x402HTTPClient } from "@x402/fetch";
|
|
3
|
+
import { ExactEvmScheme, toClientEvmSigner } from "@x402/evm";
|
|
4
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
5
|
+
import { Dedupe, SpendLog, requestKey } from "./limits.js";
|
|
6
|
+
const ESCROW_SKIP_MS = 5 * 60_000;
|
|
7
|
+
const DEDUPE_MS = 60_000; // an identical ask within this window is not paid again
|
|
8
|
+
// Pays a /v1/ask call from the Telegraph escrow balance (a failed request is
|
|
9
|
+
// never billed). With TELEGRAPH_PAYMENT=auto or x402 it can also pay by x402
|
|
10
|
+
// from the wallet's USDC; that is never the default.
|
|
11
|
+
export class Payer {
|
|
12
|
+
cfg;
|
|
13
|
+
account;
|
|
14
|
+
http;
|
|
15
|
+
escrowEmptyUntil = 0;
|
|
16
|
+
spent;
|
|
17
|
+
dedupe;
|
|
18
|
+
constructor(cfg, key) {
|
|
19
|
+
this.cfg = cfg;
|
|
20
|
+
this.account = privateKeyToAccount(key);
|
|
21
|
+
const client = new x402Client();
|
|
22
|
+
client.register("eip155:*", new ExactEvmScheme(toClientEvmSigner(this.account)));
|
|
23
|
+
this.http = new x402HTTPClient(client);
|
|
24
|
+
this.spent = new SpendLog(cfg.home);
|
|
25
|
+
this.dedupe = new Dedupe(DEDUPE_MS);
|
|
26
|
+
}
|
|
27
|
+
// A deposit may have filled the escrow: try it again on the next call.
|
|
28
|
+
escrowFunded() {
|
|
29
|
+
this.escrowEmptyUntil = 0;
|
|
30
|
+
}
|
|
31
|
+
// An identical ask while one is running, or soon after one succeeded, gets
|
|
32
|
+
// that answer back instead of being paid again.
|
|
33
|
+
async post(path, body) {
|
|
34
|
+
const ok = (r) => r.status >= 200 && r.status < 300;
|
|
35
|
+
const { value, repeated } = await this.dedupe.run(requestKey(path, body), ok, () => this.pay(path, body));
|
|
36
|
+
return repeated ? { ...value, repeated: true } : value;
|
|
37
|
+
}
|
|
38
|
+
// Refuses to sign a payment over the per-ask or the daily limit, and counts
|
|
39
|
+
// the cost before signing, so asks running at the same time cannot all pass
|
|
40
|
+
// the check. The caller gives it back when nothing was charged.
|
|
41
|
+
reserve(usd) {
|
|
42
|
+
const { maxAskUsd: max, dailyLimitUsd: daily } = this.cfg;
|
|
43
|
+
const today = this.spent.today();
|
|
44
|
+
if (max > 0 && usd > max)
|
|
45
|
+
throw new Error(`This ask costs $${usd}, over the $${max} limit per ask (TELEGRAPH_MAX_ASK_USD). Nothing was paid.`);
|
|
46
|
+
if (daily > 0 && today + usd > daily) {
|
|
47
|
+
throw new Error(`Today's asks have cost $${today}; this one ($${usd}) would pass the $${daily} daily limit ` +
|
|
48
|
+
"(TELEGRAPH_DAILY_LIMIT_USD). Nothing was paid. The limit resets at midnight UTC.");
|
|
49
|
+
}
|
|
50
|
+
this.spent.add(usd);
|
|
51
|
+
}
|
|
52
|
+
async pay(path, body) {
|
|
53
|
+
const send = (headers = {}) => fetch(this.cfg.url + path, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { "Content-Type": "application/json", Accept: "application/json", ...headers },
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
signal: AbortSignal.timeout(120_000),
|
|
58
|
+
});
|
|
59
|
+
const first = await send();
|
|
60
|
+
if (first.status !== 402)
|
|
61
|
+
return { status: first.status, body: await readJson(first) };
|
|
62
|
+
const required = this.http.getPaymentRequiredResponse((h) => first.headers.get(h), await readJson(first));
|
|
63
|
+
let escrowRefused;
|
|
64
|
+
const escrow = required.accepts.find((a) => a.scheme === "escrow");
|
|
65
|
+
const tryEscrow = this.cfg.payment === "escrow" || (this.cfg.payment === "auto" && Date.now() >= this.escrowEmptyUntil);
|
|
66
|
+
if (escrow && tryEscrow) {
|
|
67
|
+
const priceUsd = usdOf(escrow.amount);
|
|
68
|
+
this.reserve(priceUsd);
|
|
69
|
+
let charged = false;
|
|
70
|
+
try {
|
|
71
|
+
const res = await send({ "X-PAYMENT": await this.escrowHeader(escrow) });
|
|
72
|
+
const resBody = await readJson(res);
|
|
73
|
+
charged = res.status >= 200 && res.status < 300; // escrow bills only a delivered ask
|
|
74
|
+
if (res.status !== 402 || this.cfg.payment === "escrow") {
|
|
75
|
+
const refused = res.status === 402 ? String(resBody?.reason || resBody?.error || "refused") : undefined;
|
|
76
|
+
return { status: res.status, body: resBody, rail: "escrow", receipt: receiptOf(res), escrowRefused: refused, priceUsd };
|
|
77
|
+
}
|
|
78
|
+
escrowRefused = String(resBody?.reason || resBody?.error || "refused");
|
|
79
|
+
if (escrowRefused.includes("insufficient"))
|
|
80
|
+
this.escrowEmptyUntil = Date.now() + ESCROW_SKIP_MS;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
if (!charged)
|
|
84
|
+
this.spent.add(-priceUsd);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Escrow mode never falls back to the wallet; and the node may offer no
|
|
88
|
+
// escrow payment at all (an older node, or escrow turned off there).
|
|
89
|
+
const exact = required.accepts.filter((a) => a.scheme === "exact");
|
|
90
|
+
if (this.cfg.payment === "escrow" || exact.length === 0) {
|
|
91
|
+
throw new Error(`The node offered no payment this wallet may make (TELEGRAPH_PAYMENT=${this.cfg.payment}); ` +
|
|
92
|
+
"escrow mode never pays from the wallet. TELEGRAPH_PAYMENT=auto allows x402.");
|
|
93
|
+
}
|
|
94
|
+
const priceUsd = usdOf(exact[0].amount);
|
|
95
|
+
this.reserve(priceUsd);
|
|
96
|
+
let charged = false;
|
|
97
|
+
try {
|
|
98
|
+
const payload = await this.http.createPaymentPayload({ ...required, accepts: exact });
|
|
99
|
+
const res = await send(this.http.encodePaymentSignatureHeader(payload));
|
|
100
|
+
// x402 settles before the miner runs, so a failed ask is charged and
|
|
101
|
+
// credited back to escrow. A payment the node refuses charges nothing.
|
|
102
|
+
charged = res.status !== 402;
|
|
103
|
+
return { status: res.status, body: await readJson(res), rail: "x402", receipt: receiptOf(res), escrowRefused, priceUsd };
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
if (!charged)
|
|
107
|
+
this.spent.add(-priceUsd);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// The scheme "escrow" X-PAYMENT header: a personal_sign of the challenge's
|
|
111
|
+
// message. It proves intent only; it can't move funds.
|
|
112
|
+
async escrowHeader(req) {
|
|
113
|
+
const template = String(req.extra?.message || "");
|
|
114
|
+
if (!template)
|
|
115
|
+
throw new Error("the escrow challenge has no message to sign");
|
|
116
|
+
const now = Math.floor(Date.now() / 1000);
|
|
117
|
+
const authorization = {
|
|
118
|
+
from: this.account.address,
|
|
119
|
+
to: req.payTo,
|
|
120
|
+
value: req.amount,
|
|
121
|
+
validAfter: String(now - 10),
|
|
122
|
+
validBefore: String(now + 60), // the node allows a window of 2 minutes at most
|
|
123
|
+
nonce: "0x" + randomBytes(32).toString("hex"),
|
|
124
|
+
};
|
|
125
|
+
// The node rebuilds the message with the wallet lowercased.
|
|
126
|
+
const message = template
|
|
127
|
+
.replaceAll("{from}", authorization.from.toLowerCase())
|
|
128
|
+
.replaceAll("{nonce}", authorization.nonce)
|
|
129
|
+
.replaceAll("{validAfter}", authorization.validAfter)
|
|
130
|
+
.replaceAll("{validBefore}", authorization.validBefore);
|
|
131
|
+
const signature = await this.account.signMessage({ message });
|
|
132
|
+
const envelope = { x402Version: 2, scheme: "escrow", network: req.network, payload: { signature, authorization } };
|
|
133
|
+
return Buffer.from(JSON.stringify(envelope)).toString("base64");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Challenge amounts are micro-USDC strings.
|
|
137
|
+
const usdOf = (amount) => Number(amount ?? 0) / 1e6;
|
|
138
|
+
async function readJson(res) {
|
|
139
|
+
const text = await res.text();
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(text);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return text;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// The payment receipt: X-PAYMENT-RESPONSE for escrow, PAYMENT-RESPONSE for x402.
|
|
148
|
+
function receiptOf(res) {
|
|
149
|
+
const header = res.headers.get("PAYMENT-RESPONSE") || res.headers.get("X-PAYMENT-RESPONSE");
|
|
150
|
+
if (!header)
|
|
151
|
+
return undefined;
|
|
152
|
+
try {
|
|
153
|
+
return JSON.parse(Buffer.from(header, "base64").toString("utf8"));
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=pay.js.map
|
package/dist/pay.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pay.js","sourceRoot":"","sources":["../src/pay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,cAAc,EAA4B,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAA0B,MAAM,eAAe,CAAC;AAE5E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAY3D,MAAM,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC;AAClC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,wDAAwD;AAElF,6EAA6E;AAC7E,6EAA6E;AAC7E,qDAAqD;AACrD,MAAM,OAAO,KAAK;IAOI;IANX,OAAO,CAAoB;IAC5B,IAAI,CAAiB;IACrB,gBAAgB,GAAG,CAAC,CA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AAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC5F,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { Config } from "./config.js";
|
|
3
|
+
import { Payer } from "./pay.js";
|
|
4
|
+
import { type AskResult } from "./api.js";
|
|
5
|
+
type Text = {
|
|
6
|
+
content: {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
isError?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const SERVER: {
|
|
13
|
+
command: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const RUN: string;
|
|
17
|
+
export declare function registerTools(server: McpServer, cfg: Config): Payer | undefined;
|
|
18
|
+
export declare function keyAnswer(r: AskResult): Text;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAqB,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAItD,KAAK,IAAI,GAAG;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAuB7E,eAAO,MAAM,MAAM;;;CAE6B,CAAC;AACjD,eAAO,MAAM,GAAG,QAA+C,CAAC;AAchE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAmT/E;AASD,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,IAAI,CAW5C"}
|