Skip to content

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

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

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

Conversation

@mwotton

Copy link
Copy Markdown
Contributor

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-actionsgithub-actionsBot 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
Copy Markdown
Contributor

@mwotton Thanks for the fix. test_complex_schema needs a look

@github-actionsgithub-actionsBot added the T-test Testing related changes label Feb 18, 2026
@mwotton

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

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"}]}
Fixesmodelcontextprotocol#663
@mwotton
mwottonforce-pushed the fix/remove-addnullable branch from 70011f9 to 84ac0edCompareFebruary 19, 2026 07:52
@alexhancock
alexhancock merged commit 92b1459 into modelcontextprotocol:mainFeb 19, 2026
11 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Feb 19, 2026
@github-actionsgithub-actionsBot mentioned this pull request Feb 26, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-coreCore library changesT-handlerHandler implementation changesT-testTesting 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

@mwotton@alexhancock@DaleSeo