@priors/mcp 0.1.5 → 0.1.7
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 +5 -4
- package/package.json +1 -1
- package/src/server.mjs +43 -5
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ repaying.
|
|
|
26
26
|
| `credit_status(agent_id?)` | line, drawn, available, backer, record, score, open loans and due dates | no (with `agent_id`) |
|
|
27
27
|
| `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee | yes |
|
|
28
28
|
| `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 |
|
|
29
|
-
| `score_of(agent_id)` | any agent's score (0 to 1000) and repayment record | no |
|
|
29
|
+
| `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 |
|
|
30
30
|
| `find_services(query?)` | services registered with the Priors facilitator that accept USDG (`GET /merchants`) | no |
|
|
31
31
|
|
|
32
32
|
Tools that move money state the amounts in their answer, are marked destructive for MCP clients, and their
|
|
@@ -50,6 +50,7 @@ dedicated agent wallet holding only what the agent may spend.
|
|
|
50
50
|
| `PRIORS_MAX_SPEND_USD` | `5` | most `pay_url` may sign in total while the server runs (counted when signed) |
|
|
51
51
|
| `PRIORS_MAX_BORROW_TOTAL_USD` | `25` | most `borrow` and `pay_url` may borrow in total while the server runs |
|
|
52
52
|
| `PRIORS_ALLOW_LOCAL` | off | `1` lets `pay_url` reach `http://localhost` and private addresses (local testing only) |
|
|
53
|
+
| `PRIORS_SCORE_V2` | `https://priors.trade/api/score-v2` | where `score_of` reads Priors Score v2; `off` shows the on-chain score only |
|
|
53
54
|
|
|
54
55
|
Contract addresses (pool, lens, registry, USDG) come from `deployments/4663.v2.json`, bundled in the package.
|
|
55
56
|
|
|
@@ -62,7 +63,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
|
|
|
62
63
|
"mcpServers": {
|
|
63
64
|
"priors": {
|
|
64
65
|
"command": "npx",
|
|
65
|
-
"args": ["-y", "@priors/mcp@0.1.
|
|
66
|
+
"args": ["-y", "@priors/mcp@0.1.7"],
|
|
66
67
|
"env": {
|
|
67
68
|
"PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
|
|
68
69
|
"PRIORS_AGENT_ID": "1234"
|
|
@@ -84,7 +85,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
84
85
|
"mcpServers": {
|
|
85
86
|
"priors": {
|
|
86
87
|
"command": "npx",
|
|
87
|
-
"args": ["-y", "@priors/mcp@0.1.
|
|
88
|
+
"args": ["-y", "@priors/mcp@0.1.7"],
|
|
88
89
|
"env": {
|
|
89
90
|
"PRIORS_KEY": "${PRIORS_KEY}",
|
|
90
91
|
"PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
|
|
@@ -94,7 +95,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
94
95
|
}
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.1.
|
|
98
|
+
or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.1.7`
|
|
98
99
|
(the key is expanded by your shell from the environment; do not paste it on the command line).
|
|
99
100
|
|
|
100
101
|
## Try it
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@priors/mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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",
|
package/src/server.mjs
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// PRIORS_MAX_SPEND_USD most pay_url may sign in total per process (default 5)
|
|
16
16
|
// PRIORS_MAX_BORROW_TOTAL_USD most borrowed in total per process (default 25)
|
|
17
17
|
// PRIORS_ALLOW_LOCAL "1": pay_url may reach http://localhost and private addresses (testing only)
|
|
18
|
+
// PRIORS_SCORE_V2 where score_of reads Priors Score v2 (default https://priors.trade/api/score-v2; "off": v1 only)
|
|
18
19
|
import { readFileSync } from "node:fs";
|
|
19
20
|
import { randomBytes } from "node:crypto";
|
|
20
21
|
import { lookup as dnsLookup } from "node:dns/promises";
|
|
@@ -151,7 +152,17 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
151
152
|
// One money call at a time (pay_url, borrow, repay): MCP clients may send tool calls concurrently, and each check
|
|
152
153
|
// above (an outstanding payment for this URL, the session totals) must see the previous call's result (Codex review).
|
|
153
154
|
let moneyQueue = Promise.resolve();
|
|
154
|
-
|
|
155
|
+
// The time budget counts from the call's arrival, not from its turn: a call queued behind a slow one must still answer
|
|
156
|
+
// before the client gives up (a client timeout hides the "do not retry" answer and invites a retry).
|
|
157
|
+
const serial = (fn) => (args) => {
|
|
158
|
+
const deadline = Date.now() + callBudgetMs;
|
|
159
|
+
const run = moneyQueue.then(() => {
|
|
160
|
+
if (Date.now() >= deadline - Math.min(1000, callBudgetMs / 10)) throw new ToolError("another payment call was still running and this one ran out of time before it could start. Nothing was signed or paid: try again.");
|
|
161
|
+
return fn(args, deadline);
|
|
162
|
+
});
|
|
163
|
+
moneyQueue = run.catch(() => {});
|
|
164
|
+
return run;
|
|
165
|
+
};
|
|
155
166
|
// The real network goes through the rebinding-proof dispatcher; an injected fetchImpl (tests, embedders) is used as given.
|
|
156
167
|
const payFetch = fetchImpl === globalThis.fetch && !allowLocal ? guardedFetch() : fetchImpl;
|
|
157
168
|
|
|
@@ -270,7 +281,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
270
281
|
max_borrow_usd: z.number().nonnegative().optional().describe("Most to borrow from the Priors line if the wallet is short, in US dollars. Default 0: never borrow."),
|
|
271
282
|
},
|
|
272
283
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
|
|
273
|
-
}, serial(async ({ url, method = "GET", body, max_price_usd, max_borrow_usd }) => {
|
|
284
|
+
}, serial(async ({ url, method = "GET", body, max_price_usd, max_borrow_usd }, deadline) => {
|
|
274
285
|
const signer = needWallet("pay_url");
|
|
275
286
|
const u = await checkTarget(url);
|
|
276
287
|
if (method === "GET" && body !== undefined) throw new ToolError("A GET request cannot carry a body: use POST (or another method) with body.");
|
|
@@ -291,7 +302,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
291
302
|
let r;
|
|
292
303
|
if (prior) {
|
|
293
304
|
// A payment for this purchase is already out and still cashable: send that same one, never a second.
|
|
294
|
-
r = await X.createPayer({ signer, fetchImpl: payFetch, pendingRetries: 2, maxSleepMs: 10_000, timeoutMs: requestTimeoutMs, signal: AbortSignal.timeout(
|
|
305
|
+
r = await X.createPayer({ signer, fetchImpl: payFetch, pendingRetries: 2, maxSleepMs: 10_000, timeoutMs: requestTimeoutMs, signal: AbortSignal.timeout(Math.max(1, deadline - Date.now())), ...(sleep ? { sleep } : {}) }).resend(url, prior.paymentHeaders, init);
|
|
295
306
|
r = { ...r, requirement: prior.requirement, paid: r.response.ok ? prior.price : 0n, borrowed: 0n, signed: prior, resent: true, ...(r.response.ok ? { settlement: settlementOf(r.response) } : {}) };
|
|
296
307
|
lines.push("No new payment was signed: the same signed payment was sent again.");
|
|
297
308
|
} else {
|
|
@@ -299,7 +310,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
299
310
|
if (maxBorrow > 0n && session.borrowed + maxBorrow > borrowTotalCap) throw new ToolError(`this could bring what is borrowed in this session to ${usd(session.borrowed + maxBorrow)}, above ${usd(borrowTotalCap)} (PRIORS_MAX_BORROW_TOTAL_USD).`);
|
|
300
311
|
let agentId;
|
|
301
312
|
if (maxBorrow > 0n) { agentId = await resolveAgent(); await needController(agentId); }
|
|
302
|
-
const payer = X.createPayer({ signer, maxPrice, maxBorrow, fetchImpl: payFetch, pendingRetries: 2, maxSleepMs: 10_000, timeoutMs: requestTimeoutMs, signal: AbortSignal.timeout(
|
|
313
|
+
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 } : {}) });
|
|
303
314
|
try { r = await payer.pay(url, init); } catch (e) {
|
|
304
315
|
if (e?.name === "TimeoutError" || e?.name === "AbortError") throw new ToolError(`${method} ${u.href} did not answer in time. Nothing was signed or paid.`);
|
|
305
316
|
throw e;
|
|
@@ -366,19 +377,46 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
366
377
|
});
|
|
367
378
|
|
|
368
379
|
// ---- score_of ------------------------------------------------------------------------------------------------
|
|
380
|
+
// Priors Score v2 (open weights, published at /api/score-v2) next to the on-chain v1: optional. Not published
|
|
381
|
+
// (404/503), slow or unreachable means v1 only, never a tool error; a defaulted agent never shows a positive v2.
|
|
382
|
+
// Same rules and wording as the hosted MCP (mcp.priors.trade).
|
|
383
|
+
const scoreV2Url = String(env.PRIORS_SCORE_V2 ?? "https://priors.trade/api/score-v2").trim();
|
|
384
|
+
async function scoreV2Line(id, defaulted) {
|
|
385
|
+
if (!scoreV2Url || scoreV2Url === "off") return null;
|
|
386
|
+
try {
|
|
387
|
+
const u = new URL(scoreV2Url);
|
|
388
|
+
u.searchParams.set("agent", String(id));
|
|
389
|
+
const r = await fetchImpl(u.href, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(5_000) });
|
|
390
|
+
if (!r.ok) return null;
|
|
391
|
+
const t = await r.text();
|
|
392
|
+
if (t.length > 65_536) return null;
|
|
393
|
+
const s = JSON.parse(t)?.score;
|
|
394
|
+
const num = (x) => (x !== null && x !== "" && Number.isFinite(Number(x)) ? Number(x) : null);
|
|
395
|
+
if (!s || Number(s.agentId) !== Number(id) || num(s.score) === null || num(s.rung) === null) return null;
|
|
396
|
+
if (defaulted && num(s.score) > 0) return null;
|
|
397
|
+
const name = String(s.rungName || "").replace(/[^\w -]/g, "").slice(0, 30);
|
|
398
|
+
const inc = Array.isArray(s.components) ? s.components.find((c) => c && c.key === "income") : null;
|
|
399
|
+
const payers = num(s.detail?.distinctPayers) ?? 0;
|
|
400
|
+
return `Priors Score v2: ${num(s.score)}/1000, rung ${num(s.rung)}${name ? ` (${name})` : ""}`
|
|
401
|
+
+ (inc && num(inc.points) !== null ? `; x402 income ${num(inc.points)}/${num(inc.max)} from ${payers} distinct payer(s).` : ".");
|
|
402
|
+
} catch (_) { return null; }
|
|
403
|
+
}
|
|
404
|
+
|
|
369
405
|
tool("score_of", {
|
|
370
406
|
title: "Priors score of an agent",
|
|
371
|
-
description: "Look up any agent's Priors score (0 to 1000) and repayment record on Robinhood Chain: a public, on-chain credit record that cannot be faked. Useful before trusting or paying an agent. Read-only.",
|
|
407
|
+
description: "Look up any agent's Priors score (0 to 1000) and repayment record on Robinhood Chain: a public, on-chain credit record that cannot be faked, plus the open Priors Score v2 and its trust rung when published. Useful before trusting or paying an agent. Read-only.",
|
|
372
408
|
inputSchema: { agent_id: z.number().int().nonnegative().describe("Priors (ERC-8004) agent id.") },
|
|
373
409
|
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
374
410
|
}, async ({ agent_id }) => {
|
|
375
411
|
const s = await credit.status(BigInt(agent_id));
|
|
376
412
|
if (!s.enrolled) return `Agent #${agent_id} has no Priors record: score 0 (never enrolled).`;
|
|
377
413
|
const age = s.enrolledAt ? Math.floor((Date.now() / 1000 - s.enrolledAt) / 86400) : null;
|
|
414
|
+
const v2 = await scoreV2Line(agent_id, s.defaulted);
|
|
378
415
|
return [
|
|
379
416
|
`Agent #${agent_id}: score ${s.score ?? "unavailable"}/1000${s.defaulted ? ", and it has DEFAULTED on a loan" : ""}.`,
|
|
380
417
|
`Record: ${s.loansRepaid} loans repaid (${s.qualifiedRepaid} qualified), ${usd(s.volumeRepaid)} repaid, ${s.openLoans.length} open now.`,
|
|
381
418
|
`${s.sponsor === 0n ? "No backer now." : `Backed by root #${s.sponsor} with a ${usd(s.line)} line.`}${age !== null ? ` On Priors for ${age} days.` : ""}`,
|
|
419
|
+
...(v2 ? [v2] : []),
|
|
382
420
|
].join("\n");
|
|
383
421
|
});
|
|
384
422
|
|