Skip to content

fix(sequential-thinking): preserve nextThoughtNeeded in required schema fields - #4695

Open
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/sequentialthinking-required-next-thought
Open

fix(sequential-thinking): preserve nextThoughtNeeded in required schema fields#4695
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/sequentialthinking-required-next-thought

Conversation

@AbhiPra24

Copy link
Copy Markdown

Description

Fixes #4651.

In #3533, boolean parameters in src/sequentialthinking/index.ts were switched to use z.preprocess() to support string booleans from LLMs. However, z.preprocess() wraps the underlying schema into a pipeline accepting unknown, causing Zod's JSON schema generation (z.toJSONSchema) to omit nextThoughtNeeded from the required properties list.

This caused MCP clients constructing calls based strictly on the declared required tool schema to omit nextThoughtNeeded and receive validation error -32602 at runtime.

This PR fixes the issue by replacing z.preprocess() with z.union([z.boolean(), z.string().transform(...)]). This preserves case-insensitive string-to-boolean coercion while correctly emitting nextThoughtNeeded in the tool's inputSchema.required array.

Changes

  • Update coercedBoolean definition in src/sequentialthinking/index.ts to z.union.
  • Add unit tests in src/sequentialthinking/__tests__/schema.test.ts verifying input schema generation, required fields, and boolean/string parsing.

Verification

  • Ran npm test and npm run build in src/sequentialthinking. All 18 tests pass with 100% coverage on schema logic.

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.

sequential-thinking: nextThoughtNeeded missing from inputSchema.required but required at runtime (regression from #3533)

1 participant