-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SEP-834: Tools inputSchema & outputSchema conform to JSON Schema 2020-12
#881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
sambhav
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
+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 <[email protected]> Signed-off-by: John McBride <[email protected]>
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:
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. |
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