Sequential Thinking MCP Server

Sequential Thinking MCP Server

Enables AI assistants to perform structured, step-by-step reasoning through sequential thinking, allowing for thought revisions and alternative reasoning branches. It supports multi-user isolated sessions across Stdio, HTTP, and Cloudflare Workers deployments.

Category
访问服务器

README

Sequential Thinking MVP Server

A production-ready Model Context Protocol (MCP) server that enables AI assistants to perform structured, step-by-step reasoning through sequential thinking. This server facilitates breaking down complex problems into manageable steps, revising thoughts as understanding deepens, and exploring alternative reasoning paths.

✨ Latest Updates (v1.0.0)

All critical security and architectural issues have been fixed!

  • Multi-User Support: Fixed shared state bug - each user now has isolated sessions
  • Modern MCP Protocol: Upgraded to Streamable HTTP transport (MCP 2025-03-26 spec)
  • Cloudflare Workers: Fully functional with Durable Objects for persistent state
  • Comprehensive Validation: All inputs validated with proper error handling
  • Security Hardened: Cryptographically secure session IDs, configurable CORS, rate limiting
  • Memory Management: Automatic session cleanup with TTL to prevent memory leaks
  • Production Ready: Proper error handling, graceful shutdown, health checks

See CODE_REVIEW.md for details on all fixes.

Features

  • Sequential Thinking: Step-by-step problem-solving with numbered thoughts
  • Thought Revision: Ability to revise and refine previous reasoning steps
  • Branching Paths: Explore multiple alternative reasoning approaches
  • Multi-User Session Management: Isolated sessions for concurrent users
  • Input Validation: Comprehensive validation with helpful error messages
  • Rate Limiting: DoS protection (100 requests per 15 minutes per IP)
  • Security: Secure session IDs, configurable CORS, proper authentication headers
  • Multiple Deployment Options:
    • Stdio (for Claude Desktop and local MCP clients)
    • HTTP Server with Streamable HTTP (for remote access)
    • Cloudflare Workers with Durable Objects (for serverless deployment)

Installation

npm install
npm run build

Usage

Option 1: Stdio Mode (Claude Desktop)

Use with Claude Desktop or any MCP-compatible client:

npm start

Or use directly with npx:

npx sequential-thinking-mvp-server

Claude Desktop Configuration

Add to your Claude Desktop config file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "sequential-thinking": {
      "command": "node",
      "args": ["/path/to/sequential-thinking-mvp-server/dist/index.js"]
    }
  }
}

Option 2: HTTP Server Mode

Start the HTTP server for remote access:

npm run start:http

By default, the server runs on port 3000. Set a custom port:

PORT=8080 npm run start:http

Configuration

Environment Variables:

  • PORT: HTTP server port (default: 3000)
  • NODE_ENV: Environment (development/production)
  • ALLOWED_ORIGINS: Comma-separated list of allowed CORS origins (default: all in dev, none in prod)

Example:

PORT=8080 NODE_ENV=production ALLOWED_ORIGINS=https://example.com npm run start:http

Endpoints

  • GET / or /info - Server information
  • GET /health - Health check with session stats
  • POST /mcp - MCP Streamable HTTP endpoint

Session Management

Send a session ID to maintain state across requests:

Via Header:

curl -X POST http://localhost:3000/mcp \
  -H "Content-Type: application/json" \
  -H "x-session-id: your-session-id" \
  -d '{"jsonrpc":"2.0","method":"tools/call","params":{...},"id":1}'

Via Query Parameter:

curl -X POST "http://localhost:3000/mcp?sessionId=your-session-id" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/call","params":{...},"id":1}'

Features

  • Multi-user support: Each session ID gets isolated state
  • Rate limiting: 100 requests per 15 minutes per IP
  • CORS: Configurable via ALLOWED_ORIGINS environment variable
  • Automatic cleanup: Sessions expire after 1 hour of inactivity
  • Health monitoring: /health endpoint shows active sessions and uptime

Option 3: Cloudflare Workers

Deploy to Cloudflare Workers with Durable Objects for serverless, globally distributed deployment with persistent state:

# Development
npm run dev:workers

# Production deployment
npm run deploy:workers

Cloudflare Workers Features

  • Persistent State: Uses Durable Objects for reliable data persistence
  • Global Distribution: Deployed to Cloudflare's edge network
  • Auto-scaling: Handles traffic spikes automatically
  • Zero Maintenance: Fully managed infrastructure

