Skip to main content
Glama
by fmangot

sequential_thinking

Break down complex problems into manageable steps for structured analysis. Track reasoning progress, revise previous steps, and explore alternative paths to solve challenging problems systematically.

Instructions

Facilitates a detailed, step-by-step thinking process for problem-solving and analysis. Break down complex problems into manageable steps, revise and refine thoughts as understanding deepens, and branch into alternative paths of reasoning.

Input Schema

NameRequiredDescriptionDefault
thoughtYesThe current reasoning step or thought in the sequence
nextThoughtNeededYesIndicates whether additional reasoning steps are required after this one
thoughtNumberYesThe sequential number of this thought (e.g., 1, 2, 3...)
totalThoughtsYesEstimated total number of thoughts needed to complete the reasoning
isRevisionNoMarks this thought as a reconsideration or refinement of a previous step
revisesThoughtNoThe thought number being revised (required if isRevision is true)
branchFromThoughtNoThe thought number from which this alternative reasoning path branches
branchIdNoUnique identifier for this alternative reasoning branch
needsMoreThoughtsNoSignals that the total number of thoughts needs to be expanded

Input Schema (JSON Schema)

{ "properties": { "branchFromThought": { "description": "The thought number from which this alternative reasoning path branches", "type": "number" }, "branchId": { "description": "Unique identifier for this alternative reasoning branch", "type": "string" }, "isRevision": { "description": "Marks this thought as a reconsideration or refinement of a previous step", "type": "boolean" }, "needsMoreThoughts": { "description": "Signals that the total number of thoughts needs to be expanded", "type": "boolean" }, "nextThoughtNeeded": { "description": "Indicates whether additional reasoning steps are required after this one", "type": "boolean" }, "revisesThought": { "description": "The thought number being revised (required if isRevision is true)", "type": "number" }, "thought": { "description": "The current reasoning step or thought in the sequence", "type": "string" }, "thoughtNumber": { "description": "The sequential number of this thought (e.g., 1, 2, 3...)", "type": "number" }, "totalThoughts": { "description": "Estimated total number of thoughts needed to complete the reasoning", "type": "number" } }, "required": [ "thought", "nextThoughtNeeded", "thoughtNumber", "totalThoughts" ], "type": "object" }

Implementation Reference

  • Specific handler logic for the 'sequential_thinking' tool call, which invokes SequentialThinkingManager.addThought and returns the result as JSON.
    case 'sequential_thinking': { const input = args as ThoughtInput; const result = thinkingManager.addThought(input); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • JSON schema definition for the 'sequential_thinking' tool inputs and metadata.
    export const SEQUENTIAL_THINKING_TOOL: Tool = { name: 'sequential_thinking', description: 'Facilitates a detailed, step-by-step thinking process for problem-solving and analysis. Break down complex problems into manageable steps, revise and refine thoughts as understanding deepens, and branch into alternative paths of reasoning.', inputSchema: { type: 'object', properties: { thought: { type: 'string', description: 'The current reasoning step or thought in the sequence', }, nextThoughtNeeded: { type: 'boolean', description: 'Indicates whether additional reasoning steps are required after this one', }, thoughtNumber: { type: 'number', description: 'The sequential number of this thought (e.g., 1, 2, 3...)', }, totalThoughts: { type: 'number', description: 'Estimated total number of thoughts needed to complete the reasoning', }, isRevision: { type: 'boolean', description: 'Marks this thought as a reconsideration or refinement of a previous step', }, revisesThought: { type: 'number', description: 'The thought number being revised (required if isRevision is true)', }, branchFromThought: { type: 'number', description: 'The thought number from which this alternative reasoning path branches', }, branchId: { type: 'string', description: 'Unique identifier for this alternative reasoning branch', }, needsMoreThoughts: { type: 'boolean', description: 'Signals that the total number of thoughts needs to be expanded', }, }, required: ['thought', 'nextThoughtNeeded', 'thoughtNumber', 'totalThoughts'], }, };
  • src/index.ts:32-39 (registration)
    MCP server request handler registration for listing tools (includes sequential_thinking via ALL_TOOLS) and handling tool calls.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: ALL_TOOLS }; }); // Handle tool calls server.setRequestHandler(CallToolRequestSchema, async (request) => { return handleToolCall(request.params, thinkingManager); });
  • Core implementation of adding a thought to the sequence, including validation, branching, revisions, session management, and response generation.
    public addThought(input: ThoughtInput, sessionId?: string): ThoughtResponse { // Validate input validateThoughtInput(input); const sid = sessionId || this.currentSessionId; let session = this.sessions.get(sid); if (!session) { this.initializeSession(sid); session = this.sessions.get(sid)!; } const storedThought: StoredThought = { ...input, timestamp: Date.now(), sessionId: sid, }; // Handle branching if (input.branchId && input.branchFromThought !== undefined) { let branchThoughts = session.branches.get(input.branchId); if (!branchThoughts) { branchThoughts = []; session.branches.set(input.branchId, branchThoughts); } branchThoughts.push(storedThought); } else { // Regular thought in main sequence session.thoughts.push(storedThought); } session.updatedAt = Date.now(); // Build response message let message = `Thought ${input.thoughtNumber}`; if (input.isRevision && input.revisesThought !== undefined) { message += ` (revising thought ${input.revisesThought})`; } if (input.branchId) { message += ` [branch: ${input.branchId}]`; } message += `: ${input.thought}`; return { success: true, thoughtNumber: input.thoughtNumber, message, sequence: session.thoughts, totalThoughts: input.totalThoughts, }; }
  • Shared handler function that routes tool calls to the appropriate logic, providing the SequentialThinkingManager instance.
    export async function handleToolCall( params: { name: string; arguments?: unknown }, thinkingManager: SequentialThinkingManager ) { const { name, arguments: args = {} } = params; try { switch (name) { case 'sequential_thinking': { const input = args as ThoughtInput; const result = thinkingManager.addThought(input); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } case 'get_thought_sequence': { const { sessionId } = args as { sessionId?: string }; const sequence = thinkingManager.getSequence(sessionId); return { content: [ { type: 'text', text: JSON.stringify( { sessionId: sessionId || thinkingManager.getCurrentSessionId(), thoughtCount: sequence.length, thoughts: sequence, }, null, 2 ), },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fmangot/Mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server