Skip to content

Commit 607d6c2

Browse files
authored
simplify required field handling in inputSchema (#82)
1 parent 6d840a4 commit 607d6c2

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

mcp/tools.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,7 @@ func WithBoolean(name string, opts ...PropertyOption) ToolOption {
305305
// Remove required from property schema and add to InputSchema.required
306306
if required, ok := schema["required"].(bool); ok && required {
307307
delete(schema, "required")
308-
if t.InputSchema.Required == nil {
309-
t.InputSchema.Required = []string{name}
310-
} else {
311-
t.InputSchema.Required = append(t.InputSchema.Required, name)
312-
}
308+
t.InputSchema.Required = append(t.InputSchema.Required, name)
313309
}
314310

315311
t.InputSchema.Properties[name] = schema
@@ -331,11 +327,7 @@ func WithNumber(name string, opts ...PropertyOption) ToolOption {
331327
// Remove required from property schema and add to InputSchema.required
332328
if required, ok := schema["required"].(bool); ok && required {
333329
delete(schema, "required")
334-
if t.InputSchema.Required == nil {
335-
t.InputSchema.Required = []string{name}
336-
} else {
337-
t.InputSchema.Required = append(t.InputSchema.Required, name)
338-
}
330+
t.InputSchema.Required = append(t.InputSchema.Required, name)
339331
}
340332

341333
t.InputSchema.Properties[name] = schema
@@ -357,11 +349,7 @@ func WithString(name string, opts ...PropertyOption) ToolOption {
357349
// Remove required from property schema and add to InputSchema.required
358350
if required, ok := schema["required"].(bool); ok && required {
359351
delete(schema, "required")
360-
if t.InputSchema.Required == nil {
361-
t.InputSchema.Required = []string{name}
362-
} else {
363-
t.InputSchema.Required = append(t.InputSchema.Required, name)
364-
}
352+
t.InputSchema.Required = append(t.InputSchema.Required, name)
365353
}
366354

367355
t.InputSchema.Properties[name] = schema
@@ -384,11 +372,7 @@ func WithObject(name string, opts ...PropertyOption) ToolOption {
384372
// Remove required from property schema and add to InputSchema.required
385373
if required, ok := schema["required"].(bool); ok && required {
386374
delete(schema, "required")
387-
if t.InputSchema.Required == nil {
388-
t.InputSchema.Required = []string{name}
389-
} else {
390-
t.InputSchema.Required = append(t.InputSchema.Required, name)
391-
}
375+
t.InputSchema.Required = append(t.InputSchema.Required, name)
392376
}
393377

394378
t.InputSchema.Properties[name] = schema
@@ -410,11 +394,7 @@ func WithArray(name string, opts ...PropertyOption) ToolOption {
410394
// Remove required from property schema and add to InputSchema.required
411395
if required, ok := schema["required"].(bool); ok && required {
412396
delete(schema, "required")
413-
if t.InputSchema.Required == nil {
414-
t.InputSchema.Required = []string{name}
415-
} else {
416-
t.InputSchema.Required = append(t.InputSchema.Required, name)
417-
}
397+
t.InputSchema.Required = append(t.InputSchema.Required, name)
418398
}
419399

420400
t.InputSchema.Properties[name] = schema

0 commit comments

Comments
 (0)