Skip to content

docs(core): document String structuredContent parsing in JsonSchemaValidator - #1111

Merged
Kehrlann merged 1 commit into
modelcontextprotocol:mainfrom
slachiewicz:docs/json-schema-validator-string-contract
Aug 27, 2026
Merged

docs(core): document String structuredContent parsing in JsonSchemaValidator#1111
Kehrlann merged 1 commit into
modelcontextprotocol:mainfrom
slachiewicz:docs/json-schema-validator-string-contract

Conversation

@slachiewicz

Copy link
Copy Markdown
Contributor

What this change does

Adds the input-conversion contract of the validate method to the
JsonSchemaValidator interface Javadoc.

The method treats a String argument as a serialized JSON document and parses
it with readTree before validation. It converts any other type directly with
valueToTree. Both consequences follow for callers:

  • To validate a root-level string, pass quoted JSON text: "\"red\""
    represents the value red.
  • A bare string such as red reaches the parser as an unquoted token, and
    parsing fails with a message that mentions the tool JSON Schema, even though
    the schema is valid.

This contract exists identically in both implementations
(mcp-json-jackson2 at line 70, mcp-json-jackson3 at line 69). The interface
Javadoc did not state it before this change.

Why

During output-schema validation testing, a root-level enum check failed in a
way that pointed at the schema parser rather than at caller-side string
handling. Tracing both default validators revealed the undocumented branch.
Documentation-only changes to a shared SPI carry no migration risk, and the
wording mirrors what the code does so future refactors can update one place.

Testing

No production code changed. Before opening this pull request, I verified:

  • mcp-json-jackson3: DefaultJsonSchemaValidatorTests passes, 40 of 40 tests
  • mcp-json-jackson2: DefaultJsonSchemaValidatorTests passes, 40 of 40 tests
  • spring-javaformat:validate passes for the touched module

Notes for reviewers

If you prefer stronger ergonomics over pure documentation (for example, a
dedicated overload or a clearer parse-failure message), this wording still
stands on its own. Follow-up issues can adjust either message or API without
conflict. Known sharp edge, intentionally out of scope here: the
"Error parsing tool JSON Schema" prefix also appears when the content fails
to parse; existing test assertions pin that string in both modules.

@Kehrlann

Copy link
Copy Markdown
Contributor

Thanks for the docs update.

Fixes #1110

@Kehrlann Kehrlann self-assigned this Aug 27, 2026
@Kehrlann Kehrlann modified the milestone: 2.1.0 Planning Aug 27, 2026
@Kehrlann
Kehrlann self-requested a review August 27, 2026 07:32
@Kehrlann
Kehrlann merged commit b31841e into modelcontextprotocol:main Aug 27, 2026
21 checks passed
@slachiewicz
slachiewicz deleted the docs/json-schema-validator-string-contract branch August 27, 2026 08:17
slachiewicz added a commit to slachiewicz/mcp-java-sdk that referenced this pull request Aug 27, 2026
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.

2 participants