LibreChat/packages
Joseph Licata fc67416d08
fix: Resolve Local JSON Pointer Refs & Sanitize Tool Search Schema for Gemini (#14161)
*  fix: Resolve Local JSON Pointer Refs & Sanitize Tool Search Schema for Gemini

Gemini/Vertex agents fail when MCP tools are attached, in two ways:

1. MCP servers with OpenAPI-derived schemas can emit local JSON pointer
   refs (e.g. `#/properties/body/properties/start`). `resolveJsonSchemaRefs`
   only resolves `#/$defs` and `#/definitions` refs, so these survive into
   the request payload and Vertex rejects it with 400
   'Invalid JSON payload received. Unknown name "$ref"'. Resolve any local
   `#/...` pointer against the schema root (RFC 6901 unescaping, cycle
   protection), and strip still-unresolvable `$ref` keys in
   `sanitizeGeminiSchema` as a safety net.

2. When deferred tools are enabled, the injected `tool_search` schema
   declares `mcp_server` as `oneOf: [string, string[]]`, which
   `zod_to_gemini_parameters` rejects ('Gemini cannot handle union types').
   `buildToolClassification` now accepts the agent provider and collapses
   the union via `sanitizeGeminiSchema` for Google/Vertex only — the tool's
   runtime (`normalizeServerFilter`) already accepts both forms.

Complements #13623, which sanitizes MCP tool schemas but not the injected
tool_search definition, and did not cover non-$defs local pointers.
Underlying converter limitation: langchain-ai/langchainjs#9691.

* style: format tool search schema assignment

* style: sort tool classification imports

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
2026-07-08 15:30:37 -04:00
..
api fix: Resolve Local JSON Pointer Refs & Sanitize Tool Search Schema for Gemini (#14161) 2026-07-08 15:30:37 -04:00
client
data-provider
data-schemas