Skip to content

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Oct 12, 2025

Summary

Fix JSON Schema validation to comply with the official JSON Schema specification by allowing additional properties by default when not explicitly specified in schemas. Also adds support for String input in the validate() method.

  • Remove automatic additionalProperties: false injection (JSON Schema spec compliance)
  • Support String input for structuredContent in validate() method
  • Move tests to mcp-json-jackson2 module with proper dependencies
  • Replace wildcard imports with explicit imports

Complies with JSON Schema Test Suite:
https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/15e4505/tests/draft2020-12/additionalProperties.json#L112

Fixes #584

Motivation and Context

This fix ensures the SDK behaves correctly according to the JSON Schema specification, preventing false validation failures and improving interoperability with other JSON Schema validators.

Additionally, the validator now supports String input for structuredContent, allowing direct JSON string validation without requiring pre-parsing.

Breaking Changes

YES - This is a breaking change.

Users who relied on the previous non-compliant behavior (additional properties rejected by default) will need to update their schemas to explicitly set "additionalProperties": false if they want to disallow additional properties.

Migration guide:

// Before (implicit rejection of additional properties)
{
  "type": "object",
  "properties": {
    "name": {"type": "string"}
  }
}

// After (explicit rejection required)
{
  "type": "object",
  "properties": {
    "name": {"type": "string"}
  },
  "additionalProperties": false
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

- Remove automatic additionalProperties: false injection (JSON Schema spec compliance)
- Support String input for structuredContent in validate() method
- Move tests to mcp-json-jackson2 module with proper dependencies
- Replace wildcard imports with explicit imports

Complies with JSON Schema Test Suite:
https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/15e4505/tests/draft2020-12/additionalProperties.json\#L112

Fixes modelcontextprotocol#584

BREAKING CHANGE: Additional properties now allowed by default when not explicitly specified.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Copy link
Contributor

@Kehrlann Kehrlann left a comment

Choose a reason for hiding this comment

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

👍

@tzolov tzolov merged commit 2ee5853 into modelcontextprotocol:main Oct 14, 2025
1 of 2 checks passed
tzolov added a commit that referenced this pull request Oct 14, 2025
- Remove automatic additionalProperties: false injection (JSON Schema spec compliance)
- Support String input for structuredContent in validate() method
- Move tests to mcp-json-jackson2 module with proper dependencies
- Replace wildcard imports with explicit imports

Complies with JSON Schema Test Suite:
https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/15e4505/tests/draft2020-12/additionalProperties.json\#L112

Fixes #584

BREAKING CHANGE: Additional properties now allowed by default when not explicitly specified.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

additionalProperties is forced to false when missing, but default should be allowed (JSON Schema 2020-12)

2 participants