@priors/mcp 0.2.8 → 0.2.9

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
@@ -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.8"],
72
+ "args": ["-y", "@priors/mcp@0.2.9"],
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.8"],
94
+ "args": ["-y", "@priors/mcp@0.2.9"],
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.8`
104
+ or, for your user only: `claude mcp add priors --scope user -e PRIORS_KEY="$PRIORS_KEY" -- npx -y @priors/mcp@0.2.9`
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@priors/mcp",
3
3
  "mcpName": "io.github.priors-agents/priors",
4
- "version": "0.2.8",
4
+ "version": "0.2.9",
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. Key from PRIORS_KEY only.",
7
7
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@modelcontextprotocol/sdk": "^1.30.1",
46
- "@priors/x402": "0.2.8",
46
+ "@priors/x402": "0.2.9",
47
47
  "ethers": "^6.13.4",
48
48
  "undici": "6.29.0",
49
49
  "zod": "^4.6.5"
package/src/server.mjs CHANGED
@@ -313,7 +313,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
313
313
  /** Kept on file before the payment leaves; a failure throws, and the payer then does not send it (own audit: a
314
314
  * record silently lost made a restart or another session sign again). */
315
315
  async function record(key, e) {
316
- if (stateFile) await locked(() => { const m = readState(); m.set(key, e); writeState(m); });
316
+ if (stateFile) await locked(() => {
317
+ const m = readState(), cur = m.get(key); // readState keeps live entries only
318
+ // GHSA-mvvh: another session's authorization for this purchase is still out: never overwrite it and
319
+ // never send a second one (the payer drops this signature unsent, NOT_RECORDED); the next call resends that one.
320
+ if (cur && JSON.stringify(cur.paymentHeaders) !== JSON.stringify(e.paymentHeaders)) throw Object.assign(new Error("another session of this wallet has a payment out for this purchase"), { code: "OTHER_SESSION", prior: cur });
321
+ m.set(key, e); writeState(m);
322
+ });
317
323
  outstanding.set(key, e);
318
324
  }
319
325
  /** After the payment is sent and cannot be unsent: the file is best effort, memory always holds it. */
@@ -436,12 +442,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
436
442
  // Kept for the payer's clock-skew margin past validBefore: the chain's clock may be behind this machine's.
437
443
  for (const [k, v] of outstanding) if (!live(v, now)) outstanding.delete(k); // the file drops them on its next write
438
444
  refresh(); // a payment another server of this wallet (another session) signed for this purchase is resent, not signed again
439
- // SHORTCUT: two sessions of one wallet paying the same URL in the same instant (between this read and the other's
440
- // onSigned, about one 402 round trip) can still both sign: onSigned records a payment, it does not look for another
441
- // session's. Ceiling:
442
- // one extra payment of at most max_price_usd to the merchant the user chose, counted in each session's cap (the
443
- // P-15 class, Low). Upgrade trigger: a report of it, or agents running pay_url concurrently on one wallet: reserve
444
- // the purchase in the file under the lock before the 402 request, or derive the EIP-3009 nonce per purchase.
445
+ // Two sessions of one wallet paying the same purchase in the same instant (between this read and the other's
446
+ // onSigned) both sign, but only the first record() keeps its payment: the second finds it on file under the lock and
447
+ // drops its own signature unsent, and a later call resends the first (GHSA-mvvh).
448
+ // SHORTCUT: the lock is best effort (a writer stops waiting after 2 s), so behind a lock held that long both payments
449
+ // can still be recorded and sent. Ceiling: one extra payment of at most max_price_usd to the merchant the user chose,
450
+ // counted in each session's cap (the P-15 class, Low). Upgrade trigger: a report of it: derive the EIP-3009 nonce
451
+ // per purchase.
445
452
  const lines = [];
446
453
  const prior = outstanding.get(purchase);
447
454
  // A payment kept without its body (by an earlier version, or for a call without one) cannot be matched to a call with
@@ -480,6 +487,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
480
487
  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.` : ""}`);
481
488
  }
482
489
  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.` : "";
490
+ if (e?.code === "NOT_RECORDED" && e.cause?.code === "OTHER_SESSION") { outstanding.set(purchase, e.cause.prior); throw new ToolError(`Another session of this wallet signed a payment of ${usd(e.cause.prior.price)} for this purchase a moment ago, and it may still settle until ${when(e.cause.prior.validBefore + X.SKEW_SECONDS)}. Nothing was sent from this call and no payment of its own is out: calling pay_url again resends that same payment, never a new one.${loan}`); }
483
491
  if (e?.code === "NOT_RECORDED") throw new ToolError(`A payment was signed but could not be written to PRIORS_STATE_DIR (${explain(e.cause ?? e)}), so it was not sent and nothing can be settled. Fix that directory, or set PRIORS_STATE_DIR=off to keep payments in this process's memory only, then call again.${loan}`);
484
492
  if (e?.name === "TimeoutError" || e?.name === "AbortError") throw new ToolError(`${method} ${u.href} did not answer in time. Nothing was signed or paid.${loan}`);
485
493
  if (loan) throw new ToolError(`${explain(e)}.${loan}`);