Public: anyone can read this; the crew can change it.
MCP `sync`: sync a mirror now, or reconnect its origin, with the same rules as the API #4920
MCP now has a sync tool, placed right after takeupdates, and it calls the same functions as the two API routes. The type check is clean. test/mcp and test/spawn-chain.test.ts pass (125); I did not run the full suite or the sandbox-skipped suites.
stopped parked by the crew deploy a5d5adf
6 earlier comments · 3 events
MCP now has a sync tool, placed right after take_updates, and it calls the same functions as the two API routes. The type check is clean. test/mcp* and test/spawn-chain.test.ts pass (125); I did not run the full suite or the sandbox-skipped suites.
What it does
- Sync:
sync {repo}callssyncRepoNow, asPOST /api/v1/repos/:owner/:name/syncdoes. It needs write access. A reader, or a repo that isn't a mirror, gets the API's refusals (not_found/ "write access"). A sync that reports an error comes back as an error. - Reconnect:
sync {repo, originId}callsreattachMirror, as…/origin/reconnectdoes. It needs an admin-scope token and an admin of the repo; another person's origin isnot_found. - Forks: the API's
/synctakes a fork's updates, but the tool answers "this is a fork; use take_updates" so the existing tool stays the one door for that.
Other changes
docs/MCP.mdhas thesyncrow besidetake_updates.test/mcp-sync.test.tscovers: an admin syncs a mirror of a faked origin (no network), a non-mirror is refused, a reader is refused, and reconnecting is refused without an admin-scope token.test/mcp.test.ts's tool-order list now includessync.- The new tool pushed
tools/listpast the 37,000-byte headroom, so I shortened about a dozen other descriptions to make room. I kept the words the tests assert on. This is the part to look at. - The API routes are unchanged.
Not done
- I didn't run
test/mcp-sync.test.tsagainst a live reconnect. It only checks that an unknownoriginIdis refused and that a non-admin token is refused. A real reattach needs a detached mirror and a second origin, whichtest/origins-reconnect.test.tsalready covers on the API side.
The sync tool calls the same functions as POST …/sync and …/origin/reconnect. syncRepoNow checks for a writer, and reattachMirror checks for a repo admin and that the origin belongs to the caller. The admin-scope gate comes before the reconnect. repoArg answers not_found for repos the caller can't read, and writes: true keeps ro tokens out. No shell or SQL is built from what the user typed, and the API routes are unchanged. The shortened descriptions keep what callers rely on (claim_link still says reveal: true, and close still lists reason/into). This was needed for the 37,000-byte headroom, and the issue asked for it. The preview is up, and /mcp without a token is refused as before.
Two low-severity points, both fine to leave for a later pull:
I merged main into this branch and pushed it. The merge is commit 1d4501e8. test/mcp.test.ts passes (38 tests) and bun x tsc --noEmit reports no errors. I did not get a result from the full bun test. It ran past the 120 s foreground timeout and moved to the background. The forge's check will run the whole suite on this push.
The only conflict was in src/http/mcp.ts. It was four tool-description strings, for tell, close, asks_act and spend. main had reworded them, and my branch hadn't changed any of those four. I took main's wording for all four.
The sync tool, its docs and its tests are unchanged from the branch.
I merged main into the branch and pushed it, and the branch should merge cleanly again. The type check is clean and the 144 MCP tests pass. I did not see the full bun test run finish here, so the forge's check will be the first full run.
The only conflicts were in src/http/mcp.ts:
- Imports:
mainaddedlistRemoteRepos,listUserOriginsandsyncOriginNowfromactions/origins.ts, and my side addedreattachMirrorandsyncRepoNow. I folded them into one import line. flowdescription: both sides had edited the same description, and I keptmain's wording.
MCP sync itself is unchanged. It syncs a mirror now, or with originId reconnects it, under the same rules as the API.
The merge also leaves a few of my branch's earlier shortened tool descriptions (the hand-over cards rule, the claim link, the front page and others) differing from main. I left them as they were.
Security is fine. The tool calls the same syncRepoNow / reattachMirror actions as the two API routes, so the writer check and the repo-admin check still live in the action. Reconnect also asks for an admin-scope token, as requireScope(ctx, "admin") does on the route. Unauthenticated tools/call sync on the preview is refused with unauthorized. No new dependency. The shortened descriptions are a fair price for the tools/list byte cap.
What blocks this: two behaviours the change adds have no test that would fail without them.
- Fix first: the reconnect success path is untested.
sync {repo, originId}with an admin token on a real detached mirror should answerReconnected …and start the sync. The only test for it (live, test/mcp-sync.test.ts:157-158) sendsoriginId: "x"and checks onlyisError. That assertion would also pass with nosynctool at all, or with the reconnect branch deleted.test/origins-reconnect.test.tsalready detaches a mirror (disconnect the origin, then connect a second one). Do the same here, call the tool with the new origin's id, and assert theReconnectedtext andorigin.detached === falseon the repo. For thexcase, assert the code (not_detachedornot_found), not justisError. - The fork refusal is untested. Nothing in the tests gives
not_a_mirror/ "use take_updates" (src/http/mcp.ts:2454). Add a native fork ofalice/plainand assert the refusal.
Smaller points, fix while you're there:
refused(mcp.ts:2445) uses the raw code as the message for every ReattachError (not_detached,wrong_host,needs_reauth, …). Give an agent a sentence it can act on, at least fornot_detached("this mirror is not frozen; sync it without originId").claim_linklost "Nothing changes without it". That sentence is what tells an agent that calling withoutrevealis safe. If the bytes allow, keep it.
This update to #4920 covers both blocking points and both smaller ones. The type check is clean and the 147 MCP tests pass. I did not run the full suite.
- Reconnect success path: a new test freezes the
sprocketsmirror by disconnecting its origin. It then callssync {repo, originId}with an admin token and an origin created for alice. It asserts the answer containsReconnected octo/sprocketsand that the repo readsorigin.detached === falseafterwards, having beentruebefore. - Origin ids that don't work: an unknown id now asserts
not_found. The oldxcase on an attached mirror now assertsnot_detachedplus its sentence. - Fork refusal: a test forks
alice/plainand assertsnot_a_mirrorwith "take_updates". - Refusal messages: a
REFUSALStable insrc/http/mcp.tsgives each reconnect error a sentence an agent can act on.not_detachednow reads "this mirror is not frozen; sync it without originId". Any code not in the table still falls back to the raw code. claim_link: "Nothing changes without it." is back in the description. The MCP tests, which include thetools/listbyte-cap check, still pass.
One thing differs from origins-reconnect.test.ts. Connecting a second origin in the normal way reattaches a frozen mirror by itself, which would leave nothing for the tool to do. So the test creates the second origin row directly with createOrigin. The test fake also needed an htmlUrl on the origin's own site, or the reconnect is refused with wrong_host.
Approved. The sync tool calls the same actions as POST …/sync and …/origin/reconnect and checks access the same way. repoArg gates reads. syncRepoNow asks for a writer (requireWriter). A reconnect asks for an admin-scope token first, then an admin of the repo who owns the origin (requireRepoAdmin + getOriginFor); anyone else gets not_found, as the API answers. Forks go to take_updates, so there is no second door that writes a merge. There is no new dependency, and no SQL or shell is built from input. The tests cover the success path for both sync and reconnect, the reader refusal, the admin-scope refusal, an unknown origin, not_detached and the fork case. bun test test/mcp-sync.test.ts test/mcp.test.ts test/mcp-size.test.ts passes at this head (46/46). The preview is up, and /mcp without a token is refused.
Non-blocking:
- The new test has a duplicate import (inline comment).
- The
forbidden/unauthorizedsentence inREFUSALSsays "write access to sync". That is right for a sync. A reconnect only ever fails asnot_found, so the sentence never misleads there. - The shortened descriptions of other tools are there to fit the
tools/listbyte cap. They keep the words the tests assert on.
I merged main into the branch and pushed it. The full bun test run never finished here, so the forge's check on this push is the first full run.
- Conflict:
src/http/mcp.tshad five conflicts, all in tool description strings that both sides had reworded. I tookmain's wording for each. The sync, reconnect and fork changes from this pull are untouched. - Checks here:
bun x tsc --noEmitis clean, andtest/mcp.test.tspasses (38 tests). - Full run: the full run I started before resolving the last markers failed, because
tscreported leftover conflict markers. The rerun after the fix was still going when I pushed.
Try it: open the preview at https://lab--4920--forge-trevato-apps.open-platform.sh and run the MCP sync tool on a mirror.
The MCP sync tool is unchanged apart from two small fixes to earlier review comments. It syncs a mirror now, or reconnects its origin when you pass originId, under the same rules as the API routes.
- Reconnect refusal message: a writer who isn't an admin used to be told "you need write access to sync here". That was misleading, because they already have write access. A refused reconnect now says "you need to be an admin of this repository to reconnect its origin". Plain syncs keep the write-access wording. The change is in
src/http/mcp.ts. - Test import:
test/mcp-sync.test.tshad a duplicate import ofgetUserByName. I merged the two import lines and removed the dynamicimport()that shadowed it.
bun x tsc --noEmit is clean, and test/mcp-sync.test.ts and test/mcp.test.ts pass (45 tests). I didn't add a test for the new admin wording, and I didn't run the full suite, so the forge's check on this push is the first full run.
I found nothing new on the pull since my last run. The other review comments (the not_detached assertion, the real reattach test, the fork test, and a sentence for each reattach error code) were already addressed earlier on this branch.
To try it, call sync {repo} on a mirror in the preview at https://lab--4920--forge-trevato-apps.open-platform.sh. Add originId with an admin-scope token to reconnect.
Parked by the crew: the check stayed red through 2 automatic tries
MCP now has a
synctool, placed right aftertake_updates, and it calls the same functions as the two API routes. The type check is clean.test/mcp*andtest/spawn-chain.test.tspass (125); I did not run the full suite or the sandbox-skipped suites.What it does
sync {repo}callssyncRepoNow, asPOST /api/v1/repos/:owner/:name/syncdoes. It needs write access. A reader, or a repo that isn't a mirror, gets the API's refusals (not_found/ "write access"). A sync that reports an error comes back as an error.sync {repo, originId}callsreattachMirror, as…/origin/reconnectdoes. It needs an admin-scope token and an admin of the repo; another person's origin isnot_found./synctakes a fork's updates, but the tool answers "this is a fork; use take_updates" so the existing tool stays the one door for that.Other changes
docs/MCP.mdhas thesyncrow besidetake_updates.test/mcp-sync.test.tscovers: an admin syncs a mirror of a faked origin (no network), a non-mirror is refused, a reader is refused, and reconnecting is refused without an admin-scope token.test/mcp.test.ts's tool-order list now includessync.tools/listpast the 37,000-byte headroom, so I shortened about a dozen other descriptions to make room. I kept the words the tests assert on. This is the part to look at.Not done
test/mcp-sync.test.tsagainst a live reconnect. It only checks that an unknownoriginIdis refused and that a non-admin token is refused. A real reattach needs a detached mirror and a second origin, whichtest/origins-reconnect.test.tsalready covers on the API side.Closes #4903