Repository navigation
[Server] Fix SchemaValidator const errors reporting "null" - #748
Conversation
opis/json-schema provides the expected value under the `const` key; reading `expected` always fell back to the literal "null". Co-authored-by: Cursor <cursoragent@cursor.com>
chr-hertel
left a comment
There was a problem hiding this comment.
Thanks @XenosEleatikos - small follow up and we're good!
| break; | ||
| case 'const': | ||
| $expected = json_encode($args['expected'] ?? 'null', \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); | ||
| $expected = json_encode($args['const'] ?? $args['expected'] ?? null, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); |
There was a problem hiding this comment.
please check if this is also sufficient for your case?
| $expected = json_encode($args['const'] ?? $args['expected'] ?? null, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); | |
| $expected = json_encode($args['const'] ?? null, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); |
There was a problem hiding this comment.
First entry for 0.11.0 - that would look like this:
| # Changelog | |
| All notable changes to `mcp/sdk` will be documented in this file. | |
| 0.11.0 | |
| ------ | |
| ### Server | |
| * Fix `SchemaValidator` reporting every `const` violation as `"null"`: it reads the expected value from `opis/json-schema`'s `const` error arg instead of a non-existent `expected` key. | |
| 0.10.0 | |
| ------ |
There was a problem hiding this comment.
and let's go with "Fix const validation errors always reporting the expected value as null."
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks — applied both suggestions: dropped the |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the fix to expected-value reporting in server-side const validation errors.
No open issues 🎉
What changed in this PR
Fixes #747 by making server-side const validation errors report the actual expected value instead of always displaying "null".
Changes:
- Read the expected constant from the validator’s
constargument. - Add regression tests for string and
nullconstants. - Document the fix in the 0.11.0 changelog.
| File | Description |
|---|---|
| tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php | Tests error messages for string and null constants. |
| src/Server/Capability/Discovery/SchemaValidator.php | Corrects the argument used to format constant values. |
| CHANGELOG.md | Records the server validation fix under 0.11.0. |
Review effort: Balanced
Summary
SchemaValidator::formatError()read$args['expected']forconstviolations, butopis/json-schema'sConstKeywordprovides the value underconst.constfailure therefore rendered asValue must be equal to the constant value: "null".$args['const'](with$args['expected']as fallback) and cover string +nullconstants in unit tests.Fixes #747
Test plan
vendor/bin/phpunit --filter=testConstConstraint tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.phpmake ci(full suite)Made with Cursor