mcp: validate tool output (#352)
Validate the handler's returned output against the output schema of a tool. Fixes #301.
This commit is contained in:
parent
d0c5943f25
commit
8314ec099b
1 changed files with 35 additions and 7 deletions
|
|
@ -247,8 +247,12 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
|
|||
}, nil
|
||||
}
|
||||
|
||||
// TODO(v0.3.0): Validate out.
|
||||
_ = outputResolved
|
||||
// Validate output schema, if any.
|
||||
// Skip if out is nil: we've removed "null" from the output schema, so nil won't validate.
|
||||
if v := reflect.ValueOf(out); v.Kind() == reflect.Pointer && v.IsNil() {
|
||||
} else if err := validateSchema(outputResolved, &out); err != nil {
|
||||
return nil, fmt.Errorf("tool output: %w", err)
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
res = &CallToolResult{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue