SEP-834: Tools inputSchema & outputSchema conform to JSON Schema 2020-12#881
SEP-834: Tools inputSchema & outputSchema conform to JSON Schema 2020-12#881jpmcb wants to merge 1 commit into
inputSchema & outputSchema conform to JSON Schema 2020-12#881Conversation
|
+1 FastMCP just works, with MCP SDK I had a number of issues with schemas because of the confusing server.addTool({
name: "add",
description: "Add two numbers",
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return String(args.a + args.b);
},
})Also, https://modelcontextprotocol.io/docs/concepts/tools provide this example: And then after reading spec you do the same and ... it doesn't work. Very confusing. |
|
Thanks for the reference @olaservo - yes, the overlap makes a ton of sense. I can create a new one that is based on the new SEP and I can include your changes and add you as a co-author on the commit? |
29b8528 to
bec0be2
Compare
|
Hi folks, any chance that this can be merged? |
inputSchema & outputSchema conform to JSON Schema 2020-12inputSchema & outputSchema conform to JSON Schema 2020-12
27b2414 to
d9cdb6a
Compare
Not certain why the broken link checker in which seems to be caused by a |
Mintlify's Markdown parser treats dollar signs as special characters in some cases. The exact cause is not clear, but it might be related to MDX's [LaTeX support](https://mdxjs.com/guides/math/). An example of this behavior can be seen in the build failure for [modelcontextprotocol#881][], in which `npm run check:docs:links` failed to parse `schema.mdx` due to newly introduced `$schema` properties. This commit modifies the `schema.mdx` generator to HTML encode dollar signs, thus preventing such parse errors. [modelcontextprotocol#881]: modelcontextprotocol#881
I believe that is due to the new |
|
+1 this LGTM, and I think the clarity it adds will help mitigate confusion and inconsistency across SDKs. Thanks! Do we expect this will land for the October spec? |
Mintlify's Markdown parser treats dollar signs as special characters in some cases. The exact cause is not clear, but it might be related to MDX's [LaTeX support](https://mdxjs.com/guides/math/). An example of this behavior can be seen in the build failure for [#881][], in which `npm run check:docs:links` failed to parse `schema.mdx` due to newly introduced `$schema` properties. This commit modifies the `schema.mdx` generator to HTML encode dollar signs, thus preventing such parse errors. [#881]: #881
d9cdb6a to
8afdce3
Compare
|
Thanks for the feedback @findleyr - current plan is to solicite more feedback from client and SDK implementers since a few of the core maintainers had concerns about the backwards compatibility of loosening the schema object requirement. But, I 100% agree: to not adopt this would continue to cause confusion across clients, SDKs, and serves leading to drifts in how different implementers work. |
* General guidance on using JSON Schema 2020-12 * Tools `inputSchema` conforms to JSON Schema 2020-12 as "type: object" * Tools `outputSchema` conforms to JSON Schema 2020-12 * Tools `structuredContent` can be any valid JSON (as it coforms to potentially provided `outputSchema`) * Elicitation `requestedSchema` aligns with JSON Schema 2020-12 Co-authored-by: olaservo <olahungerford@gmail.com> Signed-off-by: John McBride <jpmmcbride@gmail.com>
8afdce3 to
0b1c2b5
Compare
|
Adding another vote for conforming to json schema and allowing for a fix for modelcontextprotocol/typescript-sdk#685 . I just had to work the |
|
I 2nd that |
|
@logseq-cldwalker are you saying you want to be able to accept array values as tool arguments? This proposal doesn't change inputSchema to be anything other than an "object", and I agree that doing so would probably cause issues for SDKs. Frankly, I don't necessarily see the need to relax the requirement that |
Yes. This proposes conforming to JSON Schema 2020-12 which also, by proxy, requires us to loosen the In my eyes, you cannot have one without the other. The new spec would be: inputSchema: {
$schema?: string;
[key: string]: any;
};which conforms to JSON schema 2020-12 and allows for inputs like arrays of objects (a very common use case): {
"$schema": "http://json-schema.org/2020-12/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
}
},
"required": ["id"]
}
}Forcing |
|
MCP seems to be repeating history with what OpenAPI did: for years, they also only supported a subset of JSON schema, much to the frustration of the community. They even faced similar pain where they couldn't support arrays of objects:
Eventually, with OpenAPI 3.1 in 2021, they transitioned to fully supporting JSON schema:
https://www.openapis.org/blog/2021/02/18/openapi-specification-3-1-released I would strongly encourage the maintainers to act quickly and fully adopt JSON schema 2020-12 before adoption and misalignment becomes a bigger problem. |
|
I 100% second that suggestion! |
|
Quick update: I wanted to help move this forward this round, but since this requires breaking modifications we wanted to ensure that we have a way to tag in enough client representation as part of the discussion. Despite adding more folks to the Client Implementers group and tagging people in Discord, we still hadn't seen enough engagement there to help validate breaking changes on the timeline needed for spec release. Given this constraint, I've asked the maintainer group to help establish a better engagement model so we can actually have those conversations based on client maintainer feedback instead of general wariness of breaking changes. I think we can give this proposal a much fairer chance in the next round if we can create a better forum for that over the next couple months. |
|
@olaservo How is this different from SEP-1613? And I don't see SEP-834 in the list of accepted SEPs for the 2025-11-25 spec version, so is this something we (SDK maintainers) need to think about right now? |
|
@mikekistler SEP-1613 is making the target default JSON schema dialect explicit, and SEP-834 extends that to remove the limitations on schemas which only support a subset of JSON Schema. SEP-834 isn't currently planned for the next spec release. |
- Update title to match original: "Tools inputSchema & outputSchema Conform to JSON Schema 2020-12" - inputSchema: Keep type: "object" required, but allow additional JSON Schema properties - outputSchema: Fully flexible (any valid JSON Schema) - structuredContent: Any JSON value (unknown) - Update examples to show composition with type: "object" Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Aligns schema.ts with John's original PR modelcontextprotocol#881: - inputSchema: Keep type: "object" required, allow additional properties - outputSchema: Any valid JSON Schema (with $schema field) - Regenerate schema.json and schema.mdx Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Closing this PR as it's tracked in #2106. |
Updates the Author(s) line to credit John McBride (@jpmcb) as the original proposal author (PR modelcontextprotocol#881) and Ola Hungerford (@olaservo) as the current shepherd handling the SEP-1850 conversion and review-feedback revisions. Adds an authorship note above the abstract spelling out the lineage so readers don't conflate the two contributions.
… 2020-12 (#2106) * feat: add SEP draft for full JSON Schema 2020-12 support Add SEP proposing to loosen inputSchema, outputSchema, and structuredContent restrictions to enable full JSON Schema 2020-12 compliance. This allows array responses and schema composition keywords (anyOf, oneOf, allOf). Relates to #834 Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: update author format in SEP-0000 document * fix: update sponsor name format in SEP-0000 document * SEP-834: Loosen schema type restrictions for full JSON Schema 2020-12 support - inputSchema: Allow any valid JSON Schema (enables oneOf/anyOf/allOf at root) - outputSchema: Allow any valid JSON Schema (enables array schemas) - structuredContent: Allow any JSON value (enables array responses) - Update tools.mdx documentation - Add example files demonstrating new capabilities Reference: #834 Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * SEP-834: Update reference implementation with weather forecast demo - Updated inputSchema spec to allow any valid JSON Schema (full 2020-12 compliance) - Replaced get-array-content with get-weather-forecast tool - Weather forecast matches the exact example from Motivation section - Updated npm package references to latest versions: - SDK: @olaservo/mcp-sdk@1.25.2-sep834.3 - Server: @olaservo/mcp-server-everything-sep834@1.1.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update SEP * SEP-2106: Rename file and update header per SEP-1850 - Renamed 0000-json-schema-2020-12.md to 2106-json-schema-2020-12.md - Updated SEP number to 2106 - Updated PR link to #2106 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix prettier formatting * Regenerate schema.mdx for draft spec changes * Align SEP with John's original PR #881 intent - Update title to match original: "Tools inputSchema & outputSchema Conform to JSON Schema 2020-12" - inputSchema: Keep type: "object" required, but allow additional JSON Schema properties - outputSchema: Fully flexible (any valid JSON Schema) - structuredContent: Any JSON value (unknown) - Update examples to show composition with type: "object" Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix inputSchema to require type: "object" per original intent Aligns schema.ts with John's original PR #881: - inputSchema: Keep type: "object" required, allow additional properties - outputSchema: Any valid JSON Schema (with $schema field) - Regenerate schema.json and schema.mdx Co-Authored-By: John McBride <jpmmcbride@gmail.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update SDK reference to 1.25.2-sep834.4 * Update server reference to 1.1.0-sep834.1 * Fix SEP-2106 self-references, examples, and add docs page - Replace "SEP-834" references with "SEP-2106" throughout - Update JSON-serialized content examples to model-friendly summaries - Add cross-references to #1906, TS SDK #1149, and SEP-2200 - Create docs/community/seps/2106-json-schema-2020-12.mdx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Regenerate SEP docs via render-seps script Run `npm run generate:seps` to update index, docs.json, and .mdx to match the CI-expected output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fix Prettier formatting in SEP-2106 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Regenerate schema.mdx from schema.ts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Address review feedback on SEP-2106 - seps: type code blocks now use `unknown` (matches schema definition) - seps: split Backward Compatibility into a directional matrix and document the source-breaking TypeScript widening for consumers - seps: expand Security Implications to require non-local `$ref`s not be auto-dereferenced (SSRF/fetch-DoS) and to bound composition cost - schema.ts: TSDoc on `inputSchema` calls out `type: "object"` root requirement and lists the JSON Schema 2020-12 keywords now allowed - example: add `type: "object"` at the root of the composition inputSchema example so it conforms to the spec - regenerate schema.json, schema.mdx, and SEP MDX * Format docs.json to match render-seps output The render-seps --check job rewrites docs.json via JSON.stringify (one element per array line) and compares raw. A prior prettier pass had collapsed short pages arrays onto single lines, which diverged from what the check expects. * Restore docs/community/seps/2243-http-standardization.mdx Upstream main keeps an orphaned copy of this SEP at the legacy docs/community/seps/ path alongside the canonical docs/seps/ one. Removing it during conflict resolution was unrelated cleanup that doesn't belong in this PR — restoring to match upstream. * Distinguish original author from current shepherd in SEP-2106 Updates the Author(s) line to credit John McBride (@jpmcb) as the original proposal author (PR #881) and Ola Hungerford (@olaservo) as the current shepherd handling the SEP-1850 conversion and review-feedback revisions. Adds an authorship note above the abstract spelling out the lineage so readers don't conflate the two contributions. * Re-fix docs.json after upstream merge The merge of upstream/main re-collapsed short pages arrays onto single lines in docs.json. The render-seps --check job compares docs.json byte-for-byte against JSON.stringify(d, null, 2) output (one element per line), so the collapsed form fails the check. Regenerated docs.json via JSON.stringify to restore the expected format. --------- Co-authored-by: John McBride <jpmmcbride@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Den Delimarsky <den@anthropic.com>
Motivation and Context
TLDR:
inputSchemato be an object withtype: objectand any additional property to support JSON schema Draft 2020-12 and more powerful validation compositions (likeanyOf,oneOf, etc.)outputSchemato fully support JSON Schema 2020-12 since MCP servers may return any valid JSON.structuredContentto support any JSON validated byoutputSchema's JSON Schema.Fixes: #834
Related to and upstream fix for:
outputSchemadoes not fully support JSON Schema inspector#552inputSchemaandoutputSchemado not support JSON Schema typescript-sdk#685allOf,oneOf, etc. inspector#496This RFC loosens the restrictions on tool
inputSchemaandoutputSchemain order to better fully support JSON Schema.The specification currently states:
which is not entierly true:
inputSchemainputSchemais currently expected to be JSON Schema oftype: object. This mostly makes sense since tool calls are expected to be well defined object key / values. This has been more accurately defined in the specification. Any additional property is now also acceptable to allow for much more powerful JSON Schema compositions (like withanyOf,oneOf, etc.)outputSchema&structuredContentoutputSchemais also currently expected to be JSON schema oftype: objectwhich can cause some headaches for MCP servers that return other forms of JSON like arrays of objects:In order to accommodate results that may be structured as an array (or really anything that can be validated by JSON Schema),
outputSchemanow is defined simply as anobject.This impacts
structuredContentwhich was previously restricted to be anobject: but, ifoutputSchemacan validate any JSON, thenstructuredContentmust be able to also be any valid JSON. Thus, it has been loosened tounknown.How Has This Been Tested?
Tested in a weather application I'm building that returns a sorted array of weather hourly objects (see comment: #834 (comment))
Breaking Changes
No updates required. All existing
type: objectbased schemas still work with JSON Schema. Not sure if this belongs indraftor would be better suited for2025-06-18: I leave that to the maintainers.Types of changes
Checklist