fix: add boolean union type support for FastMCP optional booleans

This commit is contained in:
Mats Julius Funke 2025-08-02 16:35:42 +02:00
commit 5469993e27
No known key found for this signature in database

View file

@ -160,6 +160,15 @@ export function normalizeUnionType(schema: JsonSchemaType): JsonSchemaType {
return { ...schema, type: "string", anyOf: undefined };
}
// Handle anyOf with boolean and null (FastMCP pattern)
if (
schema.anyOf &&
schema.anyOf.some((t) => (t as JsonSchemaType).type === "boolean") &&
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
) {
return { ...schema, type: "boolean", anyOf: undefined };
}
// Handle array type with string and null
if (
Array.isArray(schema.type) &&
@ -169,6 +178,15 @@ export function normalizeUnionType(schema: JsonSchemaType): JsonSchemaType {
return { ...schema, type: "string" };
}
// Handle array type with boolean and null
if (
Array.isArray(schema.type) &&
schema.type.includes("boolean") &&
schema.type.includes("null")
) {
return { ...schema, type: "boolean" };
}
return schema;
}