Handle nullable arrays in tool inputSchemas #895
Merged
+28
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In DynamicJsonForm.tsx
In jsonUtils.ts
In schemaUtils.ts
In ToolsTab.tsx
Fixes #846
Motivation and Context
We recently merged a PR that added support for nullable fields, but the case of nullable arrays was not handled. This PR adds builds on that work.
In issue #846, we can see that when a tool's inputSchema has a nullable array field like this:
We respond like this:
How Has This Been Tested?
Nullable Array tool parameter
Added a nullable array field with default of null to the mcp-maintainer-toolkit project, which is based on the
everythingreference server but easier for adding weird testing scenarios. This duplicates the problematic structure reported in the #846. We're using number instead of integer, but this PR supports nullable arrays of any primitive type, so integer, string, or boolean would also work.Invoke tool with null checkbox checked
Since this tool param has a default of null, the
nullcheckbox starts out checked. Just hitting the submit button sends a null for the field.Invoke the tool with null checkbox unchecked but empty field
Unchecking the
nullcheckbox and submitting an empty field, causes the field not to be sent, but on the server, since it has a default of null, the server parses the missing field as containing a null value, also as expected.Invoke tool with an actual array
Unchecking the
nullcheckbox and entering an array of numbers, we can see it operates as expected.Breaking Changes
Nope.
Types of changes
Checklist
Additional context