@priors/mcp 0.6.1 → 0.6.3

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
@@ -42,7 +42,10 @@ repaying.
42
42
  | `pt_redeem(amount_pt \| "all", slippage_bps?, dry_run?)` | redeem the wallet's PT-USDG for USDG 1:1, from maturity (2027-03-25) on; needs ETH for gas | yes |
43
43
 
44
44
  Tools that move money state the amounts in their answer, are marked destructive for MCP clients, and their
45
- descriptions tell the assistant to confirm with you first. Merchant text (response bodies, listings, redirect targets)
45
+ descriptions tell the assistant to confirm with you first. They run one at a time and each answers within 45 s, under an
46
+ MCP client's usual 60 s timeout: one whose transactions have not confirmed by then says so and goes on, and a money
47
+ call made meanwhile does nothing and says so. After two minutes a new call can act while that one still runs; what that
48
+ one may still borrow, sign or save keeps counting against the session caps until it ends. Merchant text (response bodies, listings, redirect targets)
46
49
  comes back between random `<<merchant-data …>>` markers, as data. They act on Robinhood Chain mainnet.
47
50
 
48
51
  ## Savings
@@ -132,7 +135,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
132
135
  "mcpServers": {
133
136
  "priors": {
134
137
  "command": "npx",
135
- "args": ["-y", "@priors/mcp@0.6.1"],
138
+ "args": ["-y", "@priors/mcp@0.6.3"],
136
139
  "env": {
137
140
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
138
141
  "PRIORS_AGENT_ID": "1234"
@@ -154,7 +157,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
154
157
  "mcpServers": {
155
158
  "priors": {
156
159
  "command": "npx",
157
- "args": ["-y", "@priors/mcp@0.6.1"],
160
+ "args": ["-y", "@priors/mcp@0.6.3"],
158
161
  "env": {
159
162
  "PRIORS_KEY": "${PRIORS_KEY}",
160
163
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -164,7 +167,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
164
167
  }
165
168
  ```
166
169
 
167
- or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.6.1`
170
+ or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.6.3`
168
171
  (the key is expanded by your shell from the environment; do not paste it on the command line).
169
172
 
170
173
  ## Try it
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@priors/mcp",
3
3
  "mcpName": "io.github.priors-agents/priors",
4
- "version": "0.6.1",
4
+ "version": "0.6.3",
5
5
  "private": false,
6
6
  "description": "MCP server for Priors on Robinhood Chain: pay x402 URLs in USDG, read balances, credit lines and scores, borrow and repay, and buy, sell and redeem PT-USDG. Key from PRIORS_KEY only.",
7
7
  "type": "module",
package/src/server.mjs CHANGED
@@ -246,10 +246,33 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
246
246
  if (hold) {
247
247
  const h = hold;
248
248
  await Promise.race([h, new Promise((ok) => setTimeout(ok, Math.max(0, deadline - margin - Date.now())).unref?.())]);
249
- if (hold === h) throw new ToolError("a savings withdrawal from an earlier call is still in flight. Nothing was done: check the savings tool and try again in a minute.");
249
+ if (hold === h) throw new ToolError(h.busy || "a savings withdrawal from an earlier call is still in flight. Nothing was done: check the savings tool and try again in a minute.");
250
+ // a call queued behind one that ran out of time (most likely its retry) never goes ahead on its own (GHSA-rg79)
251
+ if (h.busy) throw new ToolError(h.busy);
250
252
  }
251
253
  if (Date.now() >= deadline - margin) 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.");
252
- return fn(args, deadline);
254
+ // Every money call answers by its deadline, whatever it waits for (GHSA-rg79: pt_buy waited for its receipts past the
255
+ // client's timeout, the model saw nothing, and its retry bought again). One still running then goes on, and holds
256
+ // every later money call, as a savings withdrawal in flight does: what it sent may still land.
257
+ // What a call may still borrow, sign or save counts against the session caps from the moment its check passes
258
+ // (`count`, with no await between the two) until it ends; then only what it did, counted as before. The hold ends
259
+ // after HOLD_MAX_MS even while the call runs, and a call made then runs beside it: its check read a total that left
260
+ // the first one out, and a second borrow passed PRIORS_MAX_BORROW_TOTAL_USD (GHSA-cq9v). One that never ends stays
261
+ // counted, the safe direction (as a borrow whose answer was lost, GHSA-v9xj).
262
+ const kept = {};
263
+ const count = (k, amount) => { session[k] += amount; kept[k] = (kept[k] ?? 0n) + amount; };
264
+ const p = fn(args, deadline, count).finally(() => { for (const k of Object.keys(kept)) session[k] -= kept[k]; });
265
+ let timer;
266
+ const late = new Promise((_, no) => {
267
+ timer = setTimeout(() => {
268
+ const h = Object.assign(Promise.race([p.then(() => {}, () => {}), new Promise((ok) => setTimeout(ok, HOLD_MAX_MS).unref?.())]).then(() => { if (hold === h) hold = null; }),
269
+ { busy: "Nothing was done by this call: an earlier money call ran out of time while still running, and what it sent may still land. Check the wallet (wallet_balance, credit_status, savings or pt_position) before calling again." });
270
+ hold = h;
271
+ no(new ToolError(`this call did not finish within ${Math.round(callBudgetMs / 1000)} s and is still running: a transaction it sent may still land, and it may still send the rest of what it was asked to do. Do NOT call it again for the same thing; check the wallet (wallet_balance, credit_status, savings or pt_position) in a minute. Money calls made meanwhile do nothing.`));
272
+ }, Math.max(0, deadline + margin - Date.now()));
273
+ timer.unref?.();
274
+ });
275
+ try { return await Promise.race([p, late]); } finally { clearTimeout(timer); }
253
276
  });
254
277
  moneyQueue = run.catch(() => {});
255
278
  return run;
@@ -590,7 +613,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
590
613
  use_savings: z.boolean().optional().describe("Default true: once the price is known, if the wallet holds less, first take the difference out of the agent's savings, before any borrowing."),
591
614
  },
592
615
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
593
- }, serial(async ({ url, method = "GET", body, max_price_usd, max_borrow_usd, use_savings = true }, deadline) => {
616
+ }, serial(async ({ url, method = "GET", body, max_price_usd, max_borrow_usd, use_savings = true }, deadline, count) => {
594
617
  const signer = needWallet("pay_url");
595
618
  const u = await checkTarget(url);
596
619
  if (method === "GET" && body !== undefined) throw new ToolError("A GET request cannot carry a body: use POST (or another method) with body.");
@@ -639,6 +662,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
639
662
  } else {
640
663
  if (session.spent + maxPrice > spendCap) throw new ToolError(`this would bring what pay_url may sign in this session to ${usd(session.spent + maxPrice)}, above ${usd(spendCap)} (PRIORS_MAX_SPEND_USD). ${usd(session.spent)} was signed so far; the user can raise the limit and restart the server.`);
641
664
  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).`);
665
+ count("spent", maxPrice); count("borrowed", maxBorrow); // the most it may sign and borrow, until it ends (GHSA-cq9v)
642
666
  let agentId;
643
667
  if (maxBorrow > 0n) { agentId = await resolveAgent(); await needController(agentId); }
644
668
  // The agent's own savings before a loan: once the 402 names the price, only what the wallet is short of.
@@ -813,12 +837,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
813
837
  dry_run: z.boolean().optional().describe("true: only quote the fee and due amount, borrow nothing."),
814
838
  },
815
839
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
816
- }, serial(async ({ amount_usd, days, dry_run }) => {
840
+ }, serial(async ({ amount_usd, days, dry_run }, _deadline, count) => {
817
841
  needWallet("borrow");
818
842
  const amount = dollars(amount_usd, "amount_usd");
819
843
  if (amount === 0n) throw new ToolError("amount_usd must be above zero");
820
844
  if (amount > maxBorrowCeiling) throw new ToolError(`amount_usd ${X.formatUsdg(amount)} is above this server's ceiling of ${usd(maxBorrowCeiling)} (PRIORS_MAX_BORROW_USD).`);
821
845
  if (!dry_run && session.borrowed + amount > borrowTotalCap) throw new ToolError(`this would bring what is borrowed in this session to ${usd(session.borrowed + amount)}, above ${usd(borrowTotalCap)} (PRIORS_MAX_BORROW_TOTAL_USD).`);
846
+ if (!dry_run) count("borrowed", amount); // until this call ends (GHSA-cq9v)
822
847
  const term = BigInt(Math.round(days * 86400));
823
848
  const id = await resolveAgent();
824
849
  await needController(id);
@@ -968,7 +993,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
968
993
  description: "Move USDG from the configured wallet into the savings vault (Steakhouse USDG on Morpho by default), where it earns the vault's rate (which moves with its markets) until the agent needs it; pay_url and repay take it back out automatically when the wallet is short. Moves real money into a third-party vault, whose risk the agent carries: state the amount to the user and get their go-ahead first. Keep enough in the wallet for loans coming due and payments expected soon. Needs ETH for gas.",
969
994
  inputSchema: { amount_usd: z.number().positive().describe("How much to save, in US dollars of USDG.") },
970
995
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
971
- }, serial(async ({ amount_usd }) => {
996
+ }, serial(async ({ amount_usd }, _deadline, count) => {
972
997
  needSavings();
973
998
  if (savingsOff) throw new ToolError("Savings are off on this server (PRIORS_SAVINGS_VAULT=off): save is disabled. The savings and unsave tools still work.");
974
999
  needWallet("save");
@@ -976,6 +1001,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
976
1001
  if (amount === 0n) throw new ToolError("amount_usd must be above zero");
977
1002
  if (amount > maxSaveCeiling) throw new ToolError(`amount_usd ${X.formatUsdg(amount)} is above this server's ceiling of ${usd(maxSaveCeiling)} per save (PRIORS_MAX_SAVE_USD).`);
978
1003
  if (session.saved + amount > saveTotalCap) throw new ToolError(`this would bring what save moved in this session to ${usd(session.saved + amount)}, above ${usd(saveTotalCap)} (PRIORS_MAX_SAVE_TOTAL_USD).`);
1004
+ count("saved", amount); // until this call ends (GHSA-cq9v)
979
1005
  // Payments signed and not yet settled still need their USDG in the wallet: never save it away from under them.
980
1006
  const nowS = Math.floor(Date.now() / 1000);
981
1007
  refresh(); // another session's pending payments need their USDG too