Skip to content

Commit d6402ef

Browse files
AmirF194olaservoclaude
authored
fix(sequentialthinking): restore nextThoughtNeeded in the advertised inputSchema required array (#4652)
* fix(sequentialthinking): restore nextThoughtNeeded in the advertised inputSchema required array commit 1cdf806 (#3533) wrapped nextThoughtNeeded in a z.preprocess-based coercedBoolean to fix a real footgun (string "false" coercing to true). zod's toJSONSchema(..., { io: "input" }) treats a z.preprocess()-wrapped field's input type as unknown, so it silently drops that field from the emitted required array, even though it carries no .optional(). A client that builds its call arguments from the advertised schema then omits nextThoughtNeeded and gets a -32602 Invalid params from the runtime validator, which still requires it. Rebuild coercedBoolean as a transform on an explicit z.union([z.boolean(), z.string()]) instead of z.preprocess. The union gives toJSONSchema a concrete input type to report, so nextThoughtNeeded stays in required, while parse behavior (including the case-insensitive string coercion #3533 added) is unchanged. Fixes #4651 * test(sequentialthinking): pin nextThoughtNeeded in required and string coercion Runs against the built server so it checks the schema the SDK emits. Skips when dist/ is absent, matching server-version.test.ts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Wo28CHPXyM3DHoLWvKnCK --------- Co-authored-by: olaservo <olahungerford@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 40a8de8 commit d6402ef

2 files changed

Lines changed: 74 additions & 8 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2+
import { existsSync } from 'node:fs';
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
7+
8+
const packageRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
9+
const distIndexPath = path.join(packageRoot, 'dist', 'index.js');
10+
11+
// Regression coverage for #4651: nextThoughtNeeded must stay in the advertised
12+
// `required` array, and string coercion must keep accepting "True"/"FALSE"
13+
// while rejecting anything else. Runs against the built server so it checks
14+
// the schema the SDK actually emits, not the zod object.
15+
describe.skipIf(!existsSync(distIndexPath))('sequentialthinking input schema', () => {
16+
let client: Client;
17+
18+
beforeAll(async () => {
19+
const transport = new StdioClientTransport({
20+
command: process.execPath,
21+
args: [distIndexPath],
22+
cwd: packageRoot,
23+
stderr: 'pipe',
24+
});
25+
client = new Client({ name: 'input-schema-test', version: '0.0.0' });
26+
await client.connect(transport);
27+
});
28+
29+
afterAll(async () => {
30+
await client?.close();
31+
});
32+
33+
it('advertises nextThoughtNeeded as required', async () => {
34+
const { tools } = await client.listTools();
35+
const tool = tools.find(t => t.name === 'sequentialthinking');
36+
expect(tool).toBeDefined();
37+
expect(tool!.inputSchema.required).toEqual(
38+
expect.arrayContaining(['thought', 'nextThoughtNeeded', 'thoughtNumber', 'totalThoughts'])
39+
);
40+
});
41+
42+
it('rejects a call that omits nextThoughtNeeded', async () => {
43+
const result = await client.callTool({
44+
name: 'sequentialthinking',
45+
arguments: { thought: 't', thoughtNumber: 1, totalThoughts: 1 },
46+
});
47+
expect(result.isError).toBe(true);
48+
expect(JSON.stringify(result.content)).toMatch(/nextThoughtNeeded/);
49+
});
50+
51+
it.each(['True', 'FALSE', 'true', 'false'])('accepts the string %s', async (value) => {
52+
const result = await client.callTool({
53+
name: 'sequentialthinking',
54+
arguments: { thought: 't', nextThoughtNeeded: value, thoughtNumber: 1, totalThoughts: 1 },
55+
});
56+
expect(result.isError).toBeFalsy();
57+
});
58+
59+
it.each(['yes', '', '1'])('rejects the string %j', async (value) => {
60+
const result = await client.callTool({
61+
name: 'sequentialthinking',
62+
arguments: { thought: 't', nextThoughtNeeded: value, thoughtNumber: 1, totalThoughts: 1 },
63+
});
64+
expect(result.isError).toBe(true);
65+
});
66+
});

‎src/sequentialthinking/index.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { z } from "zod";
66
import { SequentialThinkingServer } from './lib.js';
77
import { SERVER_VERSION } from './version.js';
88

9-
/** Safe boolean coercion that correctly handles string "false" */
10-
const coercedBoolean = z.preprocess((val) => {
9+
/** Safe boolean coercion that correctly handles string "false". A union+transform,
10+
* not z.preprocess (whose input type is `unknown`), so toJSONSchema keeps this required. */
11+
const coercedBoolean = z.union([z.boolean(), z.string()]).transform((val, ctx) => {
1112
if (typeof val === "boolean") return val;
12-
if (typeof val === "string") {
13-
if (val.toLowerCase() === "true") return true;
14-
if (val.toLowerCase() === "false") return false;
15-
}
16-
return val;
17-
}, z.boolean());
13+
if (val.toLowerCase() === "true") return true;
14+
if (val.toLowerCase() === "false") return false;
15+
ctx.addIssue({ code: "custom", message: `Expected boolean or "true"/"false" string, received "${val}"` });
16+
return z.NEVER;
17+
});
1818

1919
const server = new McpServer({
2020
name: "sequential-thinking-server",

0 commit comments

Comments
 (0)