Skip to content

MCP: schema validation errors return a 3 kB raw Zod union dump in error.message while error.issues already holds the clean answer #5951

Description

@Densrt

When an input fails a union-typed schema, the MCP tool returns an error.message that is the raw stringified ZodError: one entry per union branch, all identical, none naming the expected shape. The same response already carries a correctly flattened error.issues — so the useful message is computed, just not used.

This matters more for MCP than for a human CLI user: an agent reads message first, and 3 kB of repeated text is pure context burn for zero information. The CLI's own hand-written errors are excellent by comparison, which is what makes the contrast jarring:

delete-styles input.deletes is not supported. Expected one of: deletions.
update-design-token-styles input.token is not supported. Expected one of: designTokenId, updates. Did you mean designTokenId?

One turn to fix, no ambiguity. The Zod path gives the opposite.

Environment

webstudio@0.282.1, Node v22.23.1, Linux.

Reproduction

Pass a plain string where update-styles expects a StyleValue object — a very natural first attempt, since CSS values are strings everywhere else in the product:

$ webstudio update-styles '{"updates":[{"instanceId":"<id>","property":"color","value":"red"}],"dryRun":true}'

Result:

  • error.message3068 characters, containing "Invalid input: expected object, received string" 15 times (once per branch of the StyleValue union), with "path": [] on every one.
  • error.issues — already correct and minimal:
[{"code": "invalid_type", "path": ["value"],
  "message": "Invalid input: expected object, received string",
  "constraint": "type:object"}]

Nothing in either field says what a StyleValue actually looks like, so the caller still has to go read meta.get_more_tools to learn it is {"type":"keyword","value":"red"}.

Suggestion

  1. Set error.message from the already-computed error.issues (dedup identical branch errors, keep the real path) instead of the raw Zod dump.
  2. For union mismatches, name the expected shape and give one valid example — the tool's mcpExamples already contains it:
    update-styles updates[0].value must be a StyleValue object, received a string.
    Example: {"type":"keyword","value":"red"}
    

That would bring schema errors in line with the quality of the hand-written ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions