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
Check · Review · Land · Live done — Landed and live in production.
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
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.tswith no arguments answers{ position, marginPct, policy, words, changes }, the API's shape. A read-only token may do this. - Set: with
positionand/ormarginPct, the call is planned first (dryRunis true unlessfalse) 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_foundfor 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
kindon an existing one, as the issue asked.test/mcp-size.test.tspasses 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.
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
positionand/ormarginPctit plans first (dryRunis true unlessfalse). WithdryRun: falseand an admin token it writes throughsrc/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.tsand named indocs/features/economics.md.llms.txtlists it automatically from the tool'sdocline. test/mcp-economics.test.tscovers 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.
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
economicsexport in the wrong place insrc/http/mcp/tools/index.ts. I regenerated the file withbun 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.
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.
- Add a test that an admin agent token is told
not_foundwhen 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). - Add a test for an
rw-scope token held by a real admin, calling withdryRun: false. Dispatch letsrwthrough, so thescopeAllows(..., "admin")line in the tool is the only guard, and the only token tested isro, which dispatch refuses before the tool runs. That line could be deleted and every test would stay green. Assertforbiddenand that the position is unchanged. - Tidy:
bad1is an unclear name, andwireduplicates src/http/api/economics.ts. Export the API'swire(or move it next toEconomicsView) and use it in both so the MCP and API shapes cannot drift. In the dry-run branch, check the numbers before buildingto.
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_agentuser withis_admin = 1) getsnot_foundwhen it reads and when it sets withdryRun: false. The slider position stays at 70. rwscope test: anrwtoken held by a real admin, calling withdryRun: false, getsforbidden, and the position stays at 70. This test exercises thescopeAllows(..., "admin")guard insrc/http/mcp/tools/economics.ts.- Shared
wire:src/http/api/economics.tsnow exportswire, 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:
bad1is renamedinvalid, and the check now runs beforetois built.
The new tests are in test/mcp-economics.test.ts.
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.
The MCP now has an
economicstool that reads and sets the profit slider the wayGET/PUT /api/v1/forge/economicsdo. The tests I ran are green: the newtest/mcp-economics.test.ts, plustest/mcp-size.test.ts,test/mcp.test.tsandtest/conversation-confirm.test.ts.bun x tsc --noEmitandbun scripts/gate.tsshowed no errors. I did not run the full suite.scripts/fast.tssaid the diff reaches too many tests to name, so I picked these four, and the forge's check runs everything.What changed
src/http/mcp/tools/economics.tswith no arguments answers{ position, marginPct, policy, words, changes }, the API's shape. A read-only token may do this.positionand/ormarginPct, the call is planned first (dryRunis true unlessfalse) and answers{ from, to, says }.- With
dryRun: falseand an admin token it writes throughchangeEconomics, 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.not_foundfor reading and setting, as the API gives. A non-admin-scope token is refused when setting.- The tool is exported from
tools/index.ts. - It is added to the expected-tools list intest/mcp.test.ts. - It is added to the writes-that-don't-ask list intest/conversation-confirm.test.ts. I put it there because it plans by default and its writes need an admin token. -docs/features/economics.mdnames it. -llms.txtis generated from the tool'sdocline, so it lists it with no separate edit.What I chose not to do
docs/mcp/tools/directory in this repo, so I added no per-tool doc file.kindon an existing one, as the issue asked.test/mcp-size.test.tspasses with the ceilings unchanged.How to try it: call the
economicstool 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