takar-mcp 0.0.0-stage → 0.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 (3) hide show
  1. package/README.md +22 -2
  2. package/package.json +15 -4
  3. package/server.mjs +185 -0
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # takar-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Three tools for any MCP client (Claude Desktop, Claude Code, Cursor, and so on).
4
+ There are no dependencies, no API key and no wallet.
5
+
6
+ ```json
7
+ { "mcpServers": { "takar": { "command": "npx", "args": ["-y", "takar-mcp"] } } }
8
+ ```
9
+
10
+ | Tool | What it returns |
11
+ |---|---|
12
+ | `resolve_event` | Whether a real-world event happened, or who won it. Every yes or no answer carries a sentence quoted word for word from the cited Wikipedia article, checked in code. Events that have not ended, or that the sources do not settle, come back as `unresolved` instead of a guess. It is the same resolver as the Takar Outcome miner on Telegraph. |
13
+ | `forecast_scorecard` | The Mission 13 forecast scorecard: prediction-market prices 7 days before close, Brier-scored against outcomes bought through Telegraph. The Ed25519 signature is checked against Takar's **pinned** public key, so an edited scorecard reports `verified: false`. |
14
+ | `intent_ranking` | Live miner ranking for any Telegraph intent, read from the node's leaderboard. It walks back through epochs, because the latest epoch lists only the intents it scored. |
15
+
16
+ Environment overrides: `TAKAR_RESOLVER`, `TELEGRAPH_NODE`, `TAKAR_SCORECARD`.
17
+
18
+ ```bash
19
+ node test.mjs # 4 offline signature checks + 5 live checks
20
+ node test.mjs --offline
21
+ ```
22
+
23
+ Source: https://github.com/PugarHuda/takar (`mcp/`). MIT.
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "takar-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Resolve real-world events with verbatim quotes, read a signed forecast scorecard, and rank Telegraph miners. No key, no wallet.",
5
+ "keywords": ["mcp", "modelcontextprotocol", "telegraph", "prediction-markets", "event-resolution", "oracle", "forecasting"],
6
+ "homepage": "https://github.com/PugarHuda/takar/tree/main/mcp",
7
+ "repository": { "type": "git", "url": "git+https://github.com/PugarHuda/takar.git", "directory": "mcp" },
8
+ "bugs": "https://github.com/PugarHuda/takar/issues",
9
+ "license": "MIT",
10
+ "author": "Pugar Huda Mantoro",
11
+ "type": "module",
12
+ "engines": { "node": ">=20" },
13
+ "bin": { "takar-mcp": "server.mjs" },
14
+ "main": "server.mjs",
15
+ "mcpName": "io.github.PugarHuda/takar",
16
+ "files": ["server.mjs", "README.md"]
17
+ }
package/server.mjs ADDED
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ // Takar as an MCP server: three tools over stdio, no dependencies, no wallet.
3
+ //
4
+ // npx -y takar-mcp
5
+ // node mcp/server.mjs
6
+ //
7
+ // { "mcpServers": { "takar": { "command": "npx", "args": ["-y", "takar-mcp"] } } }
8
+ //
9
+ // Every tool is a free read over plain HTTPS. Nothing here signs or spends; the
10
+ // paid Telegraph rails (x402, escrow) live in lib/ of the repo.
11
+ //
12
+ // ponytail: JSON-RPC by hand rather than @modelcontextprotocol/sdk, same as
13
+ // amanat-mcp. Four methods over newline-delimited JSON; swap in the SDK if this
14
+ // ever needs sampling, resources or prompts.
15
+
16
+ import { createInterface } from "node:readline";
17
+ import { readFileSync, realpathSync } from "node:fs";
18
+ import { fileURLToPath } from "node:url";
19
+ import { createPublicKey, verify } from "node:crypto";
20
+
21
+ const RESOLVER = (process.env.TAKAR_RESOLVER ?? "https://takar-outcome.vercel.app").replace(/\/+$/, "");
22
+ const NODE = (process.env.TELEGRAPH_NODE ?? "https://devnode.telegraphprotocol.com").replace(/\/+$/, "");
23
+ const SCORECARD = process.env.TAKAR_SCORECARD ?? "https://raw.githubusercontent.com/PugarHuda/takar/main/receipts/scorecard.json";
24
+ // Pinned, not read from the document: a scorecard that carries its own key can be
25
+ // re-signed by anyone. This is keys/takar-ed25519.pub in the repo.
26
+ const TAKAR_KEY = "MCowBQYDK2VwAyEA3Hx7R/RFow5HcbXTPXlbw0gS4eX7xliuos4D9uyQa5I=";
27
+ const NAME = "takar";
28
+ const VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
29
+ const PROTOCOL = "2024-11-05";
30
+
31
+ const TOOLS = [
32
+ {
33
+ name: "resolve_event",
34
+ description:
35
+ "Resolve whether a real-world event happened, or who won it, from Wikipedia text. Every yes/no " +
36
+ "answer carries a sentence quoted word for word from the cited article, checked in code. An " +
37
+ "event whose period has not ended, or that the sources do not settle, is answered \"unresolved\" " +
38
+ "instead of guessed. Same resolver as the Takar Outcome miner on Telegraph.",
39
+ inputSchema: {
40
+ type: "object",
41
+ properties: {
42
+ event: { type: "string", description: 'The event as a question, with its year, e.g. "Did Argentina win the 2022 FIFA World Cup?". At most 500 characters.' },
43
+ },
44
+ required: ["event"],
45
+ },
46
+ },
47
+ {
48
+ name: "forecast_scorecard",
49
+ description:
50
+ "Takar's Mission 13 forecast scorecard: prediction-market crowd prices 7 days before each market " +
51
+ "closed, scored (Brier) against outcomes bought through Telegraph. The Ed25519 signature is " +
52
+ "checked here against Takar's pinned public key, so an edited scorecard reports verified: false.",
53
+ inputSchema: { type: "object", properties: {} },
54
+ },
55
+ {
56
+ name: "intent_ranking",
57
+ description:
58
+ "Live miner ranking for one Telegraph intent (e.g. EVENT_OUTCOME_RESOLUTION_GENERAL, " +
59
+ "WEATHER_FORECAST_VERIFY_GENERAL): rank, miner slug and score from the most recent epoch that " +
60
+ "scored it. Walks back through epochs, because the latest one lists only the intents it scored.",
61
+ inputSchema: {
62
+ type: "object",
63
+ properties: {
64
+ intent: { type: "string", description: "Exact intent name, e.g. EVENT_OUTCOME_RESOLUTION_GENERAL." },
65
+ top: { type: "integer", minimum: 1, maximum: 50, description: "How many miners to return. Default 10." },
66
+ },
67
+ required: ["intent"],
68
+ },
69
+ },
70
+ ];
71
+
72
+ async function getJson(url, init) {
73
+ const r = await fetch(url, { ...init, signal: AbortSignal.timeout(90_000) });
74
+ const text = await r.text();
75
+ let body;
76
+ try { body = JSON.parse(text); } catch { throw new Error(`${r.status} from ${url}: not JSON`); }
77
+ if (!r.ok) throw new Error(body.error ?? body.message ?? `${r.status} from ${url}`);
78
+ return body;
79
+ }
80
+
81
+ /** Stable JSON with sorted keys: what the scorecard was signed over. */
82
+ const canonical = (v) =>
83
+ Array.isArray(v) ? `[${v.map(canonical).join(",")}]`
84
+ : v && typeof v === "object" ? `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}`
85
+ : JSON.stringify(v ?? null);
86
+
87
+ export function verifyScorecard(card, pinned = TAKAR_KEY) {
88
+ const { attestation, ...doc } = card;
89
+ if (!attestation?.signature) return false;
90
+ try {
91
+ const key = createPublicKey({ key: Buffer.from(pinned, "base64"), format: "der", type: "spki" });
92
+ return verify(null, Buffer.from(canonical(doc)), key, Buffer.from(attestation.signature, "base64"));
93
+ } catch {
94
+ return false;
95
+ }
96
+ }
97
+
98
+ const CALLS = {
99
+ async resolve_event({ event }) {
100
+ const e = String(event ?? "").trim();
101
+ if (!e) throw new Error("event is required");
102
+ if (e.length > 500) throw new Error("event must be at most 500 characters");
103
+ return getJson(`${RESOLVER}/api/resolve`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ event: e }) });
104
+ },
105
+
106
+ async forecast_scorecard() {
107
+ const card = await getJson(SCORECARD);
108
+ return {
109
+ verified: verifyScorecard(card),
110
+ signer: TAKAR_KEY,
111
+ generated_at: card.generated_at,
112
+ method: card.method,
113
+ summary: card.summary,
114
+ rows: card.rows,
115
+ };
116
+ },
117
+
118
+ async intent_ranking({ intent, top = 10 }) {
119
+ const name = String(intent ?? "").trim();
120
+ if (!/^[A-Z0-9_]{3,80}$/.test(name)) throw new Error("intent must be an exact intent name such as EVENT_OUTCOME_RESOLUTION_GENERAL");
121
+ const latest = await getJson(`${NODE}/leaderboard/miners`);
122
+ for (let e = latest.epoch, seen = 0; e > 0 && seen < 24; e--, seen++) {
123
+ const board = e === latest.epoch ? latest : await getJson(`${NODE}/leaderboard/miners/epoch/${e}`).catch(() => null);
124
+ const rows = board?.intents?.[name];
125
+ if (rows?.length) return { intent: name, epoch: e, miners: rows.slice(0, Math.min(50, Math.max(1, top))) };
126
+ }
127
+ return { intent: name, epoch: null, miners: [], note: "not scored in the last 24 epochs" };
128
+ },
129
+ };
130
+
131
+ // ── JSON-RPC (from amanat-mcp) ───────────────────────────────────────────────
132
+
133
+ const send = (msg) => process.stdout.write(JSON.stringify(msg) + "\n");
134
+ const reply = (id, result) => send({ jsonrpc: "2.0", id, result });
135
+ const fail = (id, code, message) => send({ jsonrpc: "2.0", id, error: { code, message } });
136
+
137
+ async function handle(msg) {
138
+ const { id, method, params } = msg;
139
+ const isNotification = id === undefined || id === null;
140
+ switch (method) {
141
+ case "initialize":
142
+ return reply(id, { protocolVersion: params?.protocolVersion ?? PROTOCOL, capabilities: { tools: {} }, serverInfo: { name: NAME, version: VERSION } });
143
+ case "notifications/initialized":
144
+ case "notifications/cancelled":
145
+ return;
146
+ case "ping":
147
+ return reply(id, {});
148
+ case "tools/list":
149
+ return reply(id, { tools: TOOLS });
150
+ case "tools/call": {
151
+ const fn = CALLS[params?.name];
152
+ if (!fn) return fail(id, -32602, `no tool called ${params?.name}`);
153
+ try {
154
+ const out = await fn(params.arguments ?? {});
155
+ return reply(id, { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] });
156
+ } catch (e) {
157
+ // A refusal is a result the model can act on, not a dead session.
158
+ return reply(id, { content: [{ type: "text", text: `error: ${e.message}` }], isError: true });
159
+ }
160
+ }
161
+ default:
162
+ if (isNotification) return;
163
+ return fail(id, -32601, `unknown method ${method}`);
164
+ }
165
+ }
166
+
167
+ // Only run the stdio loop when started directly, so the test can import verifyScorecard.
168
+ const main = (() => { try { return realpathSync(process.argv[1]) === fileURLToPath(import.meta.url); } catch { return false; } })();
169
+ if (main) {
170
+ let pending = 0;
171
+ let leaving = false;
172
+ const leaveIfIdle = () => { if (leaving && pending === 0) process.exit(0); };
173
+ createInterface({ input: process.stdin }).on("line", (line) => {
174
+ const text = line.trim();
175
+ if (!text) return;
176
+ let msg;
177
+ try { msg = JSON.parse(text); } catch { return fail(null, -32700, "parse error"); }
178
+ pending++;
179
+ handle(msg)
180
+ .catch((e) => { if (msg.id !== undefined && msg.id !== null) fail(msg.id, -32603, e.message); })
181
+ .finally(() => { pending--; leaveIfIdle(); });
182
+ });
183
+ // Answer what was already asked before leaving: piping frames then closing must still get replies.
184
+ process.stdin.on("close", () => { leaving = true; leaveIfIdle(); });
185
+ }