🔳 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:
Danny Avila 2025-07-24 00:11:20 -04:00 committed by GitHub
parent 365e3bca95
commit 0aafdc0a86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 344 additions and 1 deletions

View file

@ -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