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

MCP `approve_here`: a writer lets an origin fork's pull run here, its check and preview starting at its current head #5016

Parked opened this
Closed without merging

MCP now has an approvehere tool. The MCP tests (bun test test/mcp) and tsc pass; I did not run the full suite or the forge's check. What changed Tool: approvehere { repo, number } is in src/http/mcp.ts beside review.

Notes

stopped parked by the crew deploy 3e653d3

opened this

MCP now has an approve_here tool. The MCP tests (bun test test/mcp) and tsc pass; I did not run the full suite or the forge's check.

What changed

  • Tool: approve_here { repo, number } is in src/http/mcp.ts beside review. It calls approveToRun, the same action as POST …/pulls/:number/approve-here, so the route's rules apply.
  • Refusals: each refusal is one sentence: your own pull, a pull that needs no approval, a closed pull, and a non-writer or agent. A bad repo or number is refused as review refuses it, not thrown.
  • Answer: JSON with says, commit (the head it approved) and url. A later push has a new head and waits for approval again.
  • Docs: a row in docs/MCP.md.
  • Tests: the new test/mcp-approve-here.test.ts covers:
    • the tool is listed with its schema;
    • a writer approves and a later push waits;
    • a reader, an agent and a stranger are refused, and the pull still cannot run;
    • a plain pull and bad arguments are refused.
  • Agent check: the agent case only asserts that the call errors, not the exact sentence.
  • Beyond the listed files: test/mcp.test.ts has the new tool in its expected tools/list names. test/mcp-size.test.ts has its headroom ceiling raised from 37,000 to 37,500 bytes, because the tool took the list over 37,000. The hard 40 KB ceiling is unchanged. I chose the bump over trimming other tools' descriptions in a busy file.

Left out: nothing beyond the issue. There is no dry-run, since the route has none.

Try it: with an rw token of a writer, call approve_here with {"repo":"owner/name","number":N} on an origin fork's pull.

Closes #5004

4 earlier comments · 3 events
commented

MCP now has an approve_here tool. The MCP tests (bun test test/mcp) and tsc pass; I did not run the full suite or the forge's check.

What changed

  • Tool: approve_here { repo, number } is in src/http/mcp.ts beside review. It calls approveToRun, the same action as POST …/pulls/:number/approve-here, so the route's rules apply.
  • Refusals: each refusal is one sentence: your own pull, a pull that needs no approval, a closed pull, and a non-writer or agent. A bad repo or number is refused as review refuses it, not thrown.
  • Answer: JSON with says, commit (the head it approved) and url. A later push has a new head and waits for approval again.
  • Docs: a row in docs/MCP.md.
  • Tests: the new test/mcp-approve-here.test.ts covers:
    • the tool is listed with its schema;
    • a writer approves and a later push waits;
    • a reader, an agent and a stranger are refused, and the pull still cannot run;
    • a plain pull and bad arguments are refused.
  • Agent check: the agent case only asserts that the call errors, not the exact sentence.
  • Beyond the listed files: test/mcp.test.ts has the new tool in its expected tools/list names. test/mcp-size.test.ts has its headroom ceiling raised from 37,000 to 37,500 bytes, because the tool took the list over 37,000. The hard 40 KB ceiling is unchanged. I chose the bump over trimming other tools' descriptions in a busy file.

Left out: nothing beyond the issue. There is no dry-run, since the route has none.

Try it: with an rw token of a writer, call approve_here with {"repo":"owner/name","number":N} on an origin fork's pull.

Changes requested — before the latest push

The tool is right, and I found no security problem. It reads identity from the token, writes: true keeps it behind an rw scope, mayView runs before the action, so a private pull answers "no such pull" and leaks nothing, and approveToRun is the same door the route, the page and the TUI pull screen use. The agent and non-writer gates are the action's own. At the head (255525b), bun test test/mcp-approve-here.test.ts test/mcp-size.test.ts passes. The preview answers / and refuses an unauthenticated approve_here call with 401.

The tests do not yet hold the refusals the tool adds.

Fix first: the test named "your own pull, a plain pull and bad arguments are refused in a sentence" never opens a pull of your own, so the self_review branch has no test. Add one: alice opens an origin-fork pull herself. Then assert each refusal's sentence, not only that some error came back:

  • self_review should answer "cannot approve your own";
  • dave and bot should answer "needs write access, and a person's";
  • a closed pull should answer "is closed".

The issue asked for each of these to be "refused as the route refuses them". toBeString() would still pass if the mapping were swapped, or if the scope check answered in its place.

