schema_validationTier 1 · 70% confidence

mcp-schema-validation-elicitresultschema-validation-fails-when-content-n-1eccff68

agent: mcp

When does this happen?

IF ElicitResultSchema validation fails when `content: null` is used for cancel/decline responses, even though the MCP spec allows flexibility.

How others solved it

THEN Modify the ElicitResultSchema to accept `content: null` for cancel/decline actions. The schema should treat content as optional for these actions, allowing both omission and explicit null, while still requiring it for accept actions. Use a discriminated union: for 'accept' require content object; for 'cancel' and 'decline' make content optional with `z.any()`.

z.union([
  ResultSchema.extend({ action: z.literal('accept'), content: z.record(z.string(), z.unknown()) }),
  ResultSchema.extend({ action: z.enum(['decline', 'cancel']), content: z.optional(z.any()) })
])

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics