fix: replace z.base64() with z.string() for Gemini compatibility#10
Open
RaviTharuma wants to merge 1 commit intoagentmail-to:mainfrom
Open
fix: replace z.base64() with z.string() for Gemini compatibility#10RaviTharuma wants to merge 1 commit intoagentmail-to:mainfrom
RaviTharuma wants to merge 1 commit intoagentmail-to:mainfrom
Conversation
z.base64() generates `contentEncoding: "base64"` in the JSON Schema output (via zod-to-json-schema). Google Gemini's function calling API does not support `contentEncoding` in its schema subset, causing 400 errors when registering tools that use this field. Replacing with z.string() preserves the same runtime behavior (base64 strings are valid strings) while producing a Gemini-compatible schema. The description already indicates the expected format is base64. Fixes agentmail-to/agentmail-mcp#8
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
z.base64()withz.string()inAttachmentSchema.contentfieldz.base64()generatescontentEncoding: "base64"in JSON Schema output, which Google Gemini's function calling API does not supportsend_message,reply_to_message,forward_message)Problem
When MCP tools are registered with Gemini models, the generated JSON Schema includes:
{ "content": { "type": "string", "contentEncoding": "base64", "format": "base64", "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*..." } }Gemini only supports a subset of JSON Schema (
type,description,enum,items,properties,required,format,nullable) and rejectscontentEncodingwith:Fix
z.string()produces a clean{"type": "string"}schema that all providers accept. The.describe('Base64 encoded content')already communicates the expected format to the LLM. Runtime behavior is unchanged since base64 strings are valid strings.References
Summary by cubic
Replace AttachmentSchema.content from z.base64() to z.string() to produce Gemini-compatible JSON Schema. This removes the unsupported contentEncoding field and fixes 400 errors when registering tools with attachments (e.g., send_message, reply_to_message, forward_message).
Written for commit 8dbea9e. Summary will update on new commits.