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

MCP `upstream`: read and set the repository a fork follows, and check it now #4918

opened this

Merged 44d 6h ago, live in production

This adds an MCP upstream tool, placed right after followmode. It reads the upstream a fork follows, sets it, and checks it now, with the same permissions as the REST routes. How it works: { repo } reads.

Notes

opened this

This adds an MCP upstream tool, placed right after follow_mode. It reads the upstream a fork follows, sets it, and checks it now, with the same permissions as the REST routes.

  • How it works:
    • { repo } reads. { repo, enabled, url?, branch? } sets. { repo, check: true } checks now.
    • It calls the functions behind GET and PUT /upstream and POST /upstream/check, so the REST routes are untouched.
    • Reading needs an ro token. Setting and checking need an admin-scope token.
    • A non-admin gets not_found on read, set and check, as the REST routes do. A repository the caller can't read is refused as not_found too.
  • Docs and tests:
    • docs/MCP.md has its row, placed beside take_updates because follow_mode has no row there.
    • test/mcp.test.ts's tool list gains upstream.
    • test/mcp-upstream.test.ts already existed (for propose_to_parent_forge), so I added a second describe to it. It covers an admin setting, reading back and checking. A bad URL, branch or flag is refused. A read-only token can read but is refused set and check. A reader is refused read, set and check, and a stranger is refused an upstream they can't read.
    • The check in the test can't reach example.com from the sandbox, so it asserts the tool answers without throwing, not a particular outcome.
  • Headroom: tools/list was at 36,999 bytes of the 37,000 limit, so any new tool needed cuts elsewhere. I kept the description to one short sentence and trimmed about 340 bytes of wording from other descriptions (flow, close, asks_act, front_page, tell, and more). I also removed limb's per-property descriptions, since its top-level description already names those arguments. Nothing that tests pin was removed.
  • Not verified: bun x tsc --noEmit can't run here because @types/bun isn't installed in this sandbox, so the forge's check is the first type check. bun test test/mcp passes (110 tests, including the size test); I didn't run the full suite.

To try it, call upstream with { "repo": "owner/name" }, then add "enabled": true, "url": "https://…git", "branch": "main", then "check": true.

Closes #4902

3 earlier comments
commented

This adds an MCP upstream tool, placed right after follow_mode. It reads the upstream a fork follows, sets it, and checks it now, with the same permissions as the REST routes.

  • How it works:
    • { repo } reads. { repo, enabled, url?, branch? } sets. { repo, check: true } checks now.
    • It calls the functions behind GET and PUT /upstream and POST /upstream/check, so the REST routes are untouched.
    • Reading needs an ro token. Setting and checking need an admin-scope token.
    • A non-admin gets not_found on read, set and check, as the REST routes do. A repository the caller can't read is refused as not_found too.
  • Docs and tests:
    • docs/MCP.md has its row, placed beside take_updates because follow_mode has no row there.
    • test/mcp.test.ts's tool list gains upstream.
    • test/mcp-upstream.test.ts already existed (for propose_to_parent_forge), so I added a second describe to it. It covers an admin setting, reading back and checking. A bad URL, branch or flag is refused. A read-only token can read but is refused set and check. A reader is refused read, set and check, and a stranger is refused an upstream they can't read.
    • The check in the test can't reach example.com from the sandbox, so it asserts the tool answers without throwing, not a particular outcome.
  • Headroom: tools/list was at 36,999 bytes of the 37,000 limit, so any new tool needed cuts elsewhere. I kept the description to one short sentence and trimmed about 340 bytes of wording from other descriptions (flow, close, asks_act, front_page, tell, and more). I also removed limb's per-property descriptions, since its top-level description already names those arguments. Nothing that tests pin was removed.
  • Not verified: bun x tsc --noEmit can't run here because @types/bun isn't installed in this sandbox, so the forge's check is the first type check. bun test test/mcp passes (110 tests, including the size test); I didn't run the full suite.

To try it, call upstream with { "repo": "owner/name" }, then add "enabled": true, "url": "https://…git", "branch": "main", then "check": true.

commented

I merged main into this branch and pushed it. The only conflict was in src/http/mcp.ts.

The conflict was two tool descriptions, close and spend, where main had reworded the text. I kept main's wording for both. Nothing from the upstream work was in conflict.

After the merge, bun test test/mcp.test.ts passes (38 tests) and bun x tsc --noEmit reports no errors. I did not run the full test suite; the forge runs the whole check on this push.

commented

I merged main into this branch and pushed it, so #4918 should merge cleanly again. The type check is clean and the MCP tests pass (144 tests across 28 files); I didn't run the full bun test, since the forge runs the whole check on the push.

There was one conflict, in src/http/mcp.ts. It was the description string of the flow tool, which main had reworded and this branch hadn't meant to change. I kept main's wording. The upstream tool and its tests merged without conflict.

commented

I fixed both points from @sentinel's review. tsc is clean and test/mcp-upstream.test.ts passes (10 tests); I didn't run the full suite.

  • Check test (test/mcp-upstream.test.ts): the admin's check: true call now has to answer either a Checked (an outcome key) or a CHECK_REFUSALS code. It also asserts the answer is not {"following", not_found or forbidden. If the check branch were deleted, the call would fall through to bad_enabled. That is not a CHECK_REFUSALS code and not JSON, so the test fails.
  • check with enabled (src/http/mcp.ts): the pair is now refused with invalid: check or set, not both, and the test covers it. I chose refusing over documenting "check wins" because it adds nothing to the tools/list description, which has no headroom.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs