fix(server): emit object schema for wrapped Zod inputs in tools/list#2159
Open
cogeor wants to merge 4 commits into
Open
fix(server): emit object schema for wrapped Zod inputs in tools/list#2159cogeor wants to merge 4 commits into
cogeor wants to merge 4 commits into
Conversation
…tools/list
normalizeObjectSchema doesn't unwrap ZodEffects / ZodPipeline (.refine,
.superRefine, .transform, .pipe), so the tools/list emission sites were
falling back to {} (input) or dropping outputSchema entirely. validateToolOutput
had the same shape and would crash on safeParseAsync(undefined, ...).
Mirror the fallback validateToolInput already uses: when normalizeObjectSchema
returns undefined, hand the original schema to the converter / parser.
zod-to-json-schema (v3) and z4mini.toJSONSchema (v4) walk those wrappers
natively and drop the refinement body, so the underlying object's properties
come through without us maintaining a wrapper-type list across zod versions.
Widens toJsonSchemaCompat's first parameter from AnyObjectSchema to AnySchema
so it accepts wrapped schemas. Validation against the wrapped schema is
unchanged (still parses the original) — only the JSON Schema emission and
output-validation parsing change.
Fixes modelcontextprotocol#2145
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: b54fd1a The changes in this PR will be included in the next version bump. 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 |
commit: |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ol#2106 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ba016fd to
b54fd1a
Compare
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.
Fixes #2145
Summary
tools/listemitsinputSchema: {}(and silently dropsoutputSchema) for tools whose schema is wrapped inZodEffects/ZodPipeline(.refine,.superRefine,.transform,.pipe), becausenormalizeObjectSchemaonly walks unwrappedZodObjects.Fix: mirror the fallback
validateToolInputalready uses at the two emission sites, and widentoJsonSchemaCompat's first parameter fromAnyObjectSchematoAnySchema. WhennormalizeObjectSchemacan't unwrap, hand the original schema to the converter.zod-to-json-schema(v3) andz4mini.toJSONSchema(v4) walk those wrappers natively and drop the refinement body, so no wrapper-type list is maintained across zod versions. Validation isn't touched.Scope is limited to
tools/listemission.validateToolOutputhas the same broken pattern (safeParseAsync(undefined, ...)crashes on a wrappedoutputSchema) but is already covered by #2106 (#1308), so leaving it alone here to keep ownership clean.Test plan
New
tools/list with wrapped inputSchema (issue #2145)describe block intest/server/mcp.test.ts, parametrized over.refine/.superRefine/.transform/.pipe, under the existingzodTestMatrix(Zod v3 and v4):tools/listemits an inputSchema withtype: "object"andpropertiescontaining both fields.tools/callwith valid args passes; for.refine/.superRefine, args violating the rule still fail validation.inputSchemastill emitsEMPTY_OBJECT_JSON_SCHEMA.outputSchemanow has it emitted intools/list(previously dropped).20 new tests pass (10 per zod version). Typecheck and eslint clean on changed files.