fix: several MCP server and TOML schema bugs - #67
Open
tellang wants to merge 1 commit into
Open
Conversation
- fileHandler: use os.homedir() instead of `process.env.HOME || '~'` for Downloads/Desktop search paths. Node does not set HOME on Windows, so the previous expression produced literal `~\Downloads` that silently never matched. - fileHandler: generateFilename now accepts a mimeType argument and derives the extension from it (JPEG -> jpg, PNG -> png, WebP -> webp, GIF -> gif), falling back to the caller's `format` only when the MIME type is missing or unrecognised. Previously the extension was always derived from `fileFormat` (default png), so JPEG bytes returned by the model were saved under a `.png` filename whenever `image/jpeg` came back in inlineData. - imageGenerator: forward `seed` to generateContent via `config`. The MCP generate_image tool has always exposed a seed parameter and ImageGenerationRequest carried it, but the value was dropped before reaching the Google GenAI SDK, making seeded variations a no-op. - imageGenerator: isValidBase64ImageData now checks PNG/JPEG/WebP/ GIF magic bytes after the base64 shape check, so long base64-like strings that aren't actually images (logs, JSON payloads) are no longer accepted. - commands/generate.toml: expose --no-preview flag. The MCP handler in index.ts already reads noPreview / no-preview, but the TOML parser prompt listed only --preview, so users had no documented way to force preview off. - commands/icon.toml: strengthen the --sizes instruction to require parsing as an integer array (e.g. "16,32,64" -> [16, 32, 64]), since the TOML LLM parser was occasionally forwarding it as a plain string or a single integer. The saveImageFromBase64 write race is deliberately left for PR gemini-cli-extensions#60, which already modifies that function.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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
Six small fixes, mostly in
fileHandler/imageGeneratorplus two TOML command schemas. Public MCP tool schemas (tool names, required args, output shapes) are unchanged.Fixes
fileHandlerusesos.homedir()for search paths —process.env.HOME || '~'produced literal~\Downloads/~\Desktopon Windows (Node doesn't setHOMEby default).os.homedir()resolvesHOMEon Unix andUSERPROFILEon Windows.generateFilenamematches extension to the actual MIME type — the model regularly returnsimage/jpegininlineData.mimeType, but the extension was derived solely from the caller'sformatargument (defaultpng). Result:.pngfiles on disk containing JPEG bytes (filereportsJPEG image data, JFIF standard 1.01). Added amimeType?: stringargument; picksjpg/png/webp/giffrom the MIME type, falling back toformatonly when the MIME type is missing or unrecognised.seedis forwarded togenerateContent—seedwas advertised in the MCP schema and carried inImageGenerationRequest, but silently dropped before the SDK call, making the parameter a no-op. Addedconfig: { seed }on the three call sites (generateTextToImage,generateStorySequence,editImage).isValidBase64ImageDatachecks magic bytes — previously any base64-shaped string longer than 1000 chars was accepted. Now checks PNG (89 50 4E 47 ...), JPEG (FF D8 FF), WebP (RIFF +WEBP), and GIF (GIF87a/GIF89a) magic on the first decoded bytes, so long non-image base64 payloads (logs, JSON) are no longer written to disk.commands/generate.tomlexposes--no-preview—index.tsalready readsnoPreview/no-previewin thegenerate_imagehandler, but the TOML parser prompt only listed--preview, so users had no documented way to force preview off. Added--no-preview (flag)to the valid-options list and the error-message fallback.commands/icon.tomlstrengthens--sizesparsing — the TOML LLM parser was occasionally forwarding--sizes="16,32,64"as a plain string or a single integer instead of[16, 32, 64]. Strengthened the prompt so the parser must produce an integer array before callinggenerate_icon.Out of scope
saveImageFromBase64write race — deliberately left for #60, which already modifies that function. Touching it here would just create a merge conflict.Test plan
npm run buildpasses cleanly inmcp-server/tools/listvia JSON-RPC still returns the same 7 tools with the same schemasgenerate_imagecall returnedmimeType: 'image/jpeg'and was saved assmoke_test_mime_fix_clean_white_.jpg(magic bytesFF D8 FF E0 ... JFIF). Before the fix, the same response would have written a.pngfileseedproducing deterministic output across back-to-back calls — the SDK accepts theconfig.seedfield, but I didn't run a reproducibility smokeHOMEis unset — old code would have silently failed, new code works). No explicit Downloads/Desktop lookup regression test.