Repository navigation
Conversation
Zod's toJSONSchema() retains a ~standard prop on its output whose converters re-run the conversion from the original zod schema, so such a document passed to registerTool()/registerPrompt() was re-converted on every tools/list and toolInputSchemaJson() call (modelcontextprotocol#3132). A schema carrying $schema or properties is now recognized as a document and used as-is; live schemas never carry those keywords (zod: def, valibot: entries, ArkType nodes are functions).
🦋 Changeset detectedLatest commit: 26564b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
registerTool()/registerPrompt()schemas (and elicitationrequestedSchema) that are themselves already-converted JSON Schema documents — most prominently the output of zod'stoJSONSchema(), which retains a~standardprop whose converters reference the original zod schema — were re-converted through those converters on everytools/listandtoolInputSchemaJson()call, instead of being used directly (#3132).standardSchemaToJsonSchema()now detects a JSON Schema document by its own$schema/propertieskeywords and uses it as-is, before consulting~standard.jsonSchema. Live Standard Schemas cannot be misdetected this way: zod schemas carrydef, valibot usesentries, and ArkType nodes are functions — none expose$schemaorpropertiesat the root.Fixes #3132
Behavior notes
toJSONSchema()document the advertised schema is now the document itself. For example,additionalProperties: falsethat zod emits is preserved as registered — matching the documentedfromJsonSchema()contract — where the previous re-conversion path dropped it.requestedSchema: a document carrying root-level constraints elicitation does not support (e.g.additionalProperties) now fails with the documented unsupported-constraint error — the same treatment a raw JSON Schema already receives — where the previous re-conversion silently dropped them.$schemanorproperties(e.g. an openapi-3.0-style scalar root) keep the previous best-effort re-conversion behavior.Testing
packages/core-internal/test/util/standardSchema.test.ts: atoJSONSchema()document is used directly with zero converter invocations; a live zod schema still converts exactly once.packages/server/test/server/lazyToolSchemaConversion.test.ts: the reporter's scenario —registerToolwith a pre-converted document, thentoolInputSchemaJson()andtools/list, each with zero converter invocations.core-internalandserversuites pass (the two pre-existing core-internal conformance failures are identical on unpatched main);tsgo, eslint and prettier are clean. The reporter's 1000-tool MRE drops from ~7.8 ms to ~1.9 ms of conversion work.