Skip to content

fix: replace z.base64() with z.string() for Gemini compatibility#10

Open
RaviTharuma wants to merge 1 commit intoagentmail-to:mainfrom
RaviTharuma:fix/gemini-contentEncoding-compat
Open

fix: replace z.base64() with z.string() for Gemini compatibility#10
RaviTharuma wants to merge 1 commit intoagentmail-to:mainfrom
RaviTharuma:fix/gemini-contentEncoding-compat

Conversation

@RaviTharuma
Copy link

@RaviTharuma RaviTharuma commented Mar 1, 2026

Summary

  • Replace z.base64() with z.string() in AttachmentSchema.content field
  • z.base64() generates contentEncoding: "base64" in JSON Schema output, which Google Gemini's function calling API does not support
  • This causes 400 errors for all tools that include attachments (send_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 rejects contentEncoding with:

Unknown name "contentEncoding" at 'request.tools[0].function_declarations[N].parameters...'

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.

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
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant