Skip to content

[Server] Fix SchemaValidator const errors reporting "null" - #748

Merged
chr-hertel merged 3 commits into
modelcontextprotocol:mainfrom
XenosEleatikos:fix/const-validation-error-expected-value
Nov 16, 2026
Merged

chr-hertel merged 3 commits into
modelcontextprotocol:mainfrom
XenosEleatikos:fix/const-validation-error-expected-value

Conversation

@XenosEleatikos

Copy link
Copy Markdown
Contributor

Summary

  • SchemaValidator::formatError() read $args['expected'] for const violations, but opis/json-schema's ConstKeyword provides the value under const.
  • Every const failure therefore rendered as Value must be equal to the constant value: "null".
  • Read $args['const'] (with $args['expected'] as fallback) and cover string + null constants in unit tests.

Fixes #747

Test plan

  • vendor/bin/phpunit --filter=testConstConstraint tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php
  • make ci (full suite)

Made with Cursor

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 chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please check if this is also sufficient for your case?

Suggested change
$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);

Comment thread CHANGELOG.md Outdated
Comment on lines 1 to 13

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

First entry for 0.11.0 - that would look like this:

Suggested change
# 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
------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and let's go with "Fix const validation errors always reporting the expected value as null."

@chr-hertel chr-hertel changed the title Fix SchemaValidator const errors reporting "null" [Server] Fix SchemaValidator const errors reporting "null" Nov 16, 2026
@chr-hertel chr-hertel added bug Something isn't working Server Issues & PRs related to the Server component needs more work Not ready to be merged yet, needs additional follow-up from the author(s). labels Nov 16, 2026
XenosEleatikos and others added 2 commits November 16, 2026 20:18
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@XenosEleatikos

Copy link
Copy Markdown
Contributor Author

Thanks — applied both suggestions: dropped the expected fallback, and moved the changelog entry under 0.11.0 with your wording.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 const argument.
  • Add regression tests for string and null constants.
  • 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

@chr-hertel chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @XenosEleatikos!

@chr-hertel
chr-hertel merged commit 7014a96 into modelcontextprotocol:main Nov 16, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs more work Not ready to be merged yet, needs additional follow-up from the author(s). Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SchemaValidator const errors always report "null" instead of the expected value

3 participants