@@ -151,42 +151,86 @@ export function isPropertyRequired(
151
151
* @returns A normalized schema or the original schema
152
152
*/
153
153
export function normalizeUnionType ( schema : JsonSchemaType ) : JsonSchemaType {
154
- // Handle anyOf with string and null (FastMCP pattern)
154
+ // Handle anyOf with exactly string and null (FastMCP pattern)
155
155
if (
156
156
schema . anyOf &&
157
+ schema . anyOf . length === 2 &&
157
158
schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "string" ) &&
158
159
schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
159
160
) {
160
161
return { ...schema , type : "string" , anyOf : undefined } ;
161
162
}
162
163
163
- // Handle anyOf with boolean and null (FastMCP pattern)
164
+ // Handle anyOf with exactly boolean and null (FastMCP pattern)
164
165
if (
165
166
schema . anyOf &&
167
+ schema . anyOf . length === 2 &&
166
168
schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "boolean" ) &&
167
169
schema . anyOf . some ( ( t ) => ( t as JsonSchemaType ) . type === "null" )
168
170
) {
169
171
return { ...schema , type : "boolean" , anyOf : undefined } ;
170
172
}
171
173
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
173
195
if (
174
196
Array . isArray ( schema . type ) &&
197
+ schema . type . length === 2 &&
175
198
schema . type . includes ( "string" ) &&
176
199
schema . type . includes ( "null" )
177
200
) {
178
201
return { ...schema , type : "string" } ;
179
202
}
180
203
181
- // Handle array type with boolean and null
204
+ // Handle array type with exactly boolean and null
182
205
if (
183
206
Array . isArray ( schema . type ) &&
207
+ schema . type . length === 2 &&
184
208
schema . type . includes ( "boolean" ) &&
185
209
schema . type . includes ( "null" )
186
210
) {
187
211
return { ...schema , type : "boolean" } ;
188
212
}
189
213
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
+
190
234
return schema ;
191
235
}
192
236
0 commit comments