Skip to content

Gemini function calling rejects tool schemas due to "contentEncoding" field #8

@RaviTharuma

Description

@RaviTharuma

Problem

When agentmail MCP tools are registered with Google Gemini models (via OpenCode/AI SDK), Gemini's function calling API rejects the tool schemas with:

Invalid JSON payload received. Unknown name "contentEncoding" at
'request.tools[0].function_declarations[131].parameters.properties[4].value.items.properties[2].value': Cannot find field.

This affects 3 tools: send_message, reply_to_message, forward_message -- all of which have attachments[].content defined with a contentEncoding: "base64" field in the JSON Schema.

Root Cause

The attachment content field likely uses Zod's z.string().base64() which, when serialized to JSON Schema via zod-to-json-schema, produces:

{
  "content": {
    "type": "string",
    "contentEncoding": "base64",
    "format": "base64",
    "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*..."
  }
}

contentEncoding is valid JSON Schema (RFC draft-07+) but Gemini's function calling API only supports a subset of JSON Schema and does not recognize this field. Gemini supports: type, description, enum, items, properties, required, format, nullable -- but NOT contentEncoding, contentMediaType, pattern, etc.

Affected Models

  • All Google Gemini models (gemini-2.5-, gemini-3-, gemini-3.1-*)
  • Any provider that uses Gemini's function calling schema validation

Suggested Fix

Use zod-to-json-schema with base64Strategy: "format:binary" instead of the default "contentEncoding:base64":

import { zodToJsonSchema } from 'zod-to-json-schema';

zodToJsonSchema(schema, { base64Strategy: 'format:binary' });

Or alternatively, define the field as a plain z.string() with a description noting it expects base64:

content: z.string().describe("Base64 encoded content")

Environment

  • OpenCode with Oh My OpenCode (OmO) orchestration
  • AI SDK provider routing through CLIProxyAPI/Quotio
  • agentmail MCP registered via mcpm.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions