Add patch-safe exact file update tool - #3232
Draft
jasonobrown wants to merge 4 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
apply_file_patch, a bounded exact-text update tool that lets the GitHub MCP server modify an existing UTF-8 file without requiring the MCP client/model to resend the entire replacement file.Refs #3231.
Motivation
The existing
create_or_update_file/push_filesinterfaces require complete replacement content. A real ~303 KB changelog update was truncated upstream of GitHub while only a small insertion was intended. The resulting branch commit was detected and discarded, but recovery required a separate local Git client.This tool keeps the large file server-side and sends only the intended exact replacements through MCP.
Safety model
expected_head_sha.expected_blob_shafor the target file.old_textmust match exactlyexpected_occurrencestimes at that step; default is one.force=false; concurrent branch movement fails non-fast-forward instead of overwriting it.Initial limits are 4 MiB target file, 256 KiB aggregate old/new patch text, and 100 ordered edits.
Tests
Includes focused unit coverage for ordered exact replacement, occurrence-count mismatch, empty match rejection, no-op rejection, and patch-size bounding.
I could statically verify the
go-github/v89Git API call signatures available from repository/dependency source, but this execution environment cannot clone the complete public repository to run the full Go suite locally. This PR is therefore intentionally draft until repository CI/build/snapshot/documentation checks establish the exact integration result. I will address concrete CI findings without weakening the fail-closed contract.