fix(mcp-clients): support JSON Schema union type arrays in the validation hint - #6248
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(mcp-clients): support JSON Schema union type arrays in the validation hint#6248pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
…tion hint MCP tool input schemas can declare a property's type as a union array (e.g. a nullable field as ["string", "null"]) — valid JSON Schema, and the SDK's inputSchema property values are untyped, so nothing stops an upstream tool from sending one. matchesDeclaredType/coerceArgsToSchema only handled a single type string, so a correctly-typed value against a union schema was always flagged as a type mismatch in the repair hint, and coerceArgsToSchema would never recognize the value as already valid.
pedrofrxncx
enabled auto-merge (squash)
August 19, 2026 15:49
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.
Source: bug found auditing
apps/api/src/mcp-clients/validation-hint.tsafter this week's coerce/retry hardening (#6210, #6216, #6242).Why a maintainer wants it: JSON Schema lets a property's
typebe a union array (e.g. a nullable field as["string", "null"]"), and the MCP SDK'sTool.inputSchema.propertiesvalues are untyped custom objects, so nothing stops an upstream server from advertising one.matchesDeclaredTypeandcoerceArgsToSchemaonly ever compared against a single type string, so any correctly-typed value against a union-typed property was always reported as "Wrong type" in the repair hint sent back to the agent — actively misleading it about what's actually wrong — andcoerceArgsToSchemacould never recognize a string value as already valid for such a property.Failure scenario: a tool declares
note: { type: ["string", "null"] }. The agent sends a correct string value but the call still fails validation for an unrelated reason (e.g. a missing required field). The generated hint falsely saysnote (expected string,null, got string)even thoughnotewas fine, confusing the retry. Regression test:validation-hint.test.ts— "does not flag a nullable union type's matching member as wrong-typed" / "flags a value matching none of a union type's members" / "coerces against a union type, skipping when string is already a member".Verify:
bun test apps/api/src/mcp-clients/validation-hint.test.ts(19 pass).Checks run locally:
bun run fmt,cd apps/api && bunx tsc --noEmit(clean),bunx oxlint apps/api/src/mcp-clients/validation-hint.ts apps/api/src/mcp-clients/validation-hint.test.ts(0 warnings/errors), targeted test file above. Full CI validates the rest.Summary by cubic
Fixes validation and repair hints for tools that declare JSON Schema union types (e.g., ["string", "null"]). Previously, union-typed properties were always flagged as wrong-typed; now we correctly match and coerce across union members.
typeasstring | string[]and normalizes to an array.matchesDeclaredTypematches any union member (keeps special handling for"integer").coerceArgsToSchematries coercion across union members and skips coercion when"string"is already allowed.buildValidationHintformats expected union types asa|band no longer flags values that match a union member.Written for commit 1c2adfb. Summary will update on new commits.