-
Notifications
You must be signed in to change notification settings - Fork 216
mcp: update to jsonschema that does not validate structs #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Update to the latest jsonschema commit, which removes the ability to validate structs.
Do we need to update |
Yes indeed. Added a test. |
examples/server/toolschemas/main.go
Outdated
return errf("failed to unmarshal arguments: %v", err), nil | ||
} | ||
if err := t.inputSchema.Validate(input); err != nil { | ||
if err := validateStruct(input, t.inputSchema); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right: once we re-marshal, we're no longer validating the original JSON.
For example, suppose the input contains "foo": 0
, and the struct has omitempty
for the Foo
field, and "foo"
is required. Then the original input is valid, but the re-marshalled input is not.
This is why we should expose helpers for this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
} | ||
|
||
// unmarshalAndValidate unmarshals data to a map[string]any, then validates that against res. | ||
func unmarshalAndValidate(data []byte, res *jsonschema.Resolved) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to ApplyDefaults also? Not necessarily for this CL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That wasn't in the original, so I didn't add it.
But yes, that seems right. Will do a followup (possibly tomorrow).
Update to the latest jsonschema commit, which removes the ability to validate structs and changes the type of ForOptions.TypeSchemas.