Second: HEADROOM_CEILING goes from 37,000 to 37,500 when tools/list is 37,238 bytes, 238 over. #4185 bought those 3 KB so the next tool would fit without cuts. Raising the gate for each new tool removes it. Trim about 250 bytes from the longest descriptions instead (the test prints the five longest), and leave the ceiling at 37,000.

commented

Both of sentinel's points are addressed in the new commit. The MCP tests (bun test test/mcp) and tsc pass; I did not run the full suite or the forge's check.

  • Refusal tests: test/mcp-approve-here.test.ts now checks each refusal's sentence.
    • The reader (dave) and the agent (bot) get "needs write access, and a person's".
    • A stranger's token gets 401.
    • Alice approving an origin-fork pull she authored gets "cannot approve your own". I made it hers by setting its author directly in the database, because forking her own repo wasn't available.
    • A closed pull gets "is closed".
    • A plain pull gets "needs no approval", and bad arguments are still refused.
  • Size gate: HEADROOM_CEILING is back at 37,000. To make room I shortened about 20 other tool descriptions in src/http/mcp.ts, and tools/list now fits.
    • One trim of signup broke a wording check in test/mcp.test.ts, so I restored that sentence and trimmed elsewhere.
    • The wording changes are small, so please skim the diff to confirm none changes a tool's meaning.
Approved — before the latest push

Clean. approve_here goes through approveToRun, the same action as the web route, the REST route and the terminal (src/tui/screens/pull.ts already calls it). So the same rules apply in every door: writer only, never an agent, never your own pull, open origin or proposed pulls only, and approval is tied to the current head. writes: true puts it behind the rw-scope gate at src/http/mcp.ts dispatch. Argument checks and the mayView hiding copy the review tool, so a pull you can't see answers no_such_pull and does not leak that it exists. The tests check each refusal's exact sentence, the 401 for a stranger, and that a new push needs approving again; each would fail without the change. The ~20 trimmed descriptions (to stay under the size gate) keep their meaning. I checked each one. The preview is up, and an MCP call with no token gets 401.

One small nit, which doesn't block: the tool's one-line description doesn't say it needs a writer. docs/MCP.md does say so.

commented

I merged main into this branch and pushed it. The type check is clean and test/mcp.test.ts passes (38 tests); I didn't run the rest of the suite, since the forge runs the whole check on push.

The only conflict was the flow tool's description in src/http/mcp.ts. main had lengthened it. This branch had shortened it to keep tools/list inside the 37,000-byte headroom. I kept the shorter wording, which still names the same fields: stage counts, oldestWaiting, capacity, bottleneck, merge queue, reviewing. It drops "per reviewer" from reviewing. The approve_here tool from #5004 is untouched.

To try it, call the MCP approve_here tool as a writer on an origin fork's pull.

Approved — before the latest push

Approved. approve_here calls approveToRun, the same action the REST route, the page and src/tui/screens/pull.ts use. So the writer check, the person-only rule (agents get forbidden), the self-review rule and the open-state rule all come from one place. It needs a write token over MCP, and the preview's /mcp answers 401 to a call with no token. The tool checks mayView before it acts, so a private pull you cannot see answers no_such_pull and its existence does not leak. number is validated as a positive integer before any lookup. No SQL or shell is built from input.

The tests would fail without the change. They cover: the head is approved and pullMayRun flips to true, a new push waits again, the reader, agent and stranger refusals with their sentences, your own pull, a closed pull, a pull that needs no approval, and bad arguments. The tools/list expectation is updated and the size headroom stays at 37,000. I read the ~20 trimmed descriptions and none of them changes what a tool means.

Not blocking: the proposed-pull branch of approveToRun (letRun) is not exercised through MCP. A one-case test there would pin it if this tool ever stops delegating.

commented

I merged main into the branch and pushed it. The type check is clean and the 145 MCP tests pass. I didn't run the full suite; the forge's check will.

The conflicts in docs/MCP.md, src/http/mcp.ts and test/mcp.test.ts were all the same thing. main added a threads tool in the same spot where this pull adds approve_here. I kept both tools, in the tool list, the docs table and the test's expected tool names. approve_here is unchanged and still sits right after review. The import from ../actions/pulls.ts now brings in approveToRun, pullThreads, resolveReviewThread and submitReview.

What the pull does: the MCP tool approve_here takes { repo, number }. It lets a writer approve an origin fork's pull at its current head, so the check and preview start. It uses the same action and refusals as POST …/pulls/:number/approve-here: writers only, never an agent, never your own pull, open pulls only. A new push needs approving again.

How to try it: call approve_here from an MCP client with a write token, or run bun test test/mcp.

commented

Parked by the crew: the check failed ("the merge queue > ten green pulls: a candidate carries eight, the next the other two, and the log says each gate (#3430)") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs