Conversation
…ate_file and push_files JSON tool arguments must be valid UTF-8, so binary file content (e.g. images) could not be written through create_or_update_file or push_files: the content string was passed through verbatim, corrupting non-UTF-8 bytes. Add an optional encoding parameter (utf-8, the default, or base64) to both tools. For base64 content, create_or_update_file decodes it once before handing the raw bytes to the Contents API. push_files uploads decoded content as a git blob and references it by SHA in the tree, because the Trees API rejects TreeEntry content that is not valid UTF-8. Invalid base64 and unsupported encoding values return clear tool errors. Closes github#3312
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 an optional
encodingparameter ("utf-8"default,"base64") tocreate_or_update_fileandpush_filesso binary file content (e.g. images) can be written. Base64 content is decoded once and the raw bytes are written to the repository.Why
JSON tool arguments must be valid UTF-8, so a binary file cannot be passed as a plain string: non-UTF-8 bytes are corrupted on the way to the API. Both tools previously passed
contentthrough verbatim, which made it impossible to commit binary assets through the GitHub MCP server.Fixes #3312
What changed
create_or_update_file: new optionalencodingparameter.base64content is decoded once before being handed to the Contents API (which receives raw bytes and base64-encodes them itself). Invalid base64 and unsupported encoding values return clear tool errors.push_files: each file object accepts an optionalencodingparameter. Base64 content is decoded, uploaded via the Blobs API, and referenced by its blob SHA in the tree, because the Trees API rejectsTreeEntrycontent that is not valid UTF-8.MCP impact
encodingis optional with default"utf-8", so existing callers behave exactly as before.Prompts tested (tool changes only)
Tested through unit tests with mocked HTTP (see
Test_CreateOrUpdateFile/Test_PushFiles), covering the request bodies sent to the Contents, Blobs, and Trees APIs:create_or_update_filewithencoding: "base64".push_fileswith one utf-8 file and one base64 file; the tree references the binary by blob SHA.Security / limits
The change only adds a decode step of caller-supplied content; no new data sources, permissions, or unbounded operations are introduced.
Tool renaming
deprecated_tool_aliases.goLint & tests
./script/lint./script/testgofmt -sclean on changed files,golangci-lint run ./pkg/github/...reports 0 issues, andgo test ./...passes (verified: temporarily disabling the base64 branches turns the new tests red, then green again after restoring).Docs
Tool descriptions in the schemas document the new parameter; tool documentation is generated from these schemas.