Skip to content

Conversation

@olaservo
Copy link
Member

@olaservo olaservo commented Jun 5, 2025

This PR implements SEP-1613, which establishes JSON Schema 2020-12 as the default dialect for embedded schemas within MCP messages.

Summary

Clarifies JSON Schema dialect usage for embedded schemas within MCP messages by establishing 2020-12 as the default dialect and allowing explicit dialect declaration via the $schema field.

Changes

  • Updates specification documentation to specify JSON Schema 2020-12 as default
  • Adds guidance on explicit $schema field usage for alternative dialects
  • Clarifies schema validation requirements for tools with no parameters
  • Updates generated JSON schema files to declare 2020-12 as their meta-schema (patching in the schema generation script since typescript-json-schema only supports draft-07)

Historical Context

Related Issues


Checklist

@jba
Copy link

jba commented Jun 5, 2025

Why is the default the older version of JSON Schema (draft7) instead of the newer one (2020-12)?
I think it should be the latter.

@jviotti
Copy link
Contributor

jviotti commented Jun 5, 2025

Awesome! I made a couple little suggestions, but looks pretty good otherwise 💪🏻

@jviotti
Copy link
Contributor

jviotti commented Jun 5, 2025

This is a good point from @jba though (maybe as a separate PR?)

Why is the default the older version of JSON Schema (draft7) instead of the newer one (2020-12)?I think it should be the latter

Maybe better to default to 2020-12 but still suggest support for previous versions in case some users need it?

olaservo and others added 2 commits June 5, 2025 09:15
Co-authored-by: Juan Cruz Viotti <jv@jviotti.com>
@olaservo olaservo requested a review from evalstate June 5, 2025 16:20
@olaservo
Copy link
Member Author

olaservo commented Jun 5, 2025

Why is the default the older version of JSON Schema (draft7) instead of the newer one (2020-12)? I think it should be the latter.

Using draft-07 as default came from the original discussion where @jviotti recommended this approach. Since that was a general suggestion based on general tooling support, we still need to take into account MCP implementers' pending feedback on what would make the most sense to reduce the most schema validation challenges.

@mikekistler
Copy link
Contributor

In case it benefits anyone else, I'll share this (AI generated) comparison of JSON Schema Draft-7 and Draft-2020-12:

Major Structural Changes

Draft-07 used a single monolithic specification document, while Draft 2020-12 split into modular specifications:

  • Core vocabulary
  • Validation vocabulary
  • Meta-data vocabulary
  • Format assertion vocabulary

Key New Features in Draft 2020-12

Vocabulary System: Introduced a formal vocabulary system allowing custom vocabularies and better extensibility. You can now define which vocabularies your schema uses via $vocabulary.

New Keywords:

  • unevaluatedProperties and unevaluatedItems - Handle properties/items not covered by other schema keywords
  • dependentSchemas and dependentRequired - Replace and expand on Draft-07's dependencies
  • maxContains and minContains - Provide bounds for contains validation
  • prefixItems - Validates array items by position (replaces positional array validation pattern)

Enhanced Conditionals: if/then/else logic works more intuitively with the new unevaluated keywords.

Breaking Changes

Dependencies Restructure: Draft-07's dependencies keyword is split into dependentSchemas and dependentRequired with slightly different semantics.

Array Validation: The way positional array validation works changed significantly with prefixItems replacing the old tuple validation pattern.

Format Behavior: Format validation became vocabulary-dependent rather than implementation-dependent.

Backward Compatibility

Schemas using only basic Draft-07 features will generally work, but schemas using dependencies or complex array validation patterns need updates. The meta-schema identifier changed from http://json-schema.org/draft-07/schema# to https://json-schema.org/draft/2020-12/schema.

Adoption Considerations

Draft 2020-12 offers more powerful validation capabilities and better composability, but Draft-07 still has broader tooling support across languages and platforms. Consider your ecosystem's library support when choosing between versions.

@dsp-ant dsp-ant moved this to In Review in Standards Track Jun 13, 2025
olaservo added 3 commits June 13, 2025 07:46
…no parameters more flexible

- Replace restrictive 'use true for tools with no parameters' guidance
- Provide multiple valid options: true, {}, {type: object}, etc.
- Include example showing how tools can use additional schema keywords
- Addresses comment about recommendation being too restrictive for tools
  that may want to include other keywords beyond properties/required
