Feat/filesystem content base64#4401
Open
Ev3lynx727 wants to merge 3 commits into
Open
Conversation
…ters Add optional content_base64 parameter to write_file and newText_base64 parameter to edit_file (per-edit). Base64 charset (A-Za-z0-9+/=) is fully JSON-safe, eliminating transport-level JSON serialization failures when file content contains backticks, quotes, template literals, or other special characters. - WriteFileArgsSchema: content becomes optional, content_base64 added - EditOperation: newText becomes optional, newText_base64 added - Both schemas use .refine() to require at least one of the two - Handlers decode base64 server-side via Buffer.from() - Fully backward-compatible: existing callers using content/newText continue unchanged Refs: modelcontextprotocol#4394
…d to MCP clients
The write_file and edit_file tool registrations used plain-object
inputSchema ({ path: z.string(), content: z.string() }) that excluded
content_base64/newText_base64. The MCP SDK validates against inputSchema,
so these parameters were silently stripped before the handler ran.
Fixing by passing the full Zod schemas (WriteFileArgsSchema,
EditFileArgsSchema) which include the optional base64 parameters.
E2E verified: server exposes content_base64 in schema, client sends it,
server decodes and writes correctly with all 147 existing tests passing.
…mands-rtk Before writing, ensure parent directory exists via fs.mkdir(recursive:true). Closes the gap between forked filesystem (validation + path security) and server-commands-rtk (auto-mkdir).
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.
Description
Add optional
content_base64/newText_base64parameters towrite_fileandedit_filetools. These are decoded server-side withBuffer.from(x, 'base64').Existing
contentandnewTextparameters remain unchanged — fully backward compatible. Callers provide one or the other; the.refine()Zod check enforces this.Also closes #2033 —
edit_filePowerShell$()interpolation failure, same root cause.Closes #4394
Server Details
write_file,edit_file)Motivation and Context
MCP tool parameters are serialized as JSON before transmission. File content containing special characters (quotes, backticks, newlines,
${}template syntax, PowerShell$()) can break JSON framing, causingJSON Parse error: Unterminated stringorCannot convert undefined or null to objectfailures on write operations.Base64 charset (
A-Za-z0-9+/=) is fully JSON-safe — zero escaping needed at any layer. The server already uses this pattern forread_media_fileoutput (readFileAsBase64Stream), so zero new dependencies.Bonus:
content: stringmakes binary file writes impossible.content_base64enables them.How Has This Tested?
",`,${},$(),\n, backslashes, unicode) — all pass withcontent_base64npm run build --workspace=src/filesystemcompiles cleanlynpm test --workspace=src/filesystem— all tests passBreaking Changes
None. Existing
contentandnewTextparameters unchanged. New*_base64parameters are purely additive.Types of changes
Checklist
Additional context
Schema
Prior Art
Our ecosystem — proven in production:
server-commands-rtk(Node.js MCP server) —write_filewithpath+content_b64. Used daily by OpenCode agent with zero JSON parse failures since implementation.anomalyco/opencode) — AGENTS.md documents this pattern as standard workaround.content_base64for filing large content into the knowledge palace.Upstream in this repo:
read_media_file— already returns base64-encoded images/audio viareadFileAsBase64Stream(). This completes the round-trip.No new environment variables or configuration options.
content_base64/newText_base64are optional tool parameters decoded server-side — zero config surface.Industry pattern: