internal/mcp: apply JSON schema defaults
Before validating a tool input, apply the defaults from the input schema. Change-Id: I23fae4087f898d51b3d1f0578d3203b954cb5f2d Reviewed-on: https://go-review.googlesource.com/c/tools/+/680395 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
82be9ce756
commit
6a6c44171c
1 changed files with 59 additions and 16 deletions
|
|
@ -151,9 +151,11 @@ func unmarshalSchema(data json.RawMessage, resolved *jsonschema.Resolved, v any)
|
|||
if err := dec.Decode(v); err != nil {
|
||||
return fmt.Errorf("unmarshaling: %w", err)
|
||||
}
|
||||
// TODO(jba): apply defaults.
|
||||
// TODO: test with nil args.
|
||||
if resolved != nil {
|
||||
if err := resolved.ApplyDefaults(v); err != nil {
|
||||
return fmt.Errorf("applying defaults from \n\t%s\nto\n\t%s:\n%w", schemaJSON(resolved.Schema()), data, err)
|
||||
}
|
||||
if err := resolved.Validate(v); err != nil {
|
||||
return fmt.Errorf("validating\n\t%s\nagainst\n\t %s:\n %w", data, schemaJSON(resolved.Schema()), err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue