@@ -151,42 +151,86 @@ export function isPropertyRequired(
151151 * @returns A normalized schema or the original schema
152152 */
153153export function normalizeUnionType ( schema : JsonSchemaType ) : JsonSchemaType {
154- // Handle anyOf with string and null (FastMCP pattern)
154+ // Handle anyOf with exactly string and null (FastMCP pattern)
155155 if (
156156 schema . anyOf &&
157+ schema . anyOf . length === 2 &&
157158 schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "string" ) &&
158159 schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
159160 ) {
160161 return { ...schema , type : "string" , anyOf : undefined } ;
161162 }
162163
163- // Handle anyOf with boolean and null (FastMCP pattern)
164+ // Handle anyOf with exactly boolean and null (FastMCP pattern)
164165 if (
165166 schema . anyOf &&
167+ schema . anyOf . length === 2 &&
166168 schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "boolean" ) &&
167169 schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
168170 ) {
169171 return { ...schema , type : "boolean" , anyOf : undefined } ;
170172 }
171173
172- // Handle array type with string and null
174+ // Handle anyOf with exactly number and null (FastMCP pattern)
175+ if (
176+ schema . anyOf &&
177+ schema . anyOf . length === 2 &&
178+ schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "number" ) &&
179+ schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
180+ ) {
181+ return { ...schema , type : "number" , anyOf : undefined } ;
182+ }
183+
184+ // Handle anyOf with exactly integer and null (FastMCP pattern)
185+ if (
186+ schema . anyOf &&
187+ schema . anyOf . length === 2 &&
188+ schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "integer" ) &&
189+ schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
190+ ) {
191+ return { ...schema , type : "integer" , anyOf : undefined } ;
192+ }
193+
194+ // Handle array type with exactly string and null
173195 if (
174196 Array . isArray ( schema . type ) &&
197+ schema . type . length === 2 &&
175198 schema . type . includes ( "string" ) &&
176199 schema . type . includes ( "null" )
177200 ) {
178201 return { ...schema , type : "string" } ;
179202 }
180203
181- // Handle array type with boolean and null
204+ // Handle array type with exactly boolean and null
182205 if (
183206 Array . isArray ( schema . type ) &&
207+ schema . type . length === 2 &&
184208 schema . type . includes ( "boolean" ) &&
185209 schema . type . includes ( "null" )
186210 ) {
187211 return { ...schema , type : "boolean" } ;
188212 }
189213
214+ // Handle array type with exactly number and null
215+ if (
216+ Array . isArray ( schema . type ) &&
217+ schema . type . length === 2 &&
218+ schema . type . includes ( "number" ) &&
219+ schema . type . includes ( "null" )
220+ ) {
221+ return { ...schema , type : "number" } ;
222+ }
223+
224+ // Handle array type with exactly integer and null
225+ if (
226+ Array . isArray ( schema . type ) &&
227+ schema . type . length === 2 &&
228+ schema . type . includes ( "integer" ) &&
229+ schema . type . includes ( "null" )
230+ ) {
231+ return { ...schema , type : "integer" } ;
232+ }
233+
190234 return schema ;
191235}
192236
0 commit comments