fix(mcp): preserve binary skill other files via base64 encoding - #2582
Merged
Conversation
Skill other files were transported through the MCP get/put surface as UTF-8 strings, which corrupted binary files such as images. Other file entries now carry an optional encoding field (utf-8 by default, base64 for binary), applied symmetrically on get and put, and put writes the decoded bytes verbatim. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Also document the encoding round-trip requirement and the base64/size validation rules, and measure the skill size limit in bytes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Background
Issue #2573 tracks four follow-ups from the PR #2568 review.
Items 1 and 3, plus the
isBinaryBufferpart of item 2, are obsolete: PR #2575 deletedisBinaryBufferfromsrc/utils/file.tsentirely, because skill companion files are now copied byte-faithfully with no text/binary split.What remained actionable:
src/mcp/skills.tsconverted skill other-file buffers withfileBuffer.toString("utf-8")on bothgetandput, so binary skill files (images, archives) were corrupted through the MCP surface. This is the same class of bug PR fix: write binary skill other-files without UTF-8 corruption #2568/fix(skills): copy skill supporting files byte-faithfully #2575 fixed for import/generate.readFileBufferOrNullhad no direct unit tests.Changes
otherFilesentries now carry an optionalencodingfield ("utf-8" | "base64"), applied symmetrically ongetandput.get, encoding is decided by whether the buffer survives a UTF-8 round trip byte-identically; text files keepencoding: "utf-8"and their existing body, so existing clients are unaffected.put, the client-declared encoding is trusted (defaulting to"utf-8"), base64 bodies are validated to reject silently-dropped invalid input, and the decoded bytes are written withwriteFileBufferinstead ofwriteFileContent.src/mcp/skills.ts,src/mcp/tools.ts) and tool descriptions updated to exposeencoding.docs/reference/mcp-server.mddocuments theotherFilesshape and the encoding rules (embedded docs regenerated).utf-8shape, omitted encoding is treated as UTF-8 even when the body looks like base64, invalid base64 is rejected, plus directreadFileBufferOrNulltests (missing file -> null, existing file -> exact bytes).Closes #2573
🤖 Generated with Claude Code