@priors/mcp 0.2.0 → 0.2.2

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 CHANGED
@@ -29,7 +29,7 @@ repaying.
29
29
  | `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee | yes |
30
30
  | `repay(loan_id? \| all)` | repay one of the agent's own loans, or all of them earliest due first; another agent's loan is refused | yes |
31
31
  | `score_of(agent_id)` | any agent's on-chain score (0 to 1000) and repayment record, plus its Priors Score v2 and trust rung when published | no |
32
- | `find_services(query?)` | services registered with the Priors facilitator that accept USDG (`GET /merchants`) | no |
32
+ | `find_services(query?)` | services registered with the Priors facilitator that accept USDG (`GET /merchants`), each marked as approved by Priors or self-registered and not reviewed | no |
33
33
 
34
34
  Tools that move money state the amounts in their answer, are marked destructive for MCP clients, and their
35
35
  descriptions tell the assistant to confirm with you first. Merchant text (response bodies, listings, redirect targets)
@@ -44,7 +44,7 @@ dedicated agent wallet holding only what the agent may spend.
44
44
  | variable | default | |
45
45
  |---|---|---|
46
46
  | `PRIORS_KEY` | none | the agent wallet's private key; without it only the read-only tools work |
47
- | `PRIORS_AGENT_ID` | looked up from the identity registry | the Priors agent id the wallet acts for |
47
+ | `PRIORS_AGENT_ID` | looked up from the identity registry | the Priors agent id the wallet acts for (the lookup finds only identities the wallet received since the v2 deploy; set it for an older one, or when the wallet holds several) |
48
48
  | `PRIORS_RPC` | `https://rpc.mainnet.chain.robinhood.com` | JSON-RPC endpoint (a private URL is redacted from every answer) |
49
49
  | `PRIORS_FACILITATOR` | `https://facilitator.priors.trade` | where `find_services` lists merchants |
50
50
  | `PRIORS_MAX_PRICE_USD` | `1.00` | ceiling on what `pay_url` may be told to pay per call |
