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

Parked opened this
Closed without merging

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.

Notes

stopped parked by the crew deploy 207361d

opened this

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? } calls commitToBranch as POST …/contents does. The route is untouched. It is marked writes: true, so a token without rw scope can't call it. Permission is requireWriter inside commitToBranch, so a stranger or reader gets the route's refusal codes. The answer is JSON with the commit and a says sentence ("Committed <path> to <branch>.").
  • Validation: wrong types, an unsafe branch or base name, a path that fails isSafeTreePath, an empty or over-1024-character message, and content over 2 MB each come back as a one-sentence refusal. A .git path 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.md sits beside read_file with writes ticked. test/mcp-write-file.test.ts covers:
    • a writer commits and read_file reads it back, on main and on a new branch;
    • a reader (an ro token) and a stranger are refused;
    • bad paths, branches, content and message are refused.
  • Changed an existing test: test/mcp.test.ts lists the tool names exactly, so I added write_file to 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 …/edits does both.

Closes #5289

commented

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? } calls commitToBranch as POST …/contents does. The route is untouched. It is marked writes: true, so a token without rw scope can't call it. Permission is requireWriter inside commitToBranch, so a stranger or reader gets the route's refusal codes. The answer is JSON with the commit and a says sentence ("Committed <path> to <branch>.").
  • Validation: wrong types, an unsafe branch or base name, a path that fails isSafeTreePath, an empty or over-1024-character message, and content over 2 MB each come back as a one-sentence refusal. A .git path 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.md sits beside read_file with writes ticked. test/mcp-write-file.test.ts covers:
    • a writer commits and read_file reads it back, on main and on a new branch;
    • a reader (an ro token) and a stranger are refused;
    • bad paths, branches, content and message are refused.
  • Changed an existing test: test/mcp.test.ts lists the tool names exactly, so I added write_file to 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 …/edits does both.
commented

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

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs