Repository navigation
[Server] Accept nested empty objects in tool arguments - #609
Closed
chr-hertel wants to merge 1 commit into
Closed
chr-hertel wants to merge 1 commit into
chr-hertel wants to merge 1 commit into
Conversation
chr-hertel
requested review from
CodeWithKyrian,
Nyholm and
soyuka
as code owners
October 18, 2026 14:03
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Conflicting branch repairs and union-type constraints still cause valid empty-object arguments to be rejected.
2 open issues
What changed in this PR
Adds opt-in handling of nested empty objects during tool argument validation, while preserving array-based handler inputs and strict output validation.
Changes:
- Retry validation after converting eligible empty arrays to objects.
- Enable this behavior for tool arguments.
- Add regression tests and a changelog entry.
| File | Description |
|---|---|
| tests/Unit/Server/Handler/Request/CallToolHandlerTest.php | Tests nested empty-object arguments and unchanged handler inputs. |
| tests/Unit/Capability/Discovery/SchemaValidatorTest.php | Tests opt-in conversion and strict validation. |
| src/Server/Handler/Request/CallToolHandler.php | Enables conversion for input validation. |
| src/Capability/Discovery/SchemaValidator.php | Adds error-driven conversion and validation retries. |
| CHANGELOG.md | Documents the fix and validator option. |
Review effort: Balanced
| { | ||
| $errors = []; | ||
| if (null !== $error) { | ||
| $this->collectLeafErrors($error, $errors); |
Comment on lines
+170
to
+171
| if ('type' !== $leaf->keyword() || [] !== $leaf->data()->value() || !\in_array('object', $expected, true) || \in_array('array', $expected, true)) { | ||
| continue; |
Member
Author
|
naah, not really |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Tool arguments are decoded with
assoc: true, so a nested{}arrives as[]and failed anobjectschema. Only the root was patched.SchemaValidator::validateAgainstJsonSchema()now takesemptyArrayMayBeObject: true: an empty array that only failed for not being an object is turned into{}and validated again. Since opis resolves the schema,$ref,additionalProperties,itemsandoneOf/anyOfare covered; a branch that accepts[]keeps it an array.CallToolHandleruses it for arguments and drops its root special case. Output validation stays strict.This is not #587: arguments are still decoded with
assoc: trueand handlers still get arrays, so nothing changes for them. It only stops valid{}from being rejected. What stays lossy until #587:[]sent for an object-only parameter is accepted, as the root already was{"0":"x"}and["x"]can't be told apartFixes #586