Skip to content

Conversation

jba
Copy link
Contributor

@jba jba commented Sep 22, 2025

Update to the latest jsonschema commit, which removes the ability to validate structs and changes the type of ForOptions.TypeSchemas.

Update to the latest jsonschema commit, which removes the ability
to validate structs.
@jba jba requested a review from findleyr September 22, 2025 14:57
@findleyr
Copy link
Contributor

Do we need to update examples/server/toolschemas? I believe it was validating structs.

@jba
Copy link
Contributor Author

jba commented Sep 22, 2025

Yes indeed. Added a test.

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 {
Copy link
Contributor

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

@jba jba marked this pull request as draft September 22, 2025 18:32
@jba jba marked this pull request as ready for review September 22, 2025 18:50
@jba jba requested a review from findleyr September 22, 2025 18:50
}

// unmarshalAndValidate unmarshals data to a map[string]any, then validates that against res.
func unmarshalAndValidate(data []byte, res *jsonschema.Resolved) error {
Copy link
Contributor

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.

Copy link
Contributor Author

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).

@jba jba merged commit 33ff851 into modelcontextprotocol:main Sep 22, 2025
6 checks passed
@findleyr findleyr added this to the v0.7.0 milestone Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants