takar-mcp 0.0.0-stage → 0.2.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/README.md +22 -2
- package/package.json +17 -6
- package/server.mjs +231 -0
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# takar-mcp
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
{
|
|
2
|
-
"name": "takar-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "takar-mcp",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A second opinion for any Telegraph intent: two independent miners, chosen by an open on-chain record of who was right. Plus event resolution with verbatim quotes and a signed forecast scorecard. 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,231 @@
|
|
|
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 SITE = process.env.TAKAR_SITE ?? "https://takar-telegraph.vercel.app";
|
|
29
|
+
const VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
|
|
30
|
+
const PROTOCOL = "2024-11-05";
|
|
31
|
+
|
|
32
|
+
const TOOLS = [
|
|
33
|
+
{
|
|
34
|
+
name: "resolve_event",
|
|
35
|
+
description:
|
|
36
|
+
"Resolve whether a real-world event happened, or who won it, from Wikipedia text. Every yes/no " +
|
|
37
|
+
"answer carries a sentence quoted word for word from the cited article, checked in code. An " +
|
|
38
|
+
"event whose period has not ended, or that the sources do not settle, is answered \"unresolved\" " +
|
|
39
|
+
"instead of guessed. Same resolver as the Takar Outcome miner on Telegraph.",
|
|
40
|
+
inputSchema: {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
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.' },
|
|
44
|
+
},
|
|
45
|
+
required: ["event"],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "forecast_scorecard",
|
|
50
|
+
description:
|
|
51
|
+
"Takar's Mission 13 forecast scorecard: prediction-market crowd prices 7 days before each market " +
|
|
52
|
+
"closed, scored (Brier) against outcomes bought through Telegraph. The Ed25519 signature is " +
|
|
53
|
+
"checked here against Takar's pinned public key, so an edited scorecard reports verified: false.",
|
|
54
|
+
inputSchema: { type: "object", properties: {} },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "intent_ranking",
|
|
58
|
+
description:
|
|
59
|
+
"Live miner ranking for one Telegraph intent (e.g. EVENT_OUTCOME_RESOLUTION_GENERAL, " +
|
|
60
|
+
"WEATHER_FORECAST_VERIFY_GENERAL): rank, miner slug and score from the most recent epoch that " +
|
|
61
|
+
"scored it. Walks back through epochs, because the latest one lists only the intents it scored.",
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
intent: { type: "string", description: "Exact intent name, e.g. EVENT_OUTCOME_RESOLUTION_GENERAL." },
|
|
66
|
+
top: { type: "integer", minimum: 1, maximum: 50, description: "How many miners to return. Default 10." },
|
|
67
|
+
},
|
|
68
|
+
required: ["intent"],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "second_opinion",
|
|
73
|
+
description:
|
|
74
|
+
"Before acting on intelligence from Telegraph, get a second opinion: Takar asks two DIFFERENT miners " +
|
|
75
|
+
"the same question (any intent), chosen by an open on-chain record of who was right, and compares their " +
|
|
76
|
+
"answers field by field. verdict 'agree' -> act on 'answer'. 'disagree' -> do not act on either alone; " +
|
|
77
|
+
"report both and the differing fields. 'insufficient' -> fewer than two usable answers. Takar pays the asks " +
|
|
78
|
+
"in test USDC; no key or wallet needed. Testnet only.",
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: {
|
|
82
|
+
intent: { type: "string", description: "Exact Telegraph intent name, e.g. WEATHER_FORECAST_VERIFY_GENERAL or EVENT_OUTCOME_RESOLUTION_GENERAL." },
|
|
83
|
+
params: { type: "object", description: "The intent's request params, as its schema defines them." },
|
|
84
|
+
},
|
|
85
|
+
required: ["intent", "params"],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "miner_reputation",
|
|
90
|
+
description:
|
|
91
|
+
"Which Telegraph miner to trust for an intent, from an open on-chain record (EAS on Ethereum Sepolia) of how " +
|
|
92
|
+
"each miner's paid answers held up against independent truth: right, wrong, unusable, wrong place, abstained. " +
|
|
93
|
+
"Ranked by the Wilson lower bound of accuracy. Anyone can add evidence to the same schema.",
|
|
94
|
+
inputSchema: {
|
|
95
|
+
type: "object",
|
|
96
|
+
properties: {
|
|
97
|
+
intent: { type: "string", description: "Exact intent name. Omit to list the intents with evidence." },
|
|
98
|
+
attester: { type: "string", description: "Only count evidence from this attester address." },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
async function getJson(url, init) {
|
|
105
|
+
const r = await fetch(url, { ...init, signal: AbortSignal.timeout(90_000) });
|
|
106
|
+
const text = await r.text();
|
|
107
|
+
let body;
|
|
108
|
+
try { body = JSON.parse(text); } catch { throw new Error(`${r.status} from ${url}: not JSON`); }
|
|
109
|
+
if (!r.ok) throw new Error(body.error ?? body.message ?? `${r.status} from ${url}`);
|
|
110
|
+
return body;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Stable JSON with sorted keys: what the scorecard was signed over. */
|
|
114
|
+
const canonical = (v) =>
|
|
115
|
+
Array.isArray(v) ? `[${v.map(canonical).join(",")}]`
|
|
116
|
+
: v && typeof v === "object" ? `{${Object.keys(v).sort().map((k) => `${JSON.stringify(k)}:${canonical(v[k])}`).join(",")}}`
|
|
117
|
+
: JSON.stringify(v ?? null);
|
|
118
|
+
|
|
119
|
+
export function verifyScorecard(card, pinned = TAKAR_KEY) {
|
|
120
|
+
const { attestation, ...doc } = card;
|
|
121
|
+
if (!attestation?.signature) return false;
|
|
122
|
+
try {
|
|
123
|
+
const key = createPublicKey({ key: Buffer.from(pinned, "base64"), format: "der", type: "spki" });
|
|
124
|
+
return verify(null, Buffer.from(canonical(doc)), key, Buffer.from(attestation.signature, "base64"));
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const CALLS = {
|
|
131
|
+
async resolve_event({ event }) {
|
|
132
|
+
const e = String(event ?? "").trim();
|
|
133
|
+
if (!e) throw new Error("event is required");
|
|
134
|
+
if (e.length > 500) throw new Error("event must be at most 500 characters");
|
|
135
|
+
return getJson(`${RESOLVER}/api/resolve`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ event: e }) });
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
async forecast_scorecard() {
|
|
139
|
+
const card = await getJson(SCORECARD);
|
|
140
|
+
return {
|
|
141
|
+
verified: verifyScorecard(card),
|
|
142
|
+
signer: TAKAR_KEY,
|
|
143
|
+
generated_at: card.generated_at,
|
|
144
|
+
method: card.method,
|
|
145
|
+
summary: card.summary,
|
|
146
|
+
rows: card.rows,
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
async second_opinion({ intent, params }) {
|
|
151
|
+
const name = String(intent ?? "").trim();
|
|
152
|
+
if (!/^[A-Z][A-Z0-9_]{2,80}$/.test(name)) throw new Error("intent must be an exact intent name");
|
|
153
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) throw new Error("params must be an object");
|
|
154
|
+
return getJson(`${SITE}/api/second-opinion`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ intent: name, params }) });
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
async miner_reputation({ intent, attester } = {}) {
|
|
158
|
+
const q = new URLSearchParams();
|
|
159
|
+
if (intent) q.set("intent", String(intent));
|
|
160
|
+
if (attester) q.set("attester", String(attester));
|
|
161
|
+
return getJson(`${SITE}/api/reputation?${q}`);
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
async intent_ranking({ intent, top = 10 }) {
|
|
165
|
+
const name = String(intent ?? "").trim();
|
|
166
|
+
if (!/^[A-Z0-9_]{3,80}$/.test(name)) throw new Error("intent must be an exact intent name such as EVENT_OUTCOME_RESOLUTION_GENERAL");
|
|
167
|
+
const latest = await getJson(`${NODE}/leaderboard/miners`);
|
|
168
|
+
for (let e = latest.epoch, seen = 0; e > 0 && seen < 24; e--, seen++) {
|
|
169
|
+
const board = e === latest.epoch ? latest : await getJson(`${NODE}/leaderboard/miners/epoch/${e}`).catch(() => null);
|
|
170
|
+
const rows = board?.intents?.[name];
|
|
171
|
+
if (rows?.length) return { intent: name, epoch: e, miners: rows.slice(0, Math.min(50, Math.max(1, top))) };
|
|
172
|
+
}
|
|
173
|
+
return { intent: name, epoch: null, miners: [], note: "not scored in the last 24 epochs" };
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// ── JSON-RPC (from amanat-mcp) ───────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
const send = (msg) => process.stdout.write(JSON.stringify(msg) + "\n");
|
|
180
|
+
const reply = (id, result) => send({ jsonrpc: "2.0", id, result });
|
|
181
|
+
const fail = (id, code, message) => send({ jsonrpc: "2.0", id, error: { code, message } });
|
|
182
|
+
|
|
183
|
+
async function handle(msg) {
|
|
184
|
+
const { id, method, params } = msg;
|
|
185
|
+
const isNotification = id === undefined || id === null;
|
|
186
|
+
switch (method) {
|
|
187
|
+
case "initialize":
|
|
188
|
+
return reply(id, { protocolVersion: params?.protocolVersion ?? PROTOCOL, capabilities: { tools: {} }, serverInfo: { name: NAME, version: VERSION } });
|
|
189
|
+
case "notifications/initialized":
|
|
190
|
+
case "notifications/cancelled":
|
|
191
|
+
return;
|
|
192
|
+
case "ping":
|
|
193
|
+
return reply(id, {});
|
|
194
|
+
case "tools/list":
|
|
195
|
+
return reply(id, { tools: TOOLS });
|
|
196
|
+
case "tools/call": {
|
|
197
|
+
const fn = CALLS[params?.name];
|
|
198
|
+
if (!fn) return fail(id, -32602, `no tool called ${params?.name}`);
|
|
199
|
+
try {
|
|
200
|
+
const out = await fn(params.arguments ?? {});
|
|
201
|
+
return reply(id, { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] });
|
|
202
|
+
} catch (e) {
|
|
203
|
+
// A refusal is a result the model can act on, not a dead session.
|
|
204
|
+
return reply(id, { content: [{ type: "text", text: `error: ${e.message}` }], isError: true });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
default:
|
|
208
|
+
if (isNotification) return;
|
|
209
|
+
return fail(id, -32601, `unknown method ${method}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Only run the stdio loop when started directly, so the test can import verifyScorecard.
|
|
214
|
+
const main = (() => { try { return realpathSync(process.argv[1]) === fileURLToPath(import.meta.url); } catch { return false; } })();
|
|
215
|
+
if (main) {
|
|
216
|
+
let pending = 0;
|
|
217
|
+
let leaving = false;
|
|
218
|
+
const leaveIfIdle = () => { if (leaving && pending === 0) process.exit(0); };
|
|
219
|
+
createInterface({ input: process.stdin }).on("line", (line) => {
|
|
220
|
+
const text = line.trim();
|
|
221
|
+
if (!text) return;
|
|
222
|
+
let msg;
|
|
223
|
+
try { msg = JSON.parse(text); } catch { return fail(null, -32700, "parse error"); }
|
|
224
|
+
pending++;
|
|
225
|
+
handle(msg)
|
|
226
|
+
.catch((e) => { if (msg.id !== undefined && msg.id !== null) fail(msg.id, -32603, e.message); })
|
|
227
|
+
.finally(() => { pending--; leaveIfIdle(); });
|
|
228
|
+
});
|
|
229
|
+
// Answer what was already asked before leaving: piping frames then closing must still get replies.
|
|
230
|
+
process.stdin.on("close", () => { leaving = true; leaveIfIdle(); });
|
|
231
|
+
}
|