REST API Endpoints

  • GET / or /info - Server information
  • GET /health - Health check
  • POST /think - Add a thought to the sequence
  • GET /sequence - Get current thought sequence
  • POST /reset - Reset session

Example:

curl -X POST https://your-worker.workers.dev/think \
  -H "Content-Type: application/json" \
  -d '{
    "thought": "Analyze the problem requirements",
    "thoughtNumber": 1,
    "totalThoughts": 5,
    "nextThoughtNeeded": true
  }'

Durable Objects Configuration

The server uses Cloudflare Durable Objects to persist state across requests. Each Durable Object instance maintains its own session data, which survives worker restarts and is replicated for reliability.

See wrangler.toml for configuration details.

Tools

1. sequential_thinking

The core tool for step-by-step reasoning.

Required Parameters:

  • thought (string): The current reasoning step
  • nextThoughtNeeded (boolean): Whether more steps are needed
  • thoughtNumber (number): Sequential number of this thought
  • totalThoughts (number): Estimated total thoughts needed

Optional Parameters:

  • isRevision (boolean): Marks this as a revision of a previous thought
  • revisesThought (number): The thought number being revised
  • branchFromThought (number): Starting point for alternative reasoning
  • branchId (string): Identifier for alternative reasoning branch
  • needsMoreThoughts (boolean): Signal to expand total thought count

Example:

{
  "thought": "First, I need to understand the problem requirements",
  "nextThoughtNeeded": true,
  "thoughtNumber": 1,
  "totalThoughts": 5
}

2. get_thought_sequence

Retrieves the complete sequence of thoughts.

Optional Parameters:

  • sessionId (string): Specific session ID (defaults to current)

3. get_thought_branch

Retrieves a specific branch of alternative reasoning.

Required Parameters:

  • branchId (string): The branch identifier

Optional Parameters:

  • sessionId (string): Specific session ID (defaults to current)

4. reset_thinking_session

Starts a new thinking session, clearing the current sequence.

5. get_session_summary

Gets a summary of the current thinking session.

Optional Parameters:

  • sessionId (string): Specific session ID (defaults to current)

Use Cases

Example 1: Basic Sequential Reasoning

User: How would I design a scalable chat application?

AI uses sequential_thinking:
Thought 1: "First, identify the core requirements: real-time messaging, user presence, message history"
Thought 2: "Consider the architecture: need WebSocket connections for real-time, database for persistence"
Thought 3: "Evaluate scalability: load balancing, message queuing, database sharding"
Thought 4: "Design the tech stack: Node.js + Socket.io, Redis for pub/sub, PostgreSQL for storage"
Thought 5: "Plan for growth: horizontal scaling, CDN for assets, monitoring and metrics"

Example 2: Thought Revision

Thought 1: "Use MySQL for the database"
Thought 2: "Implement real-time features with polling"
Thought 3 (revision of 2): "Actually, WebSockets would be more efficient than polling for real-time updates"
Thought 4 (revision of 1): "PostgreSQL would be better than MySQL for JSON support and advanced features"

Example 3: Alternative Reasoning Branches

Main path:
Thought 1: "Consider a monolithic architecture"
Thought 2: "This would be simpler to deploy and maintain"

Branch "microservices":
Thought 1: "Alternatively, use microservices architecture"
Thought 2: "This provides better scalability and team independence"
Thought 3: "Trade-off: increased complexity in deployment and monitoring"

API Examples (Cloudflare Workers / HTTP)

Add a thought

curl -X POST https://your-worker.workers.dev/think \
  -H "Content-Type: application/json" \
  -d '{
    "thought": "First, analyze the requirements",
    "nextThoughtNeeded": true,
    "thoughtNumber": 1,
    "totalThoughts": 5
  }'

Get thought sequence

curl https://your-worker.workers.dev/sequence

Reset session

curl -X POST https://your-worker.workers.dev/reset

Architecture

src/
├── types.ts          # TypeScript type definitions
├── lib.ts            # Core sequential thinking logic
├── index.ts          # Stdio MCP server (Claude Desktop)
├── server-http.ts    # HTTP server with SSE transport
└── worker.ts         # Cloudflare Workers implementation

Development

Watch mode for development:

npm run dev

Build the project:

npm run build

Benefits of Sequential Thinking

  1. Transparency: See the AI's reasoning process step-by-step
  2. Quality: Encourages thorough analysis and consideration
  3. Revision: Allows the AI to reconsider and improve earlier steps
  4. Exploration: Supports exploring multiple solution paths
  5. Accountability: Clear audit trail of the reasoning process

License

MIT

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Related

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选