@@ -68,7 +68,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
68
68
  "mcpServers": {
69
69
  "priors": {
70
70
  "command": "npx",
71
- "args": ["-y", "@priors/mcp@0.2.0"],
71
+ "args": ["-y", "@priors/mcp@0.2.2"],
72
72
  "env": {
73
73
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
74
74
  "PRIORS_AGENT_ID": "1234"
@@ -90,7 +90,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
90
90
  "mcpServers": {
91
91
  "priors": {
92
92
  "command": "npx",
93
- "args": ["-y", "@priors/mcp@0.2.0"],
93
+ "args": ["-y", "@priors/mcp@0.2.2"],
94
94
  "env": {
95
95
  "PRIORS_KEY": "${PRIORS_KEY}",
96
96
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -100,7 +100,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
100
100
  }
101
101
  ```
102
102
 
103
- or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.2.0`
103
+ or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.2.2`
104
104
  (the key is expanded by your shell from the environment; do not paste it on the command line).
105
105
 
106
106
  ## Try it
@@ -9,7 +9,7 @@ if (argv.some((a) => /(^|[^0-9a-fA-F])(0x)?[0-9a-fA-F]{64}($|[^0-9a-fA-F])/.test
9
9
  process.exit(2);
10
10
  }
11
11
  if (argv.includes("--help") || argv.includes("-h")) {
12
- process.stderr.write("priors-mcp: MCP server (stdio) for Priors on Robinhood Chain.\nenv: PRIORS_KEY (wallet key, optional), PRIORS_RPC, PRIORS_AGENT_ID, PRIORS_FACILITATOR, PRIORS_MAX_PRICE_USD, PRIORS_MAX_BORROW_USD\nSee the README for the Claude Desktop / Claude Code config.\n");
12
+ process.stderr.write("priors-mcp: MCP server (stdio) for Priors on Robinhood Chain.\nenv: PRIORS_KEY (wallet key, optional), PRIORS_RPC, PRIORS_AGENT_ID, PRIORS_FACILITATOR, PRIORS_MAX_PRICE_USD, PRIORS_MAX_BORROW_USD, PRIORS_MAX_SPEND_USD, PRIORS_MAX_BORROW_TOTAL_USD, PRIORS_ALLOW_LOCAL, PRIORS_STOCK_VAULT, PRIORS_SCORE_V2\nSee the README for the Claude Desktop / Claude Code config.\n");
13
13
  process.exit(0);
14
14
  }
15
15
  if (argv.length > 0) {
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "chainId": 4663,
3
+ "status": "live",
3
4
  "deployBlock": 71702460,
4
- "lens": "0x9d7035722bd42C551f82FEB9FDDd17453AEF3D9B",
5
5
  "pool": "0x281210097f0de7A8FB6F87310AF0f089c9C8DE21",
6
- "priors": "0xeDBf91223639800BCd5756815CAf908Df3b890bE",
7
- "registry": "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
8
- "safe": "0x20c6816B2419616238772591965E6E9AbE493fD5",
9
- "seatVault": "0x59D155C42A9263fA7596867b992bB3e84dF680a9",
6
+ "lens": "0x9d7035722bd42C551f82FEB9FDDd17453AEF3D9B",
10
7
  "timelock": "0x5d984C274035F81BB327d532897a902C5125F87c",
11
8
  "treasuryV4": "0x0c5091235A25bBFD3F5a009cBe04120D0CBAD573",
12
- "usdg": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
13
- "v1": "0x0259889e6EBab1a18CeE7e62Bc5B9648FB6C44e5",
14
9
  "treasuryV4AgentId": 6228,
10
+ "seatVault": "0x59D155C42A9263fA7596867b992bB3e84dF680a9",
15
11
  "seatVaultAgentId": 6234,
16
- "roots": [
17
- 490,
18
- 6191,
19
- 470,
20
- 471,
21
- 472,
22
- 473,
23
- 474
24
- ],
12
+ "usdg": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
13
+ "registry": "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
14
+ "priors": "0xeDBf91223639800BCd5756815CAf908Df3b890bE",
15
+ "safe": "0x20c6816B2419616238772591965E6E9AbE493fD5",
16
+ "v1": "0x0259889e6EBab1a18CeE7e62Bc5B9648FB6C44e5",
25
17
  "v1Pool": "0x0259889e6EBab1a18CeE7e62Bc5B9648FB6C44e5",
18
+ "inviteBond": "0x8BE478c754D9124D11e78dB20F5bf4dA45403275",
19
+ "inviteBondBlock": 72112874,
20
+ "seatVaultBlock": 72192188,
26
21
  "seatVaultV2": "0x6D934C07a33E7285cE691A9B258cdB53F18e6B5F",
27
22
  "seatVaultV2AgentId": 6229,
28
- "seatVaultBlock": 72192188,
23
+ "seatSizer": "0xd24B6484f4E68d72Fd2d3AF7bD036560B2ed5E61",
24
+ "seatSizerBlock": 72572884,
29
25
  "stockVault": "0xbEcd07EC689988e16b870C121756C4c2C8cb02B6",
30
26
  "stockVaultAgentId": 6424,
31
- "stockVaultBlock": 74826641
27
+ "stockVaultBlock": 74826641,
28
+ "seatVaultV4": "0xb1c3a04496238D62E3c93118C297163855e22192",
29
+ "seatVaultV4AgentId": 6466,
30
+ "seatVaultV4Block": 75614831,
31
+ "seatSizerV4": "0x97C4e594D458f8BBE961d5384Bbd8a9Cc2D18777",
32
+ "seatSizerV4Block": 75614955
32
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@priors/mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "description": "MCP server for Priors on Robinhood Chain: pay x402 URLs in USDG, read balances, credit lines and scores, borrow and repay. Key from PRIORS_KEY only.",
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@modelcontextprotocol/sdk": "^1.30.1",
45
- "@priors/x402": "0.2.0",
45
+ "@priors/x402": "0.2.2",
46
46
  "ethers": "^6.13.4",
47
47
  "undici": "6.29.0",
48
48
  "zod": "^4.6.5"
package/src/server.mjs CHANGED
@@ -17,7 +17,7 @@
17
17
  // PRIORS_MAX_BORROW_TOTAL_USD most borrowed in total per process (default 25)
18
18
  // PRIORS_ALLOW_LOCAL "1": pay_url may reach http://localhost and private addresses (testing only)
19
19
  // PRIORS_SCORE_V2 where score_of reads Priors Score v2 (default https://priors.trade/api/score-v2; "off": v1 only)
20
- // PRIORS_STOCK_VAULT the stock vault's address (default: deployments/4663.v2.json `stockVault`, once deployed)
20
+ // PRIORS_STOCK_VAULT the stock vault's address (default: deployments/4663.v2.json `stockVault`)
21
21
  import { readFileSync } from "node:fs";
22
22
  import { randomBytes } from "node:crypto";
23
23
  import { lookup as dnsLookup } from "node:dns/promises";
@@ -71,19 +71,30 @@ function v6Bytes(s) {
71
71
  if (groups.length !== 8) return null;
72
72
  return groups.flatMap((g) => { const v = parseInt(g || "0", 16); return [v >> 8, v & 255]; });
73
73
  }
74
- /** Loopback, private, link-local, CGNAT, unspecified, multicast and IPv4-mapped forms of those. */
74
+ /**
75
+ * Loopback, private, link-local, CGNAT, unspecified, multicast, reserved and documentation blocks, and the IPv6 forms
76
+ * that carry an IPv4 address (IPv4-mapped, NAT64, 6to4) judged by that address; Teredo and site-local are refused.
77
+ */
75
78
  export function isPrivateAddress(ip) {
76
79
  const kind = isIP(ip.replace(/^\[|\]$/g, "").split("%")[0]);
77
80
  if (kind === 4) {
78
- const [a, b] = ip.split(".").map(Number);
79
- return a === 0 || a === 10 || a === 127 || a >= 224 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 198 && (b === 18 || b === 19));
81
+ const [a, b, c] = ip.split(".").map(Number);
82
+ return a === 0 || a === 10 || a === 127 || a >= 224 || (a === 100 && b >= 64 && b <= 127) || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 198 && (b === 18 || b === 19))
83
+ || (a === 192 && b === 0 && (c === 0 || c === 2)) || (a === 198 && b === 51 && c === 100) || (a === 203 && b === 0 && c === 113); // 192.0.0.0/24, TEST-NETs
80
84
  }
81
85
  if (kind !== 6) return true; // not an address: refuse rather than guess
82
86
  const x = v6Bytes(ip);
83
87
  if (!x) return true;
84
- if (x.slice(0, 10).every((v) => v === 0) && x[10] === 255 && x[11] === 255) return isPrivateAddress(x.slice(12).join(".")); // ::ffff:a.b.c.d
88
+ const v4at = (i) => isPrivateAddress(x.slice(i, i + 4).join("."));
89
+ if (x.slice(0, 10).every((v) => v === 0) && x[10] === 255 && x[11] === 255) return v4at(12); // ::ffff:a.b.c.d
85
90
  if (x.slice(0, 12).every((v) => v === 0)) return true; // ::, ::1 and the deprecated IPv4-compatible forms
86
- return (x[0] & 0xfe) === 0xfc || (x[0] === 0xfe && (x[1] & 0xc0) === 0x80) || x[0] === 0xff; // fc00::/7, fe80::/10, ff00::/8
91
+ if (x[0] === 0 && x[1] === 0x64 && x[2] === 0xff && x[3] === 0x9b) { // NAT64
92
+ if (x[4] === 0 && x[5] === 1) return true; // 64:ff9b:1::/48, local-use: it can translate to anything
93
+ if (x.slice(4, 12).every((v) => v === 0)) return v4at(12); // 64:ff9b::/96, the well-known prefix
94
+ }
95
+ if (x[0] === 0x20 && x[1] === 0x02) return v4at(2); // 2002::/16, 6to4
96
+ if (x[0] === 0x20 && x[1] === 0x01 && x[2] === 0 && x[3] === 0) return true; // 2001::/32, Teredo
97
+ return (x[0] & 0xfe) === 0xfc || (x[0] === 0xfe && (x[1] & 0xc0) === 0x80) || (x[0] === 0xfe && (x[1] & 0xc0) === 0xc0) || x[0] === 0xff; // fc00::/7, fe80::/10, fec0::/10, ff00::/8
87
98
  }
88
99
 
89
100
  /**
@@ -202,11 +213,28 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
202
213
  };
203
214
  const addresses = { ...ADDRESSES, ...(env.PRIORS_STOCK_VAULT ? { stockVault: env.PRIORS_STOCK_VAULT } : {}), ...(deps.addresses || {}) };
204
215
 
205
- // Everything returned passes through here: the key (with or without 0x, any case) and a private RPC URL are cut.
216
+ // Everything returned passes through here. The key is cut with or without 0x, in any case, and with separators between
217
+ // its digits (spaced, split over lines, dashed, JSON-quoted chunks). A private RPC URL is cut whole and by its parts
218
+ // (the host, long path segments, query values, credentials), in any case, each also when percent-encoded.
206
219
  const secrets = [];
207
- if (rawKey) { const h = rawKey.replace(/^0x/i, ""); if (h.length >= 16) secrets.push(new RegExp(`(0x)?${h.replace(/[^0-9a-zA-Z]/g, "")}`, "gi")); }
208
- if (env.PRIORS_RPC && env.PRIORS_RPC !== X.robinhood.rpcUrl) secrets.push(new RegExp(env.PRIORS_RPC.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"));
209
- const redact = (s) => secrets.reduce((acc, re) => acc.replace(re, (m) => (m.startsWith("http") ? "<rpc>" : "<redacted>")), String(s));
220
+ if (rawKey) {
221
+ const h = rawKey.replace(/^0x/i, "").replace(/[^0-9a-zA-Z]/g, "");
222
+ if (h.length >= 16) secrets.push(new RegExp(`(0x)?${[...h].join("[\\s\"'+,\\-]{0,3}")}`, "gi"));
223
+ }
224
+ if (env.PRIORS_RPC && env.PRIORS_RPC !== X.robinhood.rpcUrl) {
225
+ const parts = [env.PRIORS_RPC];
226
+ try {
227
+ const u = new URL(env.PRIORS_RPC);
228
+ parts.push(u.href, u.host, u.username, u.password);
229
+ for (const seg of u.pathname.split("/")) if (seg.length >= 8) parts.push(seg, decodeURIComponent(seg));
230
+ for (const v of u.searchParams.values()) if (v.length >= 8) parts.push(v);
231
+ } catch (_) { /* not a URL: the literal is still cut */ }
232
+ // each character that is not a letter or a digit may also appear percent-encoded
233
+ const pattern = (p) => [...p].map((ch) => (/[0-9a-z]/i.test(ch) ? ch : `(?:${ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}|%${ch.charCodeAt(0).toString(16).padStart(2, "0")})`)).join("");
234
+ const uniq = [...new Set(parts.filter((p) => p && p.length >= 6))].sort((a, b) => b.length - a.length);
235
+ if (uniq.length) secrets.push(new RegExp(uniq.map(pattern).join("|"), "gi"));
236
+ }
237
+ const redact = (s) => secrets.reduce((acc, re) => acc.replace(re, (m) => (/^http/i.test(m) ? "<rpc>" : "<redacted>")), String(s));
210
238
 
211
239
  // One call per request: ethers batches parallel reads up to 100 calls, and the public node (the default PRIORS_RPC)
212
240
  // answers a batch that size with HTTP 429, which ethers retries until its 5-minute timeout (stock_assets' ~140 reads).
@@ -255,7 +283,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
255
283
  const mine = await credit.agentsOf(wallet.address);
256
284
  if (mine.length === 1) return (agentCache = mine[0]);
257
285
  if (mine.length > 1) throw new ToolError(`This wallet owns several agent identities (${mine.map((i) => "#" + i).join(", ")}). Set PRIORS_AGENT_ID or pass agent_id.`);
258
- throw new ToolError("This wallet owns no Priors agent identity minted since the v2 deploy. Set PRIORS_AGENT_ID if it owns an older one, or register first (the `priors join` CLI).");
286
+ throw new ToolError("This wallet owns no Priors agent identity minted since the v2 deploy. Set PRIORS_AGENT_ID if it owns an older one, or register first (`npx priors-v2 join`, from a clone of github.com/priors-agents/priors).");
259
287
  }
260
288
 
261
289
  function needWallet(action) {
@@ -310,7 +338,9 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
310
338
  let json = false; try { JSON.parse(body); json = true; } catch (_) { /* text */ }
311
339
  init.body = body; init.headers = { "content-type": json ? "application/json" : "text/plain; charset=utf-8" };
312
340
  }
313
- const purchase = `${method} ${u.href}`;
341
+ const target = new URL(u.href);
342
+ target.hash = ""; // a fragment never reaches the merchant: url#a and url#b are the same purchase
343
+ const purchase = `${method} ${target.href}`;
314
344
  const now = Math.floor(Date.now() / 1000);
315
345
  for (const [k, v] of outstanding) if (v.validBefore <= now) outstanding.delete(k);
316
346
  const lines = [];
@@ -328,7 +358,18 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
328
358
  if (maxBorrow > 0n) { agentId = await resolveAgent(); await needController(agentId); }
329
359
  const payer = X.createPayer({ signer, maxPrice, maxBorrow, fetchImpl: payFetch, pendingRetries: 2, maxSleepMs: 10_000, timeoutMs: requestTimeoutMs, signal: AbortSignal.timeout(Math.max(1, deadline - Date.now())), ...(sleep ? { sleep } : {}), ...(maxBorrow > 0n ? { pool: addresses.pool, agentId } : {}) });
330
360
  try { r = await payer.pay(url, init); } catch (e) {
331
- if (e?.name === "TimeoutError" || e?.name === "AbortError") throw new ToolError(`${method} ${u.href} did not answer in time. Nothing was signed or paid.`);
361
+ // What the error carries was done: a loan taken and a payment signed are counted, whatever failed after.
362
+ if (e?.borrowed > 0n) session.borrowed += e.borrowed;
363
+ if (e?.signed) {
364
+ const price = BigInt(e.requirement.amount ?? e.requirement.maxAmountRequired);
365
+ session.spent += price;
366
+ outstanding.set(purchase, { ...e.signed, requirement: e.requirement, price });
367
+ const until = when(e.signed.validBefore);
368
+ throw new ToolError(`A payment of ${usd(price)} to ${e.requirement.payTo} was signed, then the request failed (${explain(e)}). The merchant may still settle it until ${until}, so do NOT call pay_url again for this URL before ${until}; check wallet_balance.${e.borrowed > 0n ? ` Borrowed ${usd(e.borrowed)}${e.loanId !== null ? ` as loan #${e.loanId}` : ""}: repay it with the repay tool.` : ""}`);
369
+ }
370
+ const loan = e?.borrowed > 0n ? ` ${usd(e.borrowed)} was borrowed${e.loanId !== null ? ` as loan #${e.loanId}` : ""} before it failed: repay it with the repay tool.` : "";
371
+ if (e?.name === "TimeoutError" || e?.name === "AbortError") throw new ToolError(`${method} ${u.href} did not answer in time. Nothing was signed or paid.${loan}`);
372
+ if (loan) throw new ToolError(`${explain(e)}.${loan}`);
332
373
  throw e;
333
374
  }
334
375
  if (r.signed) {
@@ -339,7 +380,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
339
380
  if (r.borrowed > 0n) { session.borrowed += r.borrowed; lines.push(`Borrowed ${usd(r.borrowed)} from the Priors line for agent #${agentId}${r.loanId !== null ? ` as loan #${r.loanId}` : ""}${r.dueAt ? `, due ${when(r.dueAt)}` : ""}. Repay it with the repay tool before then.`); }
340
381
  else if (r.requirement) lines.push("Nothing was borrowed.");
341
382
  }
342
- const status = r.timedOut ? "no answer in time" : `HTTP ${r.response.status}`;
383
+ const status = r.timedOut ? "no answer in time" : r.transportError ? "the connection was lost" : `HTTP ${r.response.status}`;
343
384
  if (!r.requirement) lines.unshift(`No payment was asked for: ${method} ${u.href} answered ${status}. Nothing was paid.`);
344
385
  else if (r.paid > 0n) {
345
386
  outstanding.delete(purchase);
@@ -542,7 +583,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
542
583
  if (hits.length === 0) return q ? `No registered service matches "${clean(q, 100)}" (${list.length} registered in all).` : "No services are registered with the facilitator yet.";
543
584
  const vol = (v) => (/^\d+$/.test(String(v ?? "")) ? usd(BigInt(v)) : clean(v ?? "0", 30));
544
585
  const httpsUrl = (v) => { try { const x = new URL(String(v)); return x.protocol === "https:" ? oneLine(x.href, 200) : "no https url"; } catch (_) { return "no url"; } };
545
- const rows = hits.slice(0, 25).map((m) => `- ${oneLine(m.name || "(unnamed)", 60)} — ${httpsUrl(m.url)}\n ${oneLine(m.description || "", 280)}\n pays to ${ethers.isAddress(String(m.payTo ?? "")) ? ethers.getAddress(m.payTo) : "?"}; ${Number.isFinite(Number(m.settled?.count)) ? Number(m.settled.count) : 0} payments settled, ${oneLine(vol(m.settled?.volume), 40)}`);
586
+ const rows = hits.slice(0, 25).map((m) => `- ${oneLine(m.name || "(unnamed)", 60)} — ${httpsUrl(m.url)}\n ${oneLine(m.description || "", 280)}\n pays to ${ethers.isAddress(String(m.payTo ?? "")) ? ethers.getAddress(m.payTo) : "?"}; ${Number.isFinite(Number(m.settled?.count)) ? Number(m.settled.count) : 0} payments settled, ${oneLine(vol(m.settled?.volume), 40)}; ${m.approved === true ? "approved by Priors" : "self-registered, not reviewed by Priors"}`);
546
587
  return `${hits.length} service${hits.length === 1 ? "" : "s"}${q ? ` matching "${oneLine(q, 100)}"` : ""}${hits.length > 25 ? " (first 25 shown)" : ""}. Names, links and descriptions are the merchants' own words:\n${fenced(rows.join("\n"), "merchant listings")}\nPay one with pay_url.`;
547
588
  });
548
589