LibreChat/api/server
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
..
controllers 🧊 fix: Include Conversation Starters in Agent View and List Responses (#14142) 2026-07-08 12:54:54 -04:00
middleware 🧷 fix: Align Agent File Attachment Ownership (#14149) 2026-07-07 16:23:48 -04:00
routes 🧷 fix: Align Agent File Attachment Ownership (#14149) 2026-07-07 16:23:48 -04:00
services fix: Resolve Local JSON Pointer Refs & Sanitize Tool Search Schema for Gemini (#14161) 2026-07-08 15:30:37 -04:00
utils 🔄 feat: Continue Shared Conversations as Personal Copies (#13714) 2026-06-24 16:27:01 -04:00
cleanup.js 🧹 refactor: Tighten Config Schema Typing and Remove Deprecated Fields (#12452) 2026-03-29 01:10:57 -04:00
experimental.js 🧹 feat: Eager HITL Checkpoint Cleanup (Expiry + Deletion) & Full-Wiring E2E (#14123) 2026-07-05 11:29:30 -04:00
index.js 🧹 feat: Eager HITL Checkpoint Cleanup (Expiry + Deletion) & Full-Wiring E2E (#14123) 2026-07-05 11:29:30 -04:00
index.metrics.spec.js ⚖️ feat: Add Operational Prometheus Metrics (#13265) 2026-05-22 20:47:41 -04:00
index.spec.js ⚙️ refactor: lazy-load React Query Devtools (#13639) 2026-06-10 13:06:20 -04:00
socialLogins.js feat: Make OpenID Token Reuse Window Configurable (#13546) 2026-06-06 15:15:58 -04:00
socialLogins.spec.js feat: Make OpenID Token Reuse Window Configurable (#13546) 2026-06-06 15:15:58 -04:00
telemetry.js 📡 feat: Add Backend OpenTelemetry Tracing (#12909) 2026-05-14 09:08:55 -04:00
telemetry.spec.js 📡 feat: Add Backend OpenTelemetry Tracing (#12909) 2026-05-14 09:08:55 -04:00