Skip to content

fix(sequential-thinking): use z.coerce for number and boolean params#3533

Open
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3428-sequential-thinking-coerce
Open

fix(sequential-thinking): use z.coerce for number and boolean params#3533
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3428-sequential-thinking-coerce

Conversation

@nielskaspers
Copy link
Contributor

Summary

LLM clients intermittently send thoughtNumber, totalThoughts, and boolean fields as strings instead of native JSON types, causing Zod validation errors. This replaces strict z.number() and z.boolean() with z.coerce.number() and z.coerce.boolean() in the inputSchema to gracefully accept both formats.

Issue

Fixes #3428

Changes

  • Replace z.number() with z.coerce.number() for thoughtNumber, totalThoughts, revisesThought, and branchFromThought
  • Replace z.boolean() with z.coerce.boolean() for nextThoughtNeeded, isRevision, and needsMoreThoughts

Testing

  • z.coerce.number() accepts both 1 and "1", coercing strings to numbers
  • z.coerce.boolean() accepts both true and "true", coercing strings to booleans
  • All .int().min(1) and .optional() constraints are preserved
  • Existing tests pass unchanged since they already use native types

LLM clients (Claude Code, Augment.AI, etc.) intermittently send
thoughtNumber, totalThoughts, and nextThoughtNeeded as strings
instead of native JSON types. Using z.coerce gracefully handles
both string and native inputs without breaking existing behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sequential-thinking): Use z.coerce for inputSchema to handle string-typed parameters from LLM clients

1 participant