internal/mcp: validate tool input schemas

A tool now validates its input with its InputSchema.

Change schema inference to allow explicit nulls for fields of
pointer type.

We assume the schema has no external references. For example, the
following schema cannot be handled:

  {
    "$ref": "https://example.com/other.json"
  }

Schemas with internal references, like to a "$defs", are fine.

Change-Id: I6ee7c18c2c5cb609df0b22a66da986f7ea64bbe4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/670676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Jonathan Amsterdam 2025-05-06 06:55:07 -04:00
commit a07ce11b37

View file

@ -270,7 +270,7 @@ func jsonType(v reflect.Value) (string, bool) {
return "string", true
case reflect.Slice, reflect.Array:
return "array", true
case reflect.Map:
case reflect.Map, reflect.Struct:
return "object", true
default:
return "", false