Add input validation guidelines to CLAUDE.md and fix the case where there are null defaults #849
+94
−1
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.
The cleanParams function added in 0.17.0 was overly zealous and removes nulls being set by the tool schema as defaults.
Since there are a few opinionated ways to handle validation for tools I also added the established guidelines to the agent instructions, to make it clearer where and when validation should happen and what Inspector vs the server should handle in these scenarios.
Motivation and Context
Fixes #846
How Has This Been Tested?
I followed these test cases using a set of tools created for testing regression scenarios:
mcp-maintainer-toolkit@latest
Test 1: Union Type Test Tool (Primary Regression Test)
Tool:
unionTypeTest
Test 1a: Default null values are preserved and sent in
tools/call
unionTypeTest
tool without changing any valuestools/call
in the History panetools/call
paramsTest 1b: Default null values are sent if input is cleared
Test 1c: Null values are sent when user manually enters them
Test 1d: Non-null values override defaults
Test 2: Other Default Values
Tool:
formatData
Test 2a: String default value preserved
Test 2b: Enum default value preserved
Tool:
enumDropdownTest
Test 3: Optional Fields Without Defaults (Backward Compatibility)
Tool:
getCurrentTime
Test 3a: Empty optional field is omitted
Test 3b: Optional field with value is included
Test 4: Required fields preserve empty values for validation
strictTypeValidation
toolTest 5: Automated Tests
cd client && npm test -- paramUtils.test.ts
Breaking Changes
No - this part of the behavior is unintentional.
Types of changes
Checklist