Skip to content

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

Merged
alexhancock merged 3 commits intomodelcontextprotocol:mainfrom
mwotton:fix/remove-addnullable
Feb 19, 2026
Merged

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

Conversation

@mwotton
Copy link
Contributor

@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

@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
Contributor 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.

@DaleSeo
Copy link
Contributor

DaleSeo commented Feb 18, 2026

Hey @mwotton, thanks for the fix! The code change looks good.

The CI failures aren't related to your changes. All five failing checks hit the same compilation error:

error[E0004]: non-exhaustive patterns: `Some(Protocol::Tlsv13)` not covered  
--> native-tls-0.2.17/src/imp/openssl.rs:61:22

This happened because your branch is based on an older main that still used reqwest 0.12, which depends on native-tls. Since then, PR #669 upgraded to reqwest 0.13, which uses rustls by default and doesn't pull in native-tls, so the main CI is green now.

To fix the CI, please rebase your branch onto the latest main. I think that should resolve all five failures. The code changes themselves look correct.

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
@mwotton mwotton force-pushed the fix/remove-addnullable branch from 70011f9 to 84ac0ed Compare February 19, 2026 07:52
@alexhancock alexhancock merged commit 92b1459 into modelcontextprotocol:main Feb 19, 2026
11 checks passed
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

3 participants

Comments