@Kludex
Copy link
Member

Kludex commented Jun 13, 2025

To make it easier for implementers, I do think it makes more sense to use 2020-12.

Pydantic (the data parsing library we use in the Python SDK) will by default use the version 2020-12 when converting to JSON. Having worked for a long time in the FastAPI ecosystem (which leverages the OpenAPI schema), and the amount of issues that were created because of draft-07, I would suggest we actually use the latest version of the spec by default.

Also, it does add a lot of work to comply to another version.

@bhosmer-ant bhosmer-ant modified the milestone: DRAFT 2025-06-XX Jun 16, 2025
package.json Outdated
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"@olaservo/ts-to-zod": "^5.0.1-fix.1",
Copy link
Member Author

@olaservo olaservo Nov 13, 2025

Choose a reason for hiding this comment

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

Note on this - there appears to be a bug in ts-to-zod that we hit during schema conversion. I opened a PR and let the maintainer know, and in the meantime have pointed this to my own fork,

I also chatted with @jviotti and I think we could always go back to doing a much simpler replacement instead on the draft-07 JSON file, if we don't expect anything truly special to come up in the TS schema in the future. Or alternatively try this for conversion: https://github.com/sourcemeta-research/alterschema

Copy link
Contributor

@jviotti jviotti Nov 13, 2025

Choose a reason for hiding this comment

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

We are also hoping to revamp the https://github.com/sourcemeta-research/alterschema project and make it part of https://github.com/sourcemeta/jsonschema at some point. For context, schema upgrades are typically easy, but there are some complex tricky edge cases on advanced cases that are very hard to handle, which is why the project is still on the sourcemeta-research org.

That said, you are far from hitting those edge cases, as the MCP schema is relatively simple. But hopefully, we have a 100% robust upgrade tool sometime soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given all this ^^ I'm inclined to go with the simpler sed-style approach for this spec release, then make upgrading the TS -> JSON transformation a dependency for future versions. Since we now know what its supposed to look like with the full transformation, we can see that we're not really missing anything by going this route.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dsp-ant I went back to a simpler script for this which just swaps out the schema and definitions for $defs. The other approach ended up being a lot more brittle and complex once it was all said and done. I'm thinking we can continue to improve the tooling here beyond the spec freeze to make it more future-proof. At least this way its easier to trace what's happening.

- Follows the [JSON Schema usage guidelines](/specification/draft/basic#json-schema-usage)
- Defaults to 2020-12 if no `$schema` field is present
- **MUST** be a valid JSON Schema object (not `null`)
- For tools with no parameters, use one of these valid approaches:
Copy link
Member Author

@olaservo olaservo Nov 13, 2025

Choose a reason for hiding this comment

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

We chatted about whether this guidance is really needed here, since technically the schema for MCP already says that it has to be an object.

However, the original GitHub discussions showed widespread confusion around this, especially since JSON Schema 2020-12 would allow boolean schemas like true for no-parameter cases, but MCP requires an object. Given this is an MCP-specific restriction, it seems worth calling out explicitly in the spec verbiage.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dsp-ant I left this extra explanation in, but didn't add anything explicit for other schemas (such as output schemas) because this seemed to be the main need for extra clarification.

localden
localden previously approved these changes Nov 14, 2025
Copy link
Contributor

@localden localden left a comment

Choose a reason for hiding this comment

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

LGTM for spec release.

- `title`: Optional human-readable name of the tool for display purposes.
- `description`: Human-readable description of functionality
- `inputSchema`: JSON Schema defining expected parameters
- Follows the [JSON Schema usage guidelines](/specification/draft/basic#json-schema-usage)
Copy link
Member

Choose a reason for hiding this comment

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

Will this link point to /draft/ now and be edited later to point to /2025-11-24/? How are such links being handled in general?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, do you think its better not to link directly here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like @jonathanhefner might have ideas or thoughts on this? :)

cliffhall
cliffhall previously approved these changes Nov 14, 2025
Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@olaservo olaservo dismissed stale reviews from cliffhall and localden via 0aae433 November 14, 2025 23:00
@localden localden merged commit 8ad0ac7 into modelcontextprotocol:main Nov 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: In Review

Development

Successfully merging this pull request may close these issues.

SEP-1613: Establish JSON Schema 2020-12 as Default Dialect for MCP