Skip to content

fix(mcp): fall back to z.unknown() for oneOf with non-object variants#3200

Merged
caio-pizzol merged 2 commits intomainfrom
cpolive/fix-mcp-oneof-non-object-fallback
May 7, 2026
Merged

fix(mcp): fall back to z.unknown() for oneOf with non-object variants#3200
caio-pizzol merged 2 commits intomainfrom
cpolive/fix-mcp-oneof-non-object-fallback

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Refines #3192. The looseObject swap fixes object payloads but rejects arrays/booleans/etc. at the zod layer when a union contains non-object variants. Today that hits exactly one field: superdoc_edit.content (oneOf: [{type:"object"}, {type:"array"}]), where the array form (multi-fragment insert/replace) was getting rejected before reaching DocumentApi.

This commit gates the oneOf/anyOf/allOf branch on "every variant declares type: "object"" and falls back to z.unknown() otherwise.

Verified: pnpm --filter @superdoc-dev/mcp run test → 28 pass; pnpm --filter @superdoc-dev/mcp run build → clean.

z.looseObject({}) emits type:"object" which is right for object-only
unions but rejects arrays/booleans/etc. at runtime when the union
includes non-object variants. Gate the looseObject path on "every
variant is type:object" and fall back to z.unknown() otherwise. The
only catalog field this affects today is superdoc_edit.content
(oneOf object|array), where the array form was getting rejected
before reaching DocumentApi.

Adds a unit test that walks the catalog and checks the emitted
type for both branches.
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 7, 2026 21:02
@caio-pizzol caio-pizzol merged commit ed4c717 into main May 7, 2026
12 checks passed
@caio-pizzol caio-pizzol deleted the cpolive/fix-mcp-oneof-non-object-fallback branch May 7, 2026 21:22
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 7, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.73

The release is available on GitHub release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant