Skip to content

fix(schema): remove AddNullable from draft2020_12 settings#664

Open
mwotton wants to merge 3 commits intomodelcontextprotocol:mainfrom
mwotton:fix/remove-addnullable
Open

fix(schema): remove AddNullable from draft2020_12 settings#664
mwotton wants to merge 3 commits intomodelcontextprotocol:mainfrom
mwotton:fix/remove-addnullable

Conversation

@mwotton
Copy link

@mwotton mwotton commented Feb 16, 2026

Problem

The schema_for_type() function uses AddNullable::default() as a transform when generating JSON Schema 2020-12 schemas. However, the nullable keyword is an OpenAPI 3.0 extension, not part of JSON Schema 2020-12. This causes validation failures with strict JSON Schema validators.

Solution

Remove the AddNullable transform from the draft2020_12 settings. JSON Schema 2020-12 represents nullable types using:

  • {"type": ["string", "null"]} (type array with null)
  • {"anyOf": [{"type": "string"}, {"type": "null"}]}

Before

An optional string field produced:

{
  "nullable": true,
  "type": "string"
}

After

An optional string field produces:

{
  "type": ["string", "null"]
}

Fixes #663

The `nullable` keyword is an OpenAPI 3.0 extension, not part of
JSON Schema 2020-12. Using AddNullable with draft2020_12 settings
causes validation failures with strict JSON Schema validators.

JSON Schema 2020-12 represents nullable types using:
- {"type": ["string", "null"]} (type array with null)
- {"anyOf": [{"type": "string"}, {"type": "null"}]}

Fixes modelcontextprotocol#663
@github-actions github-actions bot added T-core Core library changes T-handler Handler implementation changes labels Feb 16, 2026
alexhancock
alexhancock previously approved these changes Feb 17, 2026
@alexhancock
Copy link
Contributor

@mwotton Thanks for the fix. test_complex_schema needs a look

@github-actions github-actions bot added the T-test Testing related changes label Feb 18, 2026
@mwotton
Copy link
Author

mwotton commented Feb 18, 2026

Added a second follow-up commit (70011f9) after the test_complex_schema fix because another test had the same stale nullable assumption.

test_tool_macros::test_optional_field_schema_generation_via_macro was still asserting OpenAPI-style nullable: true and explicitly rejecting type: ["string", "null"], which conflicts with Draft 2020-12 output from schema_for_type().

This was not visible in the original CI failure because cargo test --all-features failed fast on test_complex_schema first. The second commit aligns that macro test with Draft 2020-12 behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-handler Handler implementation changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema_for_type uses AddNullable which is non-compliant with JSON Schema 2020-12

2 participants