{"record":{"id":"71fbd3a4bc38b8dd","repo":"CherryHQ/cherry-studio","slug":"invalid-nextthoughtneeded-must-be-a-boolean","errorCode":null,"errorMessage":"Invalid nextThoughtNeeded: must be a boolean","messagePattern":"Invalid nextThoughtNeeded: must be a boolean","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ai/mcp/servers/sequentialthinking.ts","lineNumber":42,"sourceCode":"\nclass SequentialThinkingServer {\n  private thoughtHistory: ThoughtData[] = []\n  private branches: Record<string, ThoughtData[]> = {}\n\n  private validateThoughtData(input: unknown): ThoughtData {\n    const data = input as Record<string, unknown>\n\n    if (!data.thought || typeof data.thought !== 'string') {\n      throw new Error('Invalid thought: must be a string')\n    }\n    if (!data.thoughtNumber || typeof data.thoughtNumber !== 'number') {\n      throw new Error('Invalid thoughtNumber: must be a number')\n    }\n    if (!data.totalThoughts || typeof data.totalThoughts !== 'number') {\n      throw new Error('Invalid totalThoughts: must be a number')\n    }\n    if (typeof data.nextThoughtNeeded !== 'boolean') {\n      throw new Error('Invalid nextThoughtNeeded: must be a boolean')\n    }\n\n    return {\n      thought: data.thought,\n      thoughtNumber: data.thoughtNumber,\n      totalThoughts: data.totalThoughts,\n      nextThoughtNeeded: data.nextThoughtNeeded,\n      isRevision: data.isRevision as boolean | undefined,\n      revisesThought: data.revisesThought as number | undefined,\n      branchFromThought: data.branchFromThought as number | undefined,\n      branchId: data.branchId as string | undefined,\n      needsMoreThoughts: data.needsMoreThoughts as boolean | undefined\n    }\n  }\n\n  private formatThought(thoughtData: ThoughtData): string {\n    const { thoughtNumber, totalThoughts, thought, isRevision, revisesThought, branchFromThought, branchId } =\n      thoughtData","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/sequentialthinking.ts#L24-L60","documentation":"The sequential-thinking server validates `nextThoughtNeeded` as a strict boolean (`typeof === 'boolean'`). Unlike the numeric fields it does NOT use a truthiness guard, so `0`/`1`/`\"true\"` are rejected. It throws a plain `Error`, returned as an `isError: true` tool result (not a thrown exception).","triggerScenarios":"Submitting `nextThoughtNeeded` as a truthy non-boolean: `1`, `0`, `\"true\"`, `\"false\"`, or omitted (undefined fails typeof).","commonSituations":"A JSON serializer coerces booleans to integers/strings; the model emits `\"true\"`; the field is omitted on the final thought.","solutions":["Always pass a real boolean: `{ nextThoughtNeeded: false }` on the final thought.","Ensure your client does not stringify/numericize booleans before sending.","Set `false` only when the chain is truly complete."],"exampleFix":"// before\n{ nextThoughtNeeded: \"true\", ... }\n// after\n{ nextThoughtNeeded: true, ... }","handlingStrategy":"type-guard","validationCode":"function asStrictBoolean(v: unknown): boolean {\n  if (typeof v === 'boolean') return v\n  throw new TypeError(\"'nextThoughtNeeded' must be a strict boolean (not 0/1/'true')\")\n}","typeGuard":"const isStrictBoolean = (v: unknown): v is boolean => typeof v === 'boolean'","tryCatchPattern":"const result = await client.callTool({ name: 'sequentialthinking', arguments: { ...raw, nextThoughtNeeded: asStrictBoolean(raw.nextThoughtNeeded) } })\nif (result.isError) {\n  const body = JSON.parse((result.content[0] as any).text)\n  if (/nextThoughtNeeded/.test(body.error)) {/* pass a real boolean */}\n}","preventionTips":["Ensure your JSON serializer emits real booleans (not 0/1 or 'true'/'false').","Set `false` only when the chain is truly complete.","Validate all four required fields before each call."],"tags":["mcp","validation","sequential-thinking","soft-error","boolean-coercion"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}