Skip to content

[bug] Gemini rejects MCP tool with nullable array schema (type: "array","null"): languages.items predicate failed + any_of0.items` missing field #48073

Description

@wenduof

Description

Description
Any request to a Gemini model fails with 400 INVALID_ARGUMENT when the @sylphx/pdf-reader-mcp MCP server is enabled — even a plain hello with no PDF involved. Gemini validates all function declarations up front, so one incompatible tool schema breaks every request. The same setup works fine on DeepSeek / OpenAI-compatible providers.
Error

  • GenerateContentRequest.tools[0].function_declarations[9].parameters.properties[languages].items: field predicate failed: $type == Type.ARRAY
  • GenerateContentRequest.tools[0].function_declarations[9].parameters.properties[languages].any_of[0].items: missing field.
    Root cause
    The MCP server's raw tools/list schema (queried directly, v4.1.3 = latest) declares:
    "languages": { "items": { "type": "string" }, "type": ["array", "null"] }
    This is valid JSON Schema, but after opencode/AI-SDK converts it to Gemini's function-calling schema, the multi-type array is split into anyOf, producing two invalid halves:
  1. top-level items left behind while type is no longer ARRAY → predicate failed: $type == Type.ARRAY
  2. a bare { "type": "array" } branch inside anyOf with no items → any_of[0].items: missing field (Gemini requires items on every array)
    The tool has ~15 similar union-typed fields (["string","null"], ["integer","null"], plus a nested sources.regions: ["array","null"]), so patching a single field is not enough — the converter/sanitizer needs to handle the pattern.
    Repro
  3. mcp.pdf-reader: npx @sylphx/pdf-reader-mcp (v4.1.3), enabled: true
  4. opencode run "hello" -m google/gemini-3.8-flash (also repros on gemini-2.5-flash-lite, gemini-3.5-flash-lite) → 400 above
  5. Set the server enabled: false, or a per-agent "pdf-reader_*": "deny" → hello-ok ✅ (verified A/B; deny proves the tools are excluded from declarations and the request then passes)
    Expected / proposed fix
    Extend sanitizeGemini in transform.ts (cf. [bug] Gemini API rejects MCP tool schemas with properties/required on non-object types #11889) to normalize multi-entry type arrays on the Gemini path, e.g. collapse type: ["array","null"] → type: "array", nullable: true keeping items on the array branch (same class of fix as LibreChat [FEATURE]: Multi-project core and API #13623 sanitizeGeminiSchema, and related to AI_APICallError: GenerateContentRequest.tools[0].function_declarations[32].parameters. required[0]: property is not defined with Gemini API #3140 / Gemini: all requests fail due to anyOf schema in github_create_pull_request_review tool #14509). Gemini-side nullable is the documented way to express optionality — no anyOf needed.
    Environment

Plugins

pdf-reader

OpenCode version

v1.18.27

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

Ubuntu 22.04

Terminal

Ptyxis

Activity

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

Metadata

Metadata

Assignees

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