LibreChat/packages/api/src/mcp/__tests__
Danny Avila 8969034ad1
fix: Strip remaining unsupported JSON Schema keywords for Gemini MCP tools (#13850)
*  fix: Strip remaining unsupported JSON Schema keywords for Gemini MCP tools

Gemini's FunctionDeclaration.parameters schema rejects more JSON Schema
keywords than sanitizeGeminiSchema previously stripped. MCP tools shipping
examples/readOnly/multipleOf/uniqueItems/prefixItems/etc. still 400 with
`Unknown name "<key>"`, the same class as #13623 (exclusiveMinimum).

Verified live against gemini-2.5-flash and gemini-3.5-flash: each added
keyword is rejected through `parameters`, and @langchain/google-genai only
removes additionalProperties/$schema, so they must be stripped here.

*  refactor: Make Gemini strip-list fully live-verified; preserve `default`

Probed every candidate keyword against both the live Gemini API
(gemini-2.5-flash, gemini-3.5-flash) and Vertex AI. Confirmed the inferred
siblings (dependencies/dependentSchemas/contentSchema) are rejected, so they
stay. Dropped `default`: it is part of Gemini's Schema and is accepted by both
the Gemini API and Vertex (no documented reason for its removal in #13623), so
it is now preserved instead of stripped.

*  fix: Preserve `default` data and synthesize array `items` (Codex P2s)

Addresses two Codex findings on the strip-list rework:

- `default` is now copied verbatim instead of recursed, so object/array default
  values (e.g. `{ id: 'abc', readOnly: true }`) keep ordinary data keys that the
  schema-recursion would otherwise strip.
- `prefixItems` is dropped but its first member is synthesized into `items`, since
  Gemini's API requires `items` on every array (live: itemless array => 400; the
  synthesized `{type:array, items:{...}}` => 200 on Gemini 2.5/3.5 and Vertex).

Third finding (patternProperties -> empty object) not actioned: live probing shows
`{type:'object'}` with no properties is accepted by both the Gemini API and Vertex.

*  fix: Treat boolean/tuple array `items` as missing (Codex P2)

The Draft 2020 tuple form `prefixItems: [...], items: false` slipped through: the
`'items' in collapsed` check treated boolean `false` as a real item schema, so no
fallback was synthesized and `items: false` was emitted — which Gemini rejects
(live: `items: false`/`true` => 400 "Invalid value").

Now `items` is only kept when it is a schema object; boolean and tuple-array
(`items: [...]`) forms are dropped, a `prefixItems` member is synthesized when
present, and any array still missing `items` falls back to `{}` (verified accepted
by the Gemini API and Vertex). Adds an `isObjectSchema` guard + tests.
2026-06-19 13:14:47 -04:00
..
helpers 🤫 refactor: Silent MCP OAuth Refresh on Mid-Session 401 (#13369) 2026-06-10 13:12:42 -04:00
auth.test.ts
ConnectionsRepository.test.ts 🔐 fix: Honor Admin-Panel MCP Allowlist Overrides Without Restart (#13814) 2026-06-17 20:14:53 -04:00
customUserVars.integration.test.ts 🔑 fix: Type-Safe User Context Forwarding for Non-OAuth Tool Discovery (#12348) 2026-03-21 12:46:23 -04:00
dbSourced.integration.test.ts 🛡️ fix: Harden MCP OAuth Request Handling (#13264) 2026-05-22 20:39:16 -04:00
detectOAuth.integration.dev.ts
handler.refreshScope.test.ts 🪃 fix: Retry MCP OAuth Token Refresh Without Scope on Server Rejection (#13412) 2026-05-30 01:52:43 -04:00
handler.test.ts 🤫 refactor: Silent MCP OAuth Refresh on Mid-Session 401 (#13369) 2026-06-10 13:12:42 -04:00
mcp.spec.ts 🗝️ fix: Resolve MCP Runtime User and Request Placeholders (#13626) 2026-06-09 18:52:57 -04:00
MCPConnection.test.ts 🛂 fix: Detect OAuth Errors From HTTP 400 Responses (#11961) 2026-05-23 09:09:13 -04:00
MCPConnectionAgentLifecycle.test.ts 🛡️ fix: Harden MCP OAuth Request Handling (#13264) 2026-05-22 20:39:16 -04:00
MCPConnectionFactory.oauthSdk.integration.test.ts 🤫 refactor: Silent MCP OAuth Refresh on Mid-Session 401 (#13369) 2026-06-10 13:12:42 -04:00
MCPConnectionFactory.test.ts 🚐 fix: Reuse Request-Scoped MCP Connections per Run (#13673) 2026-06-11 01:17:14 -04:00
MCPConnectionSSRF.test.ts 🧷 fix: Harden MCP Proxy SSRF Checks (#13274) 2026-05-23 16:30:13 -04:00
MCPManager.test.ts 🔐 fix: Honor Admin-Panel MCP Allowlist Overrides Without Restart (#13814) 2026-06-17 20:14:53 -04:00
MCPOAuthAudience.test.ts 🪪 feat: MCP OAuth - Support audience parameter for Auth0/Cognito-style providers (#13402) 2026-05-30 06:59:39 -07:00
MCPOAuthClientRegistrationReuse.test.ts 🛡️ fix: Harden MCP OAuth Request Handling (#13264) 2026-05-22 20:39:16 -04:00
MCPOAuthConnectionEvents.test.ts 🤫 refactor: Silent MCP OAuth Refresh on Mid-Session 401 (#13369) 2026-06-10 13:12:42 -04:00
MCPOAuthCSRFFallback.test.ts 🏗️ feat: bulkWrite isolation, pre-auth context, strict-mode fixes (#12445) 2026-03-28 16:43:50 -04:00
MCPOAuthFlow.test.ts 🛡️ fix: Harden MCP OAuth Request Handling (#13264) 2026-05-22 20:39:16 -04:00
MCPOAuthRaceCondition.test.ts 🔐 fix: Honor Admin-Panel MCP Allowlist Overrides Without Restart (#13814) 2026-06-17 20:14:53 -04:00
MCPOAuthSecurity.test.ts 🔬 ci: Add TypeScript Type Checks to Backend Workflow and Fix All Type Errors (#12451) 2026-03-28 21:06:39 -04:00
MCPOAuthTokenExpiry.test.ts fix: Extend and Decouple MCP OAuth Flow Timeouts (#13622) 2026-06-09 17:50:02 -04:00
MCPOAuthTokenStorage.test.ts 🤫 refactor: Silent MCP OAuth Refresh on Mid-Session 401 (#13369) 2026-06-10 13:12:42 -04:00
methods.test.ts
parsers.test.ts 🛂 fix: Enforce MCP Permissions for Agent Tools (#13174) 2026-05-30 16:19:49 -04:00
reconnection-storm.test.ts 🔐 fix: Prefer WWW-Authenticate resource_metadata Hint for MCP OAuth (#12763) 2026-04-21 16:26:20 -07:00
request.test.ts 🪢 fix: Tie MCP Cleanup To Resumable Runs (#13769) 2026-06-15 15:26:03 -04:00
tokens.test.ts
utils.test.ts 🥽 fix: Restrict MCP Server URL Disclosure to Admins, Owners, and Editors (#13784) 2026-06-16 11:20:52 -04:00
zod.spec.ts fix: Strip remaining unsupported JSON Schema keywords for Gemini MCP tools (#13850) 2026-06-19 13:14:47 -04:00