sequentialthinking
Analyze complex problems through dynamic thinking steps that adapt and evolve, breaking down tasks into manageable parts while maintaining context for multi-step solutions.
Instructions
A detailed tool for dynamic and reflective problem-solving through thoughts. This tool helps analyze problems through a flexible thinking process that can adapt and evolve. Each thought can build on, question, or revise previous insights as understanding deepens.
When to use this tool:
Breaking down complex problems into steps
Planning and design with room for revision
Analysis that might need course correction
Problems where the full scope might not be clear initially
Problems that require a multi-step solution
Tasks that need to maintain context over multiple steps
Situations where irrelevant information needs to be filtered out
You should:
Start with an initial estimate of needed thoughts, but be ready to adjust
Feel free to question or revise previous thoughts
Don't hesitate to add more thoughts if needed, even at the "end"
Express uncertainty when present
Mark thoughts that revise previous thinking or branch into new paths
Ignore information that is irrelevant to the current step
Generate a solution hypothesis when appropriate
Verify the hypothesis based on the Chain of Thought steps
Repeat the process until satisfied with the solution
Provide a single, ideally correct answer as the final output
Only set next_thought_needed to false when truly done and a satisfactory answer is reached
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thought | Yes | ||
| thoughtNumber | Yes | ||
| totalThoughts | Yes | ||
| nextThoughtNeeded | Yes | ||
| isRevision | No | ||
| revisesThought | No | ||
| branchFromThought | No | ||
| branchId | No | ||
| needsMoreThoughts | No |
Implementation Reference
- The 'processThought' method in 'SequentialThinkingServer' is the core handler that processes the 'sequentialthinking' tool request. It validates the input, stores it, formats it for logging, and returns the processed thought data.
public processThought(input: unknown): ThoughtData { const validatedInput = this.validateThoughtData(input); // Store the thought for future reference this.storeThought(validatedInput); // Log formatted output to console const formattedOutput = this.formatThoughtOutput(validatedInput); console.error(formattedOutput); return validatedInput; } } - The 'validateThoughtData' method defines and validates the expected input structure for the 'sequentialthinking' tool.
private validateThoughtData(input: unknown): ThoughtData { const data = input as Record<string, unknown>; if (!data.thought || typeof data.thought !== 'string') { throw new Error('Invalid thought: must be a string'); } if (!data.thoughtNumber || typeof data.thoughtNumber !== 'number') { throw new Error('Invalid thoughtNumber: must be a number'); } if (!data.totalThoughts || typeof data.totalThoughts !== 'number') { throw new Error('Invalid totalThoughts: must be a number'); } if (typeof data.nextThoughtNeeded !== 'boolean') { throw new Error('Invalid nextThoughtNeeded: must be a boolean'); } // Optional fields const isRevision = data.isRevision !== undefined ? !!data.isRevision : undefined; const revisesThought = data.revisesThought !== undefined && typeof data.revisesThought === 'number' ? data.revisesThought as number : undefined; const branchFromThought = data.branchFromThought !== undefined && typeof data.branchFromThought === 'number' ? data.branchFromThought as number : undefined; const branchId = data.branchId !== undefined && typeof data.branchId === 'string' ? data.branchId as string : undefined; const needsMoreThoughts = data.needsMoreThoughts !== undefined ? !!data.needsMoreThoughts : undefined; return { thought: data.thought as string, thoughtNumber: data.thoughtNumber as number, totalThoughts: data.totalThoughts as number, nextThoughtNeeded: data.nextThoughtNeeded as boolean, isRevision, revisesThought, branchFromThought, branchId, needsMoreThoughts }; } - src/index.ts:1031-1045 (registration)The 'sequentialthinking' tool is handled within the server's 'CallToolRequestSchema' request handler, delegating the logic to 'thinkingServer.processThought'.
server.setRequestHandler(CallToolRequestSchema, async (request) => { switch (request.params.name) { case "sequentialthinking": { const result = thinkingServer.processThought( request.params.arguments ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }