go-sdk/examples/sequentialthinking
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Naoki Sega d570022d03
mcp: add sequential thinking server example (#51)
Add example of implementing mcp on [sequentialthinking
server](https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking),
from [Example Servers](https://modelcontextprotocol.io/examples).

The PR includes dynamic and reflective problem-solving through
structured thinking processes.
The server provides tools for:
- starting thinking sessions
- adding sequential thoughts with step tracking
- revising previous thoughts
- creating alternative reasoning branches
-  reviewing complete processes.

Also, features include thread-safe session management, adaptive planning
that adjusts step counts dynamically.
2025-07-14 08:12:38 -04:00
..
main.go mcp: add sequential thinking server example (#51) 2025-07-14 08:12:38 -04:00
main_test.go mcp: add sequential thinking server example (#51) 2025-07-14 08:12:38 -04:00
README.md mcp: add sequential thinking server example (#51) 2025-07-14 08:12:38 -04:00

Sequential Thinking MCP Server

This example shows a Model Context Protocol (MCP) server that enables dynamic and reflective problem-solving through structured thinking processes. It helps break down complex problems into manageable, sequential thought steps with support for revision and branching.

Features

The server provides three main tools for managing thinking sessions:

1. Start Thinking (start_thinking)

Begins a new sequential thinking session for a complex problem.

Parameters:

  • problem (string): The problem or question to think about
  • sessionId (string, optional): Custom session identifier
  • estimatedSteps (int, optional): Initial estimate of thinking steps needed

2. Continue Thinking (continue_thinking)

Adds the next thought step, revises previous steps, or creates alternative branches.

Parameters:

  • sessionId (string): The thinking session to continue
  • thought (string): The current thought or analysis
  • nextNeeded (bool, optional): Whether another thinking step is needed
  • reviseStep (int, optional): Step number to revise (1-based)
  • createBranch (bool, optional): Create an alternative reasoning path
  • estimatedTotal (int, optional): Update total estimated steps

3. Review Thinking (review_thinking)

Provides a complete review of the thinking process for a session.

Parameters:

  • sessionId (string): The session to review

Resources

Thinking History (thinking://sessions or thinking://{sessionId})

Access thinking session data and history in JSON format.

  • thinking://sessions - List all thinking sessions
  • thinking://{sessionId} - Get specific session details

Core Concepts

Sequential Processing

Problems are broken down into numbered thought steps that build upon each other, maintaining context and allowing for systematic analysis.

Dynamic Revision

Any previous thought step can be revised and updated, with the system tracking which thoughts have been modified.

Alternative Branching

Create alternative reasoning paths to explore different approaches to the same problem, allowing for comparative analysis.

Adaptive Planning

The estimated number of thinking steps can be adjusted dynamically as understanding of the problem evolves.

Running the Server

Standard I/O Mode

go run .

HTTP Mode

go run . -http :8080

Example Usage

Starting a Thinking Session

{
  "method": "tools/call",
  "params": {
    "name": "start_thinking",
    "arguments": {
      "problem": "How should I design a scalable microservices architecture?",
      "sessionId": "architecture_design",
      "estimatedSteps": 8
    }
  }
}

Adding Sequential Thoughts

{
  "method": "tools/call", 
  "params": {
    "name": "continue_thinking",
    "arguments": {
      "sessionId": "architecture_design",
      "thought": "First, I need to identify the core business domains and their boundaries to determine service decomposition."
    }
  }
}

Revising a Previous Step

{
  "method": "tools/call",
  "params": {
    "name": "continue_thinking", 
    "arguments": {
      "sessionId": "architecture_design",
      "thought": "Actually, before identifying domains, I should analyze the current system's pain points and requirements.",
      "reviseStep": 1
    }
  }
}

Creating an Alternative Branch

{
  "method": "tools/call",
  "params": {
    "name": "continue_thinking",
    "arguments": {
      "sessionId": "architecture_design", 
      "thought": "Alternative approach: Start with a monolith-first strategy and extract services gradually.",
      "createBranch": true
    }
  }
}

Completing the Thinking Process

{
  "method": "tools/call",
  "params": {
    "name": "continue_thinking",
    "arguments": {
      "sessionId": "architecture_design",
      "thought": "Based on this analysis, I recommend starting with 3 core services: User Management, Order Processing, and Inventory Management.",
      "nextNeeded": false
    }
  }
}

Reviewing the Complete Process

{
  "method": "tools/call",
  "params": {
    "name": "review_thinking", 
    "arguments": {
      "sessionId": "architecture_design"
    }
  }
}

Session State Management

Each thinking session maintains:

  • Session metadata: ID, problem statement, creation time, current status
  • Thought sequence: Ordered list of thoughts with timestamps and revision history
  • Progress tracking: Current step and estimated total steps
  • Branch relationships: Links to alternative reasoning paths
  • Status management: Active, completed, or paused sessions

Use Cases

Ideal for:

  • Complex problem analysis requiring step-by-step breakdown
  • Design decisions needing systematic evaluation
  • Scenarios where initial scope is unclear and may evolve
  • Problems requiring alternative approach exploration
  • Situations needing detailed reasoning documentation

Examples:

  • Software architecture design
  • Research methodology planning
  • Strategic business decisions
  • Technical troubleshooting
  • Creative problem solving
  • Academic research planning