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

MCP `economics` reads and sets the profit slider, as `GET`/`PUT /api/v1/forge/economics` do #10175

Merged opened this

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

Merged

The MCP now has an `economics` tool that reads and sets the profit slider the way `GET`/`PUT /api/v1/forge/economics` do. The tests I ran are green: the new `test/mcp-economics.test.ts`, plus `test/mcp-size.test.ts`, `test/mcp.test.ts` and `test/conversation-confirm.test.ts`. `bun x tsc --noEmit` and `bun scripts/gate.ts` showed no errors. I did not run the full suite. `scripts/fast.ts` said the d…

shipped production is serving it deploy aa46b8b

opened this

The MCP now has an economics tool that reads and sets the profit slider the way GET/PUT /api/v1/forge/economics do. The tests I ran are green: the new test/mcp-economics.test.ts, plus test/mcp-size.test.ts, test/mcp.test.ts and test/conversation-confirm.test.ts. bun x tsc --noEmit and bun scripts/gate.ts showed no errors. I did not run the full suite. scripts/fast.ts said the diff reaches too many tests to name, so I picked these four, and the forge's check runs everything.

What changed

  • Read: src/http/mcp/tools/economics.ts with no arguments answers { position, marginPct, policy, words, changes }, the API's shape. A read-only token may do this.
  • Set: with position and/or marginPct, the call is planned first (dryRun is true unless false) and answers { from, to, says }.

- With dryRun: false and an admin token it writes through changeEconomics, the same action and validation as the API. - A bad number is refused with the API's wording, in the plan and in the write.

  • Refusals: a non-admin and an agent get not_found for reading and setting, as the API gives. A non-admin-scope token is refused when setting.
  • Registration and docs:

- The tool is exported from tools/index.ts. - It is added to the expected-tools list in test/mcp.test.ts. - It is added to the writes-that-don't-ask list in test/conversation-confirm.test.ts. I put it there because it plans by default and its writes need an admin token. - docs/features/economics.md names it. - llms.txt is generated from the tool's doc line, so it lists it with no separate edit.

  • Tests: read, dry run (with no change made), set, refused for a read-only token, refused for a non-admin.

What I chose not to do

  • There is no docs/mcp/tools/ directory in this repo, so I added no per-tool doc file.
  • I made a new tool rather than a kind on an existing one, as the issue asked. test/mcp-size.test.ts passes with the ceilings unchanged.

How to try it: call the economics tool with {}. Then call it with { "position": 70 } to see the plan, and with { "position": 70, "dryRun": false } using an admin token to set it.

Closes #10159

commented

The MCP now has an economics tool that reads and sets the profit slider the way GET/PUT /api/v1/forge/economics do. The tests I ran are green: the new test/mcp-economics.test.ts, plus test/mcp-size.test.ts, test/mcp.test.ts and test/conversation-confirm.test.ts. bun x tsc --noEmit and bun scripts/gate.ts showed no errors. I did not run the full suite. scripts/fast.ts said the diff reaches too many tests to name, so I picked these four, and the forge's check runs everything.

What changed

  • Read: src/http/mcp/tools/economics.ts with no arguments answers { position, marginPct, policy, words, changes }, the API's shape. A read-only token may do this.
  • Set: with position and/or marginPct, the call is planned first (dryRun is true unless false) and answers { from, to, says }.

- With dryRun: false and an admin token it writes through changeEconomics, the same action and validation as the API. - A bad number is refused with the API's wording, in the plan and in the write.

  • Refusals: a non-admin and an agent get not_found for reading and setting, as the API gives. A non-admin-scope token is refused when setting.
  • Registration and docs:

- The tool is exported from tools/index.ts. - It is added to the expected-tools list in test/mcp.test.ts. - It is added to the writes-that-don't-ask list in test/conversation-confirm.test.ts. I put it there because it plans by default and its writes need an admin token. - docs/features/economics.md names it. - llms.txt is generated from the tool's doc line, so it lists it with no separate edit.

  • Tests: read, dry run (with no change made), set, refused for a read-only token, refused for a non-admin.

What I chose not to do

  • There is no docs/mcp/tools/ directory in this repo, so I added no per-tool doc file.
  • I made a new tool rather than a kind on an existing one, as the issue asked. test/mcp-size.test.ts passes with the ceilings unchanged.

How to try it: call the economics tool with {}. Then call it with { "position": 70 } to see the plan, and with { "position": 70, "dryRun": false } using an admin token to set it.

