mcp-sequentialthinking-tools

repository·main·Indexed 20 days ago

https://github.com/spences10/mcp-sequentialthinking-tools

A lightweight MCP server providing models with a structured scratchpad for sequential reasoning. It supports history tracking, branching, revision metadata, and validation of proposed tool plans against available tools. Features include tools for recording reasoning steps (sequentialthinking_tools), retrieving history (get_thinking_history), and clearing records (clear_thinking_history), along with a pre-defined sequential-thinking-guidance prompt.

Tokens
4K
Snippets
14
Records
21
Agent score
68%

What's inside mcp-sequentialthinking-tools

  1. Configure mcp-sequentialthinking-tools for Claude Desktop

    main

    To use this MCP server with Claude Desktop or other compatible MCP clients, add the following configuration to your claude_desktop_config.json. The server is executed via npx and supports an optional environment variable to control the maximum history size per session.

    Environment Variables:

    • MAX_HISTORY_SIZE: The maximum number of records stored per session. Defaults to 1000.
    {
    	"mcpServers": {
    		"mcp-sequentialthinking-tools": {
    			"command": "npx",
    			"args": ["-y", "mcp-sequentialthinking-tools"],
    			"env": {
    				"MAX_HISTORY_SIZE": "1000"
    			}
    		}
    	}
    }
  2. Retrieve thinking history with get_thinking_history

    main

    Use get_thinking_history to retrieve stored thoughts for a specific session. This is useful for inspecting the reasoning path during long agent runs.

    Parameters:

    • session_id: The ID of the session to retrieve (defaults to default).
    • branch_id: (Optional) A filter to return only thoughts from a specific branch.
    • limit: The maximum number of records to return. Default is 50, maximum is 500.
  3. Use sequentialthinking_tools to record reasoning steps

    main

    The sequentialthinking_tools tool allows a model to record a single thought in a sequential reasoning process. It acts as a scratchpad with support for branching, revision metadata, and tool-plan validation.

    Required Parameters:

    • thought: The current reasoning step text.
    • thought_number: The current step number.
    • total_thoughts: An estimate of total steps; automatically incremented if it is lower than thought_number.
    • next_thought_needed: Boolean indicating if another thought follows.

    Optional Parameters:

    • session_id: The history bucket (defaults to default).
    • is_revision, revises_thought: Metadata for revising previous thoughts.
    • branch_from_thought, branch_id: Metadata for branching the reasoning path.
    • needs_more_thoughts: Boolean flag.
    • available_tools: An array of tool names or { name, description } objects used for validation.
    • recommended_tools: Model-authored tool recommendations. Note: If a tool in recommended_tools is not present in available_tools, the call returns isError: true and the thought is not stored.
    • remaining_steps: A short list of upcoming planned steps.

    Security Note: The server scans thought text and tool descriptions for prompt-injection-like patterns. If redaction occurs, the response includes security_warnings identifying the affected fields.

    {
    	"session_id": "svelte-debug",
    	"thought": "First inspect the route files, then run the failing check.",
    	"thought_number": 1,
    	"total_thoughts": 3,
    	"next_thought_needed": true,
    	"available_tools": ["read", "bash"],
    	"recommended_tools": [
    		{
    			"tool_name": "read",
    			"confidence": 0.9,
    			"rationale": "Need to inspect the relevant files before editing.",
    			"priority": 1
    		}
    	]
    }
  4. Use the sequential-thinking-guidance prompt

    main

    The sequential-thinking-guidance prompt provides instructions to the model on how to use the sequential thinking tools correctly. It emphasizes:

    • Using the tools only for problems benefiting from explicit multi-step reasoning.
    • Keeping thoughts short and revising/branching when evidence changes.
    • Passing available_tools and recommended_tools for validation.
    • Not claiming the server performs the reasoning; the model is the author of the plan.
  5. Define tool references and recommendations

    main

    When interacting with the sequential thinking tools, tools can be referenced either as a simple string (the tool name) or as an object containing a name and an optional description.

    Tool recommendations provide structured guidance for the model, including the tool_name, a confidence score, a rationale for the suggestion, a priority level, suggested_inputs (a record of key-value pairs), and a list of alternatives.

    // Example of a tool_reference object
    const toolRef: tool_reference = {
      name: "fetch_url",
      description: "Retrieves content from a web page"
    };
    
    // Example of a tool_recommendation
    const recommendation: tool_recommendation = {
      tool_name: "search_web",
      confidence: 0.95,
      rationale: "The user is asking about current events.",
      priority: 1,
      suggested_inputs: { query: "latest news" },
      alternatives: ["google_search", "bing_search"]
    };
  6. Interpret thought results and validation issues

    main

    A thought_result is returned after processing a thought. It provides the current state of the session, including session_id, thought_number, total_thoughts, and history_length. It also tracks active branches and any remaining_steps.

    If the input was problematic, the result may contain:

    • invalid_recommendations: An array of validation_issue objects specifying the field and the error message.
    • security_warnings: An array of security_warning objects specifying the field and the offending pattern detected.
    // Example of a thought_result with validation issues
    const result: thought_result = {
      session_id: "sess_123",
      thought_number: 2,
      total_thoughts: 5,
      next_thought_needed: true,
      history_length: 2,
      branches: ["branch_a"],
      invalid_recommendations: [
        { field: "suggested_inputs", message: "Input must be a valid JSON object" }
      ],
      security_warnings: [
        { field: "thought", pattern: "<script>" }
      ]
    };
  7. Configure the thinking_store with max_history_size

    main

    The thinking_store class manages sequential thinking sessions. You can initialize it with an optional thinking_store_options object to control the maximum number of thoughts retained per session.

    If max_history_size is not provided, it defaults to 1000. The value is sanitized to ensure it is at least 1.

    import { thinking_store } from './thinking.js';
    
    const store = new thinking_store({
      max_history_size: 500
    });
  8. Structure thought inputs and records

    main

    The sequential thinking process relies on thought_input and thought_record objects.

    thought_input is used to submit a new step in the reasoning process. It includes the thought text, the current thought_number, the total_thoughts expected, and flags like next_thought_needed or needs_more_thoughts. It also supports branching logic via revises_thought, branch_from_thought, and branch_id. You can also provide available_tools and recommended_tools to guide the model.

    thought_record is the persisted version of a thought, which adds a session_id and a created_at timestamp.

    const input: thought_input = {
      thought: "I need to check the weather in London.",
      thought_number: 1,
      total_thoughts: 5,
      next_thought_needed: true,
      available_tools: ["get_weather"],
      remaining_steps: ["Check temperature", "Check humidity"]
    };