@priors/mcp 0.8.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @priors/mcp changelog
2
2
 
3
+ ## 0.8.2 (2026-10-10)
4
+
5
+ - **On `@priors/x402` 0.6.4**, whose merchant-side `recordGate` keeps a bounded cache (GHSA-vjcp-qx2h-gr2q). The MCP
6
+ server does not use the gate; nothing else changes from 0.8.1.
7
+
8
+ ## 0.8.1 (2026-10-10)
9
+
10
+ - **`repay` pays only loans the agent's owner now took** (GHSA-mmp8-g8jw-7gqp). A loan opened while someone else
11
+ held the agent (the pool's `Loan.owner` is not the agent's owner now) is refused by `loan_id` and left out by
12
+ `all: true`, which names it and who opened it; nothing is paid for it.
13
+ - **The agent lookup skips an identity that left the wallet** (GHSA-mmp8-g8jw-7gqp). Without `PRIORS_AGENT_ID`, the
14
+ wallet's agent is an identity minted to it since the v2 deploy that never left it: one that went to someone else
15
+ and came back, carrying what they borrowed, now needs `PRIORS_AGENT_ID` like a bought one.
16
+ - **On `@priors/x402` 0.6.3**, whose `repayLoan` refuses such a loan (`NOT_OWNERS_LOAN`) and whose `settleLoans` leaves
17
+ it unpaid, listed in `others`.
18
+
3
19
  ## 0.8.0 (2026-10-09)
4
20
 
5
21
  For agents that run on their own (in ElizaOS, OpenClaw, Hermes or their own code) and read untrusted text all day.
package/README.md CHANGED
@@ -27,7 +27,7 @@ repaying.
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
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
- | `repay(loan_id? \| all, use_savings?)` | repay one of the agent's own loans, or all of them earliest due first; another agent's loan is refused. If the wallet is short of what is due, it first takes the difference out of savings (unless `use_savings: false`). From 0.8.0 its answer ends with share facts for each loan repaid (amount, on time or late, the record's page; also as structured content); the server never posts | yes |
30
+ | `repay(loan_id? \| all, use_savings?)` | repay one of the agent's own loans, or all of them earliest due first; another agent's loan is refused, and (0.8.1) so is a loan opened while someone else held the agent. If the wallet is short of what is due, it first takes the difference out of savings (unless `use_savings: false`). From 0.8.0 its answer ends with share facts for each loan repaid (amount, on time or late, the record's page; also as structured content); the server never posts | yes |
31
31
  | `savings(address?)` | what the wallet (or any address) has saved in the savings vault, how much can come out right now, and the USDG in the wallet | no (with `address`) |
32
32
  | `save(amount_usd)` | move spare USDG from the wallet into the savings vault, where it earns the vault's rate (at most `PRIORS_MAX_SAVE_USD` per call, `PRIORS_MAX_SAVE_TOTAL_USD` per run); needs ETH for gas | yes |
33
33
  | `unsave(amount_usd? \| all)` | take USDG back out of savings into the wallet: a normal withdrawal, and when that is not enough, the rest from the vault's other markets in the same transaction (only where that costs no penalty); refused before any transaction when even that cannot pay it; needs ETH for gas | yes |
@@ -125,7 +125,7 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
125
125
  |---|---|---|
126
126
  | `PRIORS_KEY_FILE` | none | (0.8.0) the path of a file holding the agent wallet's private key, readable by your user only (`chmod 600`; on Windows an access list for you alone); a file others can read is refused and not read. Absolute, or starting with `~/`. Not together with `PRIORS_KEY` |
127
127
  | `PRIORS_KEY` | none | the agent wallet's private key; without it (or `PRIORS_KEY_FILE`) only the read-only tools work |
128
- | `PRIORS_AGENT_ID` | looked up from the identity registry | the Priors agent id the wallet acts for (the lookup finds only identities minted to the wallet since the v2 deploy, never one transferred to it; set it for an older or a bought one, or when the wallet holds several; (0.8.0) required with a daily limit) |
128
+ | `PRIORS_AGENT_ID` | looked up from the identity registry | the Priors agent id the wallet acts for (the lookup finds only identities minted to the wallet since the v2 deploy that never left it, never one transferred to it, nor (0.8.1) one that left and came back; set it for an older, a bought or a returned one, or when the wallet holds several; (0.8.0) required with a daily limit) |
129
129
  | `PRIORS_RPC` | `https://rpc.mainnet.chain.robinhood.com` | JSON-RPC endpoint (a private URL is redacted from every answer) |
130
130
  | `PRIORS_FACILITATOR` | `https://facilitator.priors.trade` | where `find_services` lists merchants |
131
131
  | `PRIORS_MAX_PRICE_USD` | `1.00` | ceiling on what `pay_url` may be told to pay per call |
@@ -171,7 +171,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
171
171
  "mcpServers": {
172
172
  "priors": {
173
173
  "command": "npx",
174
- "args": ["-y", "@priors/mcp@0.8.0"],
174
+ "args": ["-y", "@priors/mcp@0.8.2"],
175
175
  "env": {
176
176
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
177
177
  "PRIORS_AGENT_ID": "1234"
@@ -193,7 +193,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
193
193
  "mcpServers": {
194
194
  "priors": {
195
195
  "command": "npx",
196
- "args": ["-y", "@priors/mcp@0.8.0"],
196
+ "args": ["-y", "@priors/mcp@0.8.2"],
197
197
  "env": {
198
198
  "PRIORS_KEY": "${PRIORS_KEY}",
199
199
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -206,7 +206,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
206
206
  or, for your user only, from a macOS or Linux terminal:
207
207
 
208
208
  ```sh
209
- (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.8.0' priors-mcp ~/.config/priors/agent.key
209
+ (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.8.2' priors-mcp ~/.config/priors/agent.key
210
210
  ```
211
211
 
212
212
  It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
@@ -259,7 +259,7 @@ to approve a borrow; this package, with the key, pays for APIs. With borrowing o
259
259
  approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
260
260
 
261
261
  ```ts
262
- "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.8.0"],
262
+ "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.8.2"],
263
263
  env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
264
264
  PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
265
265
  PRIORS_PAY_HOSTS: "api.example.com" } }
@@ -271,7 +271,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
271
271
  mcp_servers:
272
272
  priors-wallet:
273
273
  command: npx
274
- args: ["-y", "@priors/mcp@0.8.0"]
274
+ args: ["-y", "@priors/mcp@0.8.2"]
275
275
  env:
276
276
  PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
277
277
  PRIORS_AGENT_ID: "7311"
@@ -298,7 +298,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
298
298
  agent's).
299
299
 
300
300
  ```sh
301
- PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.8.0 link-wallet --agent 7311
301
+ PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.8.2 link-wallet --agent 7311
302
302
  ```
303
303
 
304
304
  It reads the registry's EIP-712 domain and refuses to sign for any other, takes the owner from the chain (`--owner`
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.8.0",
4
+ "version": "0.8.2",
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_FILE (a file only you can read) or PRIORS_KEY, never the command line.",
7
7
  "type": "module",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@modelcontextprotocol/sdk": "^1.30.1",
48
- "@priors/x402": "0.6.2",
48
+ "@priors/x402": "0.6.4",
49
49
  "ethers": "^6.13.4",
50
50
  "undici": "6.29.0",
51
51
  "viem": "^2.56.9",
package/src/server.mjs CHANGED
@@ -14,8 +14,8 @@
14
14
  // runtime's config. A file anyone else can read is refused and not read (0.8.0)
15
15
  // PRIORS_KEY the agent wallet's private key (optional: without it only read-only tools work); not both
16
16
  // PRIORS_RPC JSON-RPC endpoint (default: the public https://rpc.mainnet.chain.robinhood.com)
17
- // PRIORS_AGENT_ID the Priors agent id this wallet acts for (else discovered from the identity registry;
18
- // required with a daily limit, which counts per agent)
17
+ // PRIORS_AGENT_ID the Priors agent id this wallet acts for (else discovered from the identity registry: one
18
+ // minted to it that never left it; required with a daily limit, which counts per agent)
19
19
  // PRIORS_FACILITATOR facilitator base URL for find_services (default https://facilitator.priors.trade)
20
20
  // PRIORS_MAX_PRICE_USD ceiling on pay_url's max_price_usd (default 1.00)
21
21
  // PRIORS_MAX_BORROW_USD ceiling on borrow's amount_usd and pay_url's max_borrow_usd (default 25)
@@ -677,6 +677,9 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
677
677
  borrow: (id, amount, term) => C.borrowLine(contracts, wallet, id, amount, term),
678
678
  repay: (loanId) => C.repayLoan(contracts, wallet, loanId),
679
679
  loanAgent: async (loanId) => (await contracts.pool.getLoan(loanId)).agentId,
680
+ // who held the agent when the loan was opened (the pool's Loan.owner), and who holds it now
681
+ loanOwner: async (loanId) => (await contracts.pool.getLoan(loanId)).owner,
682
+ agentOwner: (id) => contracts.registry.ownerOf(id),
680
683
  isController: (id, addr) => contracts.pool.isController(id, addr),
681
684
  agentsOf: (addr) => discoverAgents(addr),
682
685
  loanDue: async (loanId) => { const l = await contracts.pool.getLoan(loanId); return Number(l.status) === 1 ? l.principal + l.fee : null; },
@@ -751,8 +754,9 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
751
754
  } catch (e) { lines.push(savingsFailure(e)); }
752
755
  }
753
756
 
754
- // The registry is not enumerable: find identities minted to `addr` since the v2 deploy, keep what it owns. Only a mint
755
- // counts: anyone can transfer an identity with an open loan to this wallet, and `repay` would then pay it (own audit).
757
+ // The registry is not enumerable: find identities minted to `addr` since the v2 deploy that never left it, keep what it
758
+ // owns. Only a mint counts: anyone can transfer an identity with an open loan to this wallet, and `repay` would then pay
759
+ // it (own audit); one that left and came back carries what its interim holder borrowed (GHSA-mmp8).
756
760
  async function discoverAgents(addr) {
757
761
  const T = ethers.id("Transfer(address,address,uint256)");
758
762
  const latest = await provider.getBlockNumber();
@@ -762,6 +766,13 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
762
766
  const logs = await provider.getLogs({ address: addresses.registry, topics: [T, ethers.zeroPadValue(ethers.ZeroAddress, 32), ethers.zeroPadValue(addr, 32)], fromBlock: b, toBlock: Math.min(latest, b + 49_999) });
763
767
  for (const l of logs) ids.add(BigInt(l.topics[3]));
764
768
  }
769
+ if (ids.size) {
770
+ const asked = [...ids].map((id) => ethers.toBeHex(id, 32));
771
+ for (let b = from; b <= latest; b += 50_000) {
772
+ const logs = await provider.getLogs({ address: addresses.registry, topics: [T, ethers.zeroPadValue(addr, 32), null, asked], fromBlock: b, toBlock: Math.min(latest, b + 49_999) });
773
+ for (const l of logs) ids.delete(BigInt(l.topics[3]));
774
+ }
775
+ }
765
776
  const mine = [];
766
777
  for (const id of ids) if ((await contracts.registry.ownerOf(id).catch(() => ethers.ZeroAddress)).toLowerCase() === addr.toLowerCase()) mine.push(id);
767
778
  return mine;
@@ -779,7 +790,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
779
790
  const mine = await credit.agentsOf(wallet.address);
780
791
  if (mine.length === 1) return (agentCache = mine[0]);
781
792
  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.`);
782
- 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).");
793
+ throw new ToolError("This wallet owns no Priors agent identity minted to it since the v2 deploy and held ever since. Set PRIORS_AGENT_ID if it owns an older one, or one that left it and came back, or register first (`npx priors-v2 join`, from a clone of github.com/priors-agents/priors).");
783
794
  }
784
795
 
785
796
  function needWallet(action) {
@@ -1201,7 +1212,7 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
1201
1212
 
1202
1213
  tool("repay", {
1203
1214
  title: "Repay Priors loans",
1204
- description: "Repay the agent's own Priors loans in full (principal + fee) from the configured wallet's USDG; a loan of another agent is refused. Give either loan_id for one loan, or all: true to repay every open loan, earliest due first, as far as the balance covers. Moves real money: state the amounts (credit_status lists them) to the user and get their go-ahead first. The answer ends with share facts for each loan repaid (the amount, on time or late, the agent's record page), also as structured content with a suggested line; this server never posts anything.",
1215
+ description: "Repay the agent's own Priors loans in full (principal + fee) from the configured wallet's USDG; a loan of another agent, or one opened while someone else held the agent, is refused. Give either loan_id for one loan, or all: true to repay every open loan, earliest due first, as far as the balance covers. Moves real money: state the amounts (credit_status lists them) to the user and get their go-ahead first. The answer ends with share facts for each loan repaid (the amount, on time or late, the agent's record page), also as structured content with a suggested line; this server never posts anything.",
1205
1216
  inputSchema: {
1206
1217
  loan_id: z.number().int().nonnegative().optional().describe("The loan to repay."),
1207
1218
  all: z.boolean().optional().describe("true: repay every open loan of the agent, earliest due first."),
@@ -1216,9 +1227,15 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
1216
1227
  // not for others. PRIORS_AGENT_ID alone is not proof: a stale or mistyped id would point at someone else's agent.
1217
1228
  const id = await resolveAgent();
1218
1229
  await needController(id);
1230
+ // Only loans the agent's current owner took: one opened while someone else held the agent is theirs (the pool marks
1231
+ // them if it defaults), and an identity that changed hands can arrive carrying it (GHSA-mmp8).
1232
+ const holder = String(await credit.agentOwner(id)).toLowerCase();
1233
+ const openedBy = async (loanId) => { const o = String(await credit.loanOwner(loanId)); return o.toLowerCase() === holder ? null : o; };
1219
1234
  if (loan_id !== undefined) {
1220
1235
  const owner = BigInt(await credit.loanAgent(BigInt(loan_id)));
1221
1236
  if (owner !== id) throw new ToolError(`loan #${loan_id} belongs to agent #${owner}, not to agent #${id}. This tool only repays the configured agent's own loans.`);
1237
+ const other = await openedBy(BigInt(loan_id));
1238
+ if (other) throw new ToolError(`loan #${loan_id} was opened by ${other}, which held agent #${id} then; its owner now (${holder}) did not take it, so this tool does not repay it. Nothing was paid.`);
1222
1239
  // the due is read inside the savings step: a failed read there never stops the repayment
1223
1240
  if (use_savings) await fromSavings(() => credit.loanDue(BigInt(loan_id)), pre, deadline);
1224
1241
  let r;
@@ -1231,15 +1248,18 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
1231
1248
  }
1232
1249
  const s = await credit.status(id);
1233
1250
  if (s.openLoans.length === 0) return `Agent #${id} has no open loan. Nothing was repaid.`;
1234
- if (use_savings) await fromSavings(s.openLoans.reduce((a, l) => a + l.due, 0n), pre, deadline);
1251
+ const own = [], theirs = [];
1252
+ for (const l of s.openLoans) { const other = await openedBy(l.loanId); if (other) theirs.push({ ...l, other }); else own.push(l); }
1253
+ if (use_savings && own.length) await fromSavings(own.reduce((a, l) => a + l.due, 0n), pre, deadline);
1235
1254
  const done = [], left = [], repaid = [];
1236
1255
  let stop = null;
1237
- for (const l of s.openLoans) {
1256
+ for (const l of own) {
1238
1257
  if (stop) { left.push(l); continue; }
1239
1258
  try { const r = await credit.repay(l.loanId); done.push(`loan #${r.loanId}: ${usd(r.paid)}, tx ${r.hash}`); repaid.push({ loanId: r.loanId, agentId: r.agentId, paid: r.paid, dueAt: l.dueAt }); } catch (e) { stop = explain(e); left.push(l); }
1240
1259
  }
1241
1260
  const out = [...pre, done.length ? `Repaid for agent #${id}:\n- ${done.join("\n- ")}` : `Nothing was repaid for agent #${id}.`];
1242
1261
  if (left.length) out.push(`Still open: ${left.map((l) => `#${l.loanId} (${usd(l.due)} due ${when(l.dueAt)})`).join(", ")}.${stop ? ` Stopped because: ${stop}` : ""}`);
1262
+ if (theirs.length) out.push(`Not repaid, as the agent's owner now (${holder}) did not take them: ${theirs.map((l) => `#${l.loanId} (${usd(l.due)} due ${when(l.dueAt)}), opened by ${l.other} while it held the agent`).join("; ")}.`);
1243
1263
  if (repaid.length === 0) return out.join("\n");
1244
1264
  const share = await shareOf(repaid, id, deadline);
1245
1265
  out.push(shareText(share));