@priors/mcp 0.2.3 → 0.2.4
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 +6 -6
- package/package.json +2 -2
- package/src/server.mjs +34 -9
package/README.md
CHANGED
|
@@ -21,12 +21,12 @@ repaying.
|
|
|
21
21
|
|
|
22
22
|
| tool | what it does | needs the key |
|
|
23
23
|
|---|---|---|
|
|
24
|
-
| `pay_url(url, method?, body?, max_price_usd?, max_borrow_usd?)` | fetch an https URL, pay its x402 402 in USDG if the price is ≤ `max_price_usd` (default **$0.10**); borrows the gap only if `max_borrow_usd` is given. Refuses private and local addresses, never follows a redirect, answers within 45 s, and never signs a second payment for a purchase that is still pending, until its validBefore plus 60 s (a new call resends the same one, also after a restart, in a new session or from another session of the same wallet: see `PRIORS_STATE_DIR`) | yes |
|
|
24
|
+
| `pay_url(url, method?, body?, max_price_usd?, max_borrow_usd?)` | fetch an https URL, pay its x402 402 in USDG if the price is ≤ `max_price_usd` (default **$0.10**); borrows the gap only if `max_borrow_usd` is given. Refuses private and local addresses, never follows a redirect, answers within 45 s, and never signs a second payment for a purchase (the same method, URL and body) that is still pending, until its validBefore plus 60 s (a new call resends the same one, also after a restart, in a new session or from another session of the same wallet: see `PRIORS_STATE_DIR`) | yes |
|
|
25
25
|
| `wallet_balance(address?)` | USDG and gas ETH of the wallet (or any address) | no (with `address`) |
|
|
26
26
|
| `credit_status(agent_id?)` | line, drawn, available, backer, record, score, open loans and due dates; on a stock line, the stock tokens behind it, and `available` capped by what the stock vault lets it draw | no (with `agent_id`) |
|
|
27
27
|
| `stock_assets(symbol?)` | the stock tokens the Priors stock vault accepts: live Chainlink price, whether it lends against each now (or why not: a sharp price move, a multiplier change, a paused or blocked token), loan-to-value | no |
|
|
28
28
|
| `stock_position(agent_id?)` | the stock tokens behind an agent's stock line: amount, what the vault values them at, loan-to-value, what the line can draw now, any lending hold | no (with `agent_id`) |
|
|
29
|
-
| `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee | yes |
|
|
29
|
+
| `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee. A borrow sent whose answer is lost is counted and said to be possibly open (check `credit_status`) | 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
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 |
|
|
@@ -50,7 +50,7 @@ dedicated agent wallet holding only what the agent may spend.
|
|
|
50
50
|
| `PRIORS_MAX_PRICE_USD` | `1.00` | ceiling on what `pay_url` may be told to pay per call |
|
|
51
51
|
| `PRIORS_MAX_BORROW_USD` | `25` | ceiling on `borrow` and on `pay_url`'s `max_borrow_usd` |
|
|
52
52
|
| `PRIORS_MAX_SPEND_USD` | `5` | most `pay_url` may sign in total while the server runs (counted when signed) |
|
|
53
|
-
| `PRIORS_MAX_BORROW_TOTAL_USD` | `25` | most `borrow` and `pay_url` may borrow in total while the server runs |
|
|
53
|
+
| `PRIORS_MAX_BORROW_TOTAL_USD` | `25` | most `borrow` and `pay_url` may borrow in total while the server runs (a borrow sent whose answer was lost counts: it may have opened a loan) |
|
|
54
54
|
| `PRIORS_ALLOW_LOCAL` | off | `1` lets `pay_url` reach `http://localhost` and private addresses (local testing only) |
|
|
55
55
|
| `PRIORS_SCORE_V2` | `https://priors.trade/api/score-v2` | where `score_of` reads Priors Score v2; `off` shows the on-chain score only |
|
|
56
56
|
| `PRIORS_STOCK_VAULT` | the bundled deployments file's `stockVault` | the stock vault the stock tools and `credit_status` read |
|
|
@@ -69,7 +69,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
|
|
|
69
69
|
"mcpServers": {
|
|
70
70
|
"priors": {
|
|
71
71
|
"command": "npx",
|
|
72
|
-
"args": ["-y", "@priors/mcp@0.2.
|
|
72
|
+
"args": ["-y", "@priors/mcp@0.2.4"],
|
|
73
73
|
"env": {
|
|
74
74
|
"PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
|
|
75
75
|
"PRIORS_AGENT_ID": "1234"
|
|
@@ -91,7 +91,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
91
91
|
"mcpServers": {
|
|
92
92
|
"priors": {
|
|
93
93
|
"command": "npx",
|
|
94
|
-
"args": ["-y", "@priors/mcp@0.2.
|
|
94
|
+
"args": ["-y", "@priors/mcp@0.2.4"],
|
|
95
95
|
"env": {
|
|
96
96
|
"PRIORS_KEY": "${PRIORS_KEY}",
|
|
97
97
|
"PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
|
|
@@ -101,7 +101,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
101
101
|
}
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.2.
|
|
104
|
+
or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.2.4`
|
|
105
105
|
(the key is expanded by your shell from the environment; do not paste it on the command line).
|
|
106
106
|
|
|
107
107
|
## Try it
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@priors/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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.
|
|
45
|
+
"@priors/x402": "0.2.4",
|
|
46
46
|
"ethers": "^6.13.4",
|
|
47
47
|
"undici": "6.29.0",
|
|
48
48
|
"zod": "^4.6.5"
|
package/src/server.mjs
CHANGED
|
@@ -128,7 +128,11 @@ const when = (t) => new Date(Number(t) * 1000).toISOString().replace(".000Z", "Z
|
|
|
128
128
|
const tokens = (units, decimals) => (Number.isInteger(decimals) ? ethers.formatUnits(units, decimals).replace(/\.0$/, "") : String(units));
|
|
129
129
|
/** One line for the stock collateral behind a line (creditStatus.collateral, or a stockPosition). */
|
|
130
130
|
export function collateralText(c, symbol = c.symbol, decimals = c.decimals) {
|
|
131
|
-
const
|
|
131
|
+
const held = symbol ? `${tokens(c.amount, decimals)} ${symbol}` : `${c.amount} base units of ${c.token}`;
|
|
132
|
+
// after an issuer burn from the vault the position is paid its share (`payout`), which `value` prices
|
|
133
|
+
const what = c.payout !== undefined && c.payout !== null
|
|
134
|
+
? `${symbol ? `${tokens(c.payout, decimals)} ${symbol}` : `${c.payout} base units of ${c.token}`}, of ${symbol ? tokens(c.amount, decimals) : c.amount} deposited: an issuer burn left the vault short,`
|
|
135
|
+
: held;
|
|
132
136
|
return `Backed by ${what}${c.value !== null ? ` worth ${usd(c.value)} to the vault` : " (not priced for new loans right now)"}, at ${Number(c.ltvBps) / 100}% loan-to-value: ${usd(c.borrowRoom)} can be drawn now.`
|
|
133
137
|
+ (c.hold ? ` New loans wait: ${c.holdReason || "a lending hold"}.` : "") + (c.closing ? " Closing: no new loans." : "");
|
|
134
138
|
}
|
|
@@ -173,11 +177,12 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
173
177
|
const sleep = deps.sleep; // undefined: the library's own
|
|
174
178
|
const requestTimeoutMs = deps.requestTimeoutMs ?? 15_000;
|
|
175
179
|
const callBudgetMs = deps.callBudgetMs ?? 45_000; // under the MCP clients' usual 60 s request timeout
|
|
176
|
-
// Payments signed and not (yet) counted as paid, by
|
|
177
|
-
// them, so another pay_url for the same purchase resends
|
|
180
|
+
// Payments signed and not (yet) counted as paid, by purchase (X.purchaseKey: the method, the URL without its fragment,
|
|
181
|
+
// and the body): until validBefore the merchant can still cash them, so another pay_url for the same purchase resends
|
|
182
|
+
// that payment instead of signing a second one.
|
|
178
183
|
const outstanding = new Map();
|
|
179
184
|
// One money call at a time (pay_url, borrow, repay): MCP clients may send tool calls concurrently, and each check
|
|
180
|
-
// above (an outstanding payment for this
|
|
185
|
+
// above (an outstanding payment for this purchase, the session totals) must see the previous call's result (Codex review).
|
|
181
186
|
let moneyQueue = Promise.resolve();
|
|
182
187
|
// The time budget counts from the call's arrival, not from its turn: a call queued behind a slow one must still answer
|
|
183
188
|
// before the client gives up (a client timeout hides the "do not retry" answer and invites a retry).
|
|
@@ -406,9 +411,12 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
406
411
|
let json = false; try { JSON.parse(body); json = true; } catch (_) { /* text */ }
|
|
407
412
|
init.body = body; init.headers = { "content-type": json ? "application/json" : "text/plain; charset=utf-8" };
|
|
408
413
|
}
|
|
414
|
+
// The method, the URL without its fragment (url#a and url#b are the same purchase) and the body: another body at the
|
|
415
|
+
// same URL is another purchase, quoted and priced on its own (GHSA-xqp9).
|
|
416
|
+
const purchase = await X.purchaseKey(new Request(u.href, init));
|
|
409
417
|
const target = new URL(u.href);
|
|
410
|
-
target.hash = "";
|
|
411
|
-
const
|
|
418
|
+
target.hash = "";
|
|
419
|
+
const urlOnly = `${method} ${target.href}`; // the whole key without a body, and every key written before the body was in it
|
|
412
420
|
const now = Math.floor(Date.now() / 1000);
|
|
413
421
|
// Kept for the payer's clock-skew margin past validBefore: the chain's clock may be behind this machine's.
|
|
414
422
|
for (const [k, v] of outstanding) if (!live(v, now)) outstanding.delete(k); // the file drops them on its next write
|
|
@@ -420,6 +428,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
420
428
|
// the purchase in the file under the lock before the 402 request, or derive the EIP-3009 nonce per purchase.
|
|
421
429
|
const lines = [];
|
|
422
430
|
const prior = outstanding.get(purchase);
|
|
431
|
+
// A payment kept without its body (by an earlier version, or for a call without one) cannot be matched to a call with
|
|
432
|
+
// a body: resending it could serve another purchase, signing could pay this one twice. Nothing is done until it expires.
|
|
433
|
+
const unmatched = !prior && purchase !== urlOnly ? outstanding.get(urlOnly) : undefined;
|
|
434
|
+
if (unmatched) {
|
|
435
|
+
const until = when(unmatched.validBefore + X.SKEW_SECONDS);
|
|
436
|
+
throw new ToolError(`A payment of ${usd(unmatched.price)} to ${unmatched.payTo} for ${urlOnly} was signed earlier and kept without its request body (by an earlier version of this server, or for a call without a body), and the merchant may still settle it until ${until}. It cannot be told apart from this purchase, so nothing was signed: do NOT call pay_url again for this URL before ${until}; check wallet_balance.`);
|
|
437
|
+
}
|
|
423
438
|
let r;
|
|
424
439
|
let signedPrice = null; // what the payer checked and signed, never a merchant field read again here
|
|
425
440
|
if (prior) {
|
|
@@ -439,11 +454,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
439
454
|
try { r = await payer.pay(url, init); } catch (e) {
|
|
440
455
|
// What the error carries was done: a loan taken and a payment signed are counted, whatever failed after.
|
|
441
456
|
if (e?.borrowed > 0n) session.borrowed += e.borrowed;
|
|
457
|
+
// A borrow sent whose answer was lost may have mined (GHSA-v9xj): counted above, and said, never "nothing done".
|
|
458
|
+
if (e?.unconfirmed) throw new ToolError(`A borrow of ${usd(e.borrowed)} was sent${e.hash ? ` (tx ${e.hash})` : ""} and its answer was lost (${explain(e.cause ?? e)}), so it may have opened a loan: check credit_status, and repay it with the repay tool before its due date. Nothing was signed or paid.`);
|
|
442
459
|
if (e?.signed) {
|
|
443
460
|
if (signedPrice === null) { signedPrice = maxPrice; session.spent += maxPrice; await record(purchase, { ...e.signed, price: maxPrice, payTo: e.requirement.payTo }); } // not reached: onSigned ran
|
|
444
461
|
const price = signedPrice;
|
|
445
462
|
const until = when(e.signed.validBefore + X.SKEW_SECONDS);
|
|
446
|
-
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.` : ""}`);
|
|
463
|
+
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 purchase (the same method, URL and body) 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.` : ""}`);
|
|
447
464
|
}
|
|
448
465
|
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.` : "";
|
|
449
466
|
if (e?.name === "TimeoutError" || e?.name === "AbortError") throw new ToolError(`${method} ${u.href} did not answer in time. Nothing was signed or paid.${loan}`);
|
|
@@ -465,7 +482,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
465
482
|
lines.unshift(`Paid ${usd(r.paid)}${r.x402Version ? ` (x402 v${r.x402Version})` : ""} to ${r.requirement.payTo} for ${method} ${u.href}: ${status}.${tx ? (TX_RE.test(String(tx)) ? ` Settlement tx ${tx}.` : " (The merchant's settlement id is not a transaction hash; not shown.)") : ""}`);
|
|
466
483
|
} else {
|
|
467
484
|
const until = when(r.signed.validBefore + X.SKEW_SECONDS);
|
|
468
|
-
lines.unshift(`A payment of ${usd(signedPrice)} to ${r.requirement.payTo} was signed and sent (${status}), and the merchant may still settle it until ${until}, so do NOT call pay_url again for this URL before ${until}; check wallet_balance. A later call for this
|
|
485
|
+
lines.unshift(`A payment of ${usd(signedPrice)} to ${r.requirement.payTo} was signed and sent (${status}), and the merchant may still settle it until ${until}, so do NOT call pay_url again for this purchase (the same method, URL and body) before ${until}; check wallet_balance. A later call for this purchase only resends this same payment.`);
|
|
469
486
|
}
|
|
470
487
|
const loc = r.response.status >= 300 && r.response.status < 400 ? r.response.headers.get("location") : null;
|
|
471
488
|
if (loc) lines.push(`The server redirected (not followed): ${fenced(oneLine(loc, 500), "redirect target")}`);
|
|
@@ -603,7 +620,15 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
|
|
|
603
620
|
await needController(id);
|
|
604
621
|
const q = await credit.quote(id, amount, term);
|
|
605
622
|
if (dry_run) return `Quote for agent #${id}: borrow ${usd(amount)} for ${days} days, fee ${usd(q.fee)}, ${usd(q.due)} due at the end. Nothing was borrowed.`;
|
|
606
|
-
|
|
623
|
+
let r;
|
|
624
|
+
try { r = await credit.borrow(id, amount, term); } catch (e) {
|
|
625
|
+
// sent, and its answer lost: it may have mined, so it is counted and said (GHSA-v9xj)
|
|
626
|
+
if (e?.unconfirmed) {
|
|
627
|
+
session.borrowed += e.borrowed > 0n ? e.borrowed : amount;
|
|
628
|
+
throw new ToolError(`A borrow of ${usd(amount)} for agent #${id} was sent${e.hash ? ` (tx ${e.hash})` : ""} and its answer was lost (${explain(e.cause ?? e)}), so it may have opened a loan: check credit_status before borrowing again, and repay it with the repay tool before its due date.`);
|
|
629
|
+
}
|
|
630
|
+
throw e;
|
|
631
|
+
}
|
|
607
632
|
session.borrowed += r.principal;
|
|
608
633
|
return `Borrowed ${usd(r.principal)} for agent #${id}${r.loanId !== null ? ` as loan #${r.loanId}` : ""}: fee ${usd(r.fee)}, so ${usd(r.principal + r.fee)} is due${r.dueAt ? ` by ${when(r.dueAt)}` : ""}. The USDG is in ${wallet.address}. Tx ${r.hash}.`;
|
|
609
634
|
}));
|