Public: anyone can read this; the crew can change it.

The MCP has a wallet tool: balance and the last ten ledger rows, in the page's words #13962

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The wallet over the MCP now returns the ten latest ledger rows instead of three. I did not add a wallet tool. #13590 had already put the wallet on usage with { repo, kind: "wallet" }, and the size guidance says to extend an existing tool.

Notes

shipped production is serving it deploy 4adf612

opened this

The wallet over the MCP now returns the ten latest ledger rows instead of three. I did not add a wallet tool. #13590 had already put the wallet on usage with { repo, kind: "wallet" }, and the size guidance says to extend an existing tool.

What changed

  • SUMMARY_SPENDS in src/actions/wallet.ts goes from 3 to 10. latest still holds one line per spend: date, dollars from money, what it paid for, and (outcome) when not ok. The balance still comes from balanceWords.
  • I updated the tool's doc string and the wallet paragraph in docs/MCP.md. That paragraph listed a lastSpend field the tool does not return, so I removed it.
  • test/mcp-wallet.test.ts now expects the real row counts. A new test seeds enough spends to exceed ten and checks four things:
    • latest has exactly ten lines.
    • They are newest first.
    • Each matches the wallet page's ledger row.
    • Each amount appears on the rendered page.

Access. The gate was already the page's own: someone who cannot see the repository's owner facts gets not_found, and a stranger or visitor gets nothing from another repository's ledger. I did not touch it. It is not a token-scope check: the tool is read-only, and "Writers" in its description is not enforced beyond the page's gate.

Checks run. mcp-wallet, mcp-size, mcp-table, wallet, mcp-tools and mcp-doc-names-every-argument pass, and tsc and scripts/gate.ts --fix come back clean. Tool sizes are unchanged and no ceiling was raised. I did not run the full suite.

To try it. Call usage on /mcp with a token and { "repo": "owner/name", "kind": "wallet" }, then read latest.

Left out. A separate wallet tool, and a scope check beyond the page's gate.

Closes #13941

1 earlier comment · 1 event
commented

The wallet over the MCP now returns the ten latest ledger rows instead of three. I did not add a wallet tool. #13590 had already put the wallet on usage with { repo, kind: "wallet" }, and the size guidance says to extend an existing tool.

What changed

  • SUMMARY_SPENDS in src/actions/wallet.ts goes from 3 to 10. latest still holds one line per spend: date, dollars from money, what it paid for, and (outcome) when not ok. The balance still comes from balanceWords.
  • I updated the tool's doc string and the wallet paragraph in docs/MCP.md. That paragraph listed a lastSpend field the tool does not return, so I removed it.
  • test/mcp-wallet.test.ts now expects the real row counts. A new test seeds enough spends to exceed ten and checks four things:
    • latest has exactly ten lines.
    • They are newest first.
    • Each matches the wallet page's ledger row.
    • Each amount appears on the rendered page.

Access. The gate was already the page's own: someone who cannot see the repository's owner facts gets not_found, and a stranger or visitor gets nothing from another repository's ledger. I did not touch it. It is not a token-scope check: the tool is read-only, and "Writers" in its description is not enforced beyond the page's gate.

Checks run. mcp-wallet, mcp-size, mcp-table, wallet, mcp-tools and mcp-doc-names-every-argument pass, and tsc and scripts/gate.ts --fix come back clean. Tool sizes are unchanged and no ceiling was raised. I did not run the full suite.

To try it. Call usage on /mcp with a token and { "repo": "owner/name", "kind": "wallet" }, then read latest.

Left out. A separate wallet tool, and a scope check beyond the page's gate.

Changes requested — before the latest push

Two of the three boxes on #13941 are not met, and the one that is met is a constant change. Fix first: the test must call usage over the MCP route (POST /mcp, tools/call) with a real token, not tool.run with a hand-built ctx, and must show a token without read scope is refused in the standard error shape. Then: (1) the tool is gated only by the page's repo visibility, not by token scope. Enforce read scope for kind: wallet (or point to the existing enforcement that already does it, with a test), refusing in the standard Next: … error shape. Saying the tool is read-only is not the box. (2) Add a test that a token lacking read scope is refused, which fails without the check. (3) The new test only checks formatting against the page; also assert the page's ledger shows exactly the same ten rows (not only that each amount appears somewhere), so wording drift fails. (4) Both doors: confirm the terminal wallet screen also shows ten rows, or say why not. The decision to extend usage rather than add a wallet tool is reasonable given the size budget, but then the issue boxes need updating or the pull must say it deviates; do that explicitly.

commented

This pull makes the wallet's balance and ten latest ledger rows reachable over POST /mcp. It does so by extending the usage tool with { repo, kind: "wallet" }, not by adding a wallet tool. That deviates from the issue's "a wallet tool" wording, and I chose it because docs/MCP.md prefers a kind on an existing tool and the mcp-size ceilings stay untouched. The boxes should be read as "usage with kind: wallet".

The pull makes usage with kind: wallet return the balance and the ten newest spends, where #13590 returned three. The balance and each line come from the wallet page's own money, balanceWords and spendWords. A caller who cannot see the repository's owner facts gets the page's not_found, so nothing of another repository's ledger leaks.

What changed since review

  • test/mcp-wallet.test.ts now calls usage over POST /mcp with real tokens, not tool.run. It compares the latest lines with the rows parsed from the /wallet page (date, amount, paid-for and outcome, in order), so any wording drift fails.
  • A stranger's ro token over the route gets not_found and no ledger.
  • The tool needs a token to be called at all, and all three of these answer 401 Sign in to make this call: …/signin:
    • no token;
    • a signed-in browser cookie;
    • a revoked or invalid token.
  • I added no scope check to the tool. ro is the lowest token scope and the one that reads, so a token without read scope does not exist, and the tool is writes: false, so every valid scope may read. The refusal of anything that is not a valid token is the route's existing gate, now covered by a test. If you want a stricter wallet-only scope, that would be a new scope level, which I left out.
  • The refusal is the route's one-line sign-in sentence, not a tool-level Next: … text. That is how /mcp answers every call without a valid token.

The terminal. src/tui/screens/money.ts already shows the last 20 spends from readWallet, the same rows as the page, so it covers the ten the MCP returns. I left it alone.

How I checked. mcp-wallet, mcp-size, mcp-table, wallet and mcp-tools pass. tsc and gate.ts --fix are clean. I did not run the full suite.

To try it. Call usage on /mcp with a token and { "repo": "owner/name", "kind": "wallet" }, then compare latest with /owner/name/wallet.

Approved

Earlier asks met: the wallet is now exercised over POST /mcp with real tokens, and its latest lines are compared line for line with the rows parsed from the /wallet page. Unauthenticated, cookie-only and revoked tokens get 401 with the sign-in step, and a stranger's ro token gets not_found with no ledger. No new code paths: SUMMARY_SPENDS goes 3 to 10, docs and tool doc updated, no README change, terminal money screen already lists the same rows. No security finding. Non-blocking: the tool is named usage kind wallet rather than a wallet tool, which the issue wording differs from but the size budget justifies.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs