From 99ba5261969381736209c0e5236f60636ddc369c Mon Sep 17 00:00:00 2001 From: Christoph Hochholzer Date: Mon, 16 Nov 2026 19:24:00 +0100 Subject: [PATCH 1/3] Fix SchemaValidator const errors reporting "null" opis/json-schema provides the expected value under the `const` key; reading `expected` always fell back to the literal "null". Co-authored-by: Cursor --- CHANGELOG.md | 7 ++++++ .../Capability/Discovery/SchemaValidator.php | 2 +- .../Discovery/SchemaValidatorTest.php | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb0b7062..edf7dd16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +Unreleased +---------- + +### 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. + # Changelog All notable changes to `mcp/sdk` will be documented in this file. diff --git a/src/Server/Capability/Discovery/SchemaValidator.php b/src/Server/Capability/Discovery/SchemaValidator.php index 9350fc83..c5f0afc4 100644 --- a/src/Server/Capability/Discovery/SchemaValidator.php +++ b/src/Server/Capability/Discovery/SchemaValidator.php @@ -240,7 +240,7 @@ private function formatValidationError(ValidationError $error): string } 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); $message = "Value must be equal to the constant value: {$expected}."; break; case 'minLength': diff --git a/tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php b/tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php index d62a9311..49039559 100644 --- a/tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php +++ b/tests/Unit/Server/Capability/Discovery/SchemaValidatorTest.php @@ -113,6 +113,28 @@ public function testEnumConstraintViolation(): void $this->assertStringContainsString('must be one of the allowed values: "A", "B"', $errors[0]['message']); } + public function testConstConstraintViolationIncludesExpectedValue(): void + { + $schema = ['type' => 'string', 'const' => 'PairMatching']; + $data = 'Quiz'; + + $errors = $this->validator->validateAgainstJsonSchema($data, $schema); + $this->assertCount(1, $errors); + $this->assertEquals('const', $errors[0]['keyword']); + $this->assertSame('Value must be equal to the constant value: "PairMatching".', $errors[0]['message']); + } + + public function testConstConstraintViolationWithNullConstant(): void + { + $schema = ['const' => null]; + $data = 'not-null'; + + $errors = $this->validator->validateAgainstJsonSchema($data, $schema); + $this->assertCount(1, $errors); + $this->assertEquals('const', $errors[0]['keyword']); + $this->assertSame('Value must be equal to the constant value: null.', $errors[0]['message']); + } + public function testMinimumConstraintViolation(): void { $schema = ['type' => 'integer', 'minimum' => 10]; From 0a2c4daeafd4e063d0c1292353feaf90ebc33cff Mon Sep 17 00:00:00 2001 From: Christoph Hochholzer Date: Mon, 16 Nov 2026 20:18:01 +0100 Subject: [PATCH 2/3] Address review: drop expected fallback, target 0.11.0 Co-authored-by: Cursor --- src/Server/Capability/Discovery/SchemaValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/Capability/Discovery/SchemaValidator.php b/src/Server/Capability/Discovery/SchemaValidator.php index c5f0afc4..f317731d 100644 --- a/src/Server/Capability/Discovery/SchemaValidator.php +++ b/src/Server/Capability/Discovery/SchemaValidator.php @@ -240,7 +240,7 @@ private function formatValidationError(ValidationError $error): string } break; case 'const': - $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); $message = "Value must be equal to the constant value: {$expected}."; break; case 'minLength': From 644de26bf011af7e8c738f5812bb5e776f4b3a07 Mon Sep 17 00:00:00 2001 From: Christoph Hochholzer Date: Mon, 16 Nov 2026 20:18:14 +0100 Subject: [PATCH 3/3] Address review: changelog entry for 0.11.0 Co-authored-by: Cursor --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edf7dd16..c977af64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,13 @@ -Unreleased ----------- +# Changelog -### Server +All notable changes to `mcp/sdk` will be documented in this file. -* 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.11.0 +------ -# Changelog +### Server -All notable changes to `mcp/sdk` will be documented in this file. +* Fix const validation errors always reporting the expected value as null. 0.10.0 ------