mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-17 07:58:08 +01:00
🧰 fix: Convert const to enum in MCP Schemas for Gemini Compatibility (#11784)
* fix: Convert `const` to `enum` in MCP tool schemas for Gemini/Vertex AI compatibility Gemini/Vertex AI rejects the JSON Schema `const` keyword in function declarations with a 400 error. Previously, the Zod conversion layer accidentally stripped `const`, but after migrating to pass raw JSON schemas directly to providers, the unsupported keyword now reaches Gemini verbatim. Add `normalizeJsonSchema` to recursively convert `const: X` → `enum: [X]`, which is semantically equivalent per the JSON Schema spec and supported by all providers. * fix: Update secure cookie handling in AuthService to use dynamic secure flag Replaced the static `secure: isProduction` with a call to `shouldUseSecureCookie()` in the `setOpenIDAuthTokens` function. This change ensures that the secure cookie setting is evaluated at runtime, improving cookie handling in development environments while maintaining security in production. * refactor: Simplify MCP tool key formatting and remove unused mocks in tests - Updated MCP test suite to replace static tool key formatting with a dynamic delimiter from Constants, enhancing consistency and maintainability. - Removed unused mock implementations for `@langchain/core/tools` and `@librechat/agents`, streamlining the test setup. - Adjusted related test cases to reflect the new tool key format, ensuring all tests remain functional. * chore: import order
This commit is contained in:
parent
276ac8d011
commit
ccbf9dc093
6 changed files with 287 additions and 79 deletions
|
|
@ -8,9 +8,10 @@
|
|||
import { Constants, actionDelimiter } from 'librechat-data-provider';
|
||||
import type { AgentToolOptions } from 'librechat-data-provider';
|
||||
import type { LCToolRegistry, JsonSchemaType, LCTool, GenericTool } from '@librechat/agents';
|
||||
import { buildToolClassification, type ToolDefinition } from './classification';
|
||||
import type { ToolDefinition } from './classification';
|
||||
import { resolveJsonSchemaRefs, normalizeJsonSchema } from '~/mcp/zod';
|
||||
import { buildToolClassification } from './classification';
|
||||
import { getToolDefinition } from './registry/definitions';
|
||||
import { resolveJsonSchemaRefs } from '~/mcp/zod';
|
||||
|
||||
export interface MCPServerTool {
|
||||
function?: {
|
||||
|
|
@ -138,7 +139,7 @@ export async function loadToolDefinitions(
|
|||
name: actualToolName,
|
||||
description: toolDef.function.description,
|
||||
parameters: toolDef.function.parameters
|
||||
? resolveJsonSchemaRefs(toolDef.function.parameters)
|
||||
? normalizeJsonSchema(resolveJsonSchemaRefs(toolDef.function.parameters))
|
||||
: undefined,
|
||||
serverName,
|
||||
});
|
||||
|
|
@ -153,7 +154,7 @@ export async function loadToolDefinitions(
|
|||
name: toolName,
|
||||
description: toolDef.function.description,
|
||||
parameters: toolDef.function.parameters
|
||||
? resolveJsonSchemaRefs(toolDef.function.parameters)
|
||||
? normalizeJsonSchema(resolveJsonSchemaRefs(toolDef.function.parameters))
|
||||
: undefined,
|
||||
serverName,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue