mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-05 07:40:19 +01:00
🔳 fix: Bare Object MCP Tool Schemas as Passthrough (#8637)
* 🔳 fix: Bare Object MCP Tool Schemas as Passthrough
* ci: Add cases for handling complex object schemas in convertJsonSchemaToZod
This commit is contained in:
parent
365e3bca95
commit
0aafdc0a86
2 changed files with 344 additions and 1 deletions
|
|
@ -361,6 +361,18 @@ export function convertJsonSchemaToZod(
|
|||
const shape: Record<string, z.ZodType> = {};
|
||||
const properties = schema.properties ?? {};
|
||||
|
||||
/** Check if this is a bare object schema with no properties defined
|
||||
and no explicit additionalProperties setting */
|
||||
const isBareObjectSchema =
|
||||
Object.keys(properties).length === 0 &&
|
||||
schema.additionalProperties === undefined &&
|
||||
!schema.patternProperties &&
|
||||
!schema.propertyNames &&
|
||||
!schema.$ref &&
|
||||
!schema.allOf &&
|
||||
!schema.anyOf &&
|
||||
!schema.oneOf;
|
||||
|
||||
for (const [key, value] of Object.entries(properties)) {
|
||||
// Handle nested oneOf/anyOf if transformOneOfAnyOf is enabled
|
||||
if (transformOneOfAnyOf) {
|
||||
|
|
@ -436,8 +448,9 @@ export function convertJsonSchemaToZod(
|
|||
}
|
||||
|
||||
// Handle additionalProperties for open-ended objects
|
||||
if (schema.additionalProperties === true) {
|
||||
if (schema.additionalProperties === true || isBareObjectSchema) {
|
||||
// This allows any additional properties with any type
|
||||
// Bare object schemas are treated as passthrough to allow dynamic properties
|
||||
zodSchema = objectSchema.passthrough();
|
||||
} else if (typeof schema.additionalProperties === 'object') {
|
||||
// For specific additional property types
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue