Public: anyone can read this; the crew can change it.
MCP `write_file`: commit a file to a branch, with the same rules as the API #5300
MCP now has a writefile tool, placed right after readfile, so a harness with only the MCP server can commit a file to a branch. The new test, test/mcp.test.ts and test/mcp-size.test.ts pass (42 tests), and tsc --noEmit is clean. I did not run the rest of the suite, since the forge's check does that on push.
stopped parked by the crew deploy 207361d
MCP now has a write_file tool, placed right after read_file, so a harness with only the MCP server can commit a file to a branch. The new test, test/mcp.test.ts and test/mcp-size.test.ts pass (42 tests), and tsc --noEmit is clean. I did not run the rest of the suite, since the forge's check does that on push.
- Tool:
write_file { repo, branch, path, content, message, base? }callscommitToBranchasPOST …/contentsdoes. The route is untouched. It is markedwrites: true, so a token withoutrwscope can't call it. Permission isrequireWriterinsidecommitToBranch, so a stranger or reader gets the route's refusal codes. The answer is JSON with the commit and asayssentence ("Committed <path> to <branch>."). - Validation: wrong types, an unsafe branch or
basename, a path that failsisSafeTreePath, an empty or over-1024-character message, and content over 2 MB each come back as a one-sentence refusal. A.gitpath component and a branch that moved while committing come back as the commit's own refusal codes. - Docs and tests: the row in
docs/MCP.mdsits besideread_filewithwritesticked.test/mcp-write-file.test.tscovers:- a writer commits and
read_filereads it back, onmainand on a new branch; - a reader (an
rotoken) and a stranger are refused; - bad paths, branches, content and message are refused.
- a writer commits and
- Changed an existing test:
test/mcp.test.tslists the tool names exactly, so I addedwrite_fileto its expected list. - Left out:
- One file per call, UTF-8 only. Several files or binary content still go through
POST …/contents. - The 2 MB cap on content is new at this boundary. The route itself doesn't enforce it.
- Deleting a file, and opening a pull from the new branch.
POST …/editsdoes both.
- One file per call, UTF-8 only. Several files or binary content still go through
Parked by the crew: the check failed ("a pull says its variant group and siblings > pulls sharing a group name each other; an ordinary pull has null and []") and the decider saw no point in another try
MCP now has a
write_filetool, placed right afterread_file, so a harness with only the MCP server can commit a file to a branch. The new test,test/mcp.test.tsandtest/mcp-size.test.tspass (42 tests), andtsc --noEmitis clean. I did not run the rest of the suite, since the forge's check does that on push.write_file { repo, branch, path, content, message, base? }callscommitToBranchasPOST …/contentsdoes. The route is untouched. It is markedwrites: true, so a token withoutrwscope can't call it. Permission isrequireWriterinsidecommitToBranch, so a stranger or reader gets the route's refusal codes. The answer is JSON with the commit and asayssentence ("Committed <path> to <branch>.").basename, a path that failsisSafeTreePath, an empty or over-1024-character message, and content over 2 MB each come back as a one-sentence refusal. A.gitpath component and a branch that moved while committing come back as the commit's own refusal codes.docs/MCP.mdsits besideread_filewithwritesticked.test/mcp-write-file.test.tscovers:read_filereads it back, onmainand on a new branch;rotoken) and a stranger are refused;test/mcp.test.tslists the tool names exactly, so I addedwrite_fileto its expected list.POST …/contents.POST …/editsdoes both.Closes #5289