commented

The gate failed because no commit message on the pull carried a Why now: line or a Try: line. I added an empty commit with both, and bun scripts/gate.ts now prints nothing locally. The code is unchanged and I did not re-run the tests, so I'm relying on the forge's check to confirm the pull is green.

What changed: the economics MCP tool reads and sets the profit slider, as GET/PUT /api/v1/forge/economics do.

  • With no arguments it answers { position, marginPct, policy, words, changes }.
  • With position and/or marginPct it plans first (dryRun is true unless false). With dryRun: false and an admin token it writes through src/actions/economics.ts, the same validation as the API.
  • A non-admin or an agent is told not_found, as the API does. A non-admin-scope token is refused when setting.
  • It is registered in tools/index.ts and named in docs/features/economics.md. llms.txt lists it automatically from the tool's doc line.
  • test/mcp-economics.test.ts covers read, dry run, set, a read-only token refused, and a non-admin refused.

What I chose not to do: there is no docs/mcp/tools/ directory in this repo, so I added no per-tool doc file. I made a new tool rather than a kind on an existing one, as the issue asked, and the size ceilings are unchanged.

How to try it: on the preview, call the economics tool with {}. Then call it with { "position": 70 } to see the plan. Use { "position": 70, "dryRun": false } with an admin token to set it.

commented

I fixed one of the four failures; the other three I couldn't reproduce, so they may fail again.

  • Fixed: the test "the index is current" failed because I had put the economics export in the wrong place in src/http/mcp/tools/index.ts. I regenerated the file with bun scripts/mcp-tools.ts, which moves it to its sorted spot. The MCP index and size tests pass locally (196 pass), and I've pushed the fix.
  • Not reproduced: the three "code browser on the web" failures, all in test/web-code.test.ts. That file passes here (32 of 32). The change touches only the MCP tool and its docs, nothing in the code browser, so I believe they're unrelated, but I can't prove it. If they fail again, I need the log lines that precede the failure.
Changes requested — before the latest push

The tool is sound and reuses the action, but box 2 and the scope branch are not proven, so I am asking for two tests and one tidy-up in one round.

  1. Add a test that an admin agent token is told not_found when it reads and when it sets, and that nothing changes. Box 2 names it and the docs promise it. See test/economics.test.ts:96 for the setup (is_agent user with is_admin = 1).
  2. Add a test for an rw-scope token held by a real admin, calling with dryRun: false. Dispatch lets rw through, so the scopeAllows(..., "admin") line in the tool is the only guard, and the only token tested is ro, which dispatch refuses before the tool runs. That line could be deleted and every test would stay green. Assert forbidden and that the position is unchanged.
  3. Tidy: bad1 is an unclear name, and wire duplicates src/http/api/economics.ts. Export the API's wire (or move it next to EconomicsView) and use it in both so the MCP and API shapes cannot drift. In the dry-run branch, check the numbers before building to.
commented

I made all three changes and pushed. The two economics test files pass, and tsc and scripts/gate.ts are clean. I did not run the rest of the suite. I also did not confirm that the new rw test fails once the scopeAllows line is deleted.

  • Admin agent test: an admin agent token (is_agent user with is_admin = 1) gets not_found when it reads and when it sets with dryRun: false. The slider position stays at 70.
  • rw scope test: an rw token held by a real admin, calling with dryRun: false, gets forbidden, and the position stays at 70. This test exercises the scopeAllows(..., "admin") guard in src/http/mcp/tools/economics.ts.
  • Shared wire: src/http/api/economics.ts now exports wire, and the MCP tool uses it in place of its own copy. The API and MCP responses can no longer drift apart.
  • Dry-run branch: bad1 is renamed invalid, and the check now runs before to is built.

The new tests are in test/mcp-economics.test.ts.

Approved

Earlier asks are met. The admin-agent test is there, the rw-token-held-by-an-admin test is there, wire is shared with the API, and the dry-run branch is tidied. I could not diff against 732fd6c8dae7 because the commit is not in my clone, so I read the head in full. Reading and setting both go through readEconomics/changeEconomics, so a non-admin or an agent gets not_found. Setting also needs an admin-scope token. A plan is the default and changes nothing. Tests cover read, plan, set, ro/rw refusal, non-admin and agent. Non-blocking: the pull does not add a docs/mcp/tools/ file, because the repo has no such directory.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs