使用说明
MCP顺序思维服务器
MCP服务器实现,通过结构化思维过程提供动态和反思性问题解决的工具。
特性
- 将复杂问题分解为可管理的步骤
- 随着理解的加深,修改和完善想法
- 分支到其他推理路径
- 动态调整想法总数
- 生成并验证解决方案假设
技术栈
- FastMCP -MCP服务器框架
- python -核心语言
- 紫外线 -包管理
可用工具
| 工具 | 说明 |
|---|---|
create_thought_chain |
启动新的推理链 |
add_thought |
为现有链添加一个想法 |
revise_thought |
更新现有想法 |
delete_thought |
从链中删除一个想法 |
get_chain |
检索思维链 |
summarize_chain |
获取推理摘要 |
branch_chain |
创建备选推理路径 |
add_hypothesis |
提出解决方案假设 |
verify_hypothesis |
标记假设已验证/被拒绝 |
list_chains |
列出所有活动链 |
安装
# Clone the repository
git clone https://github.com/ShawnKyzer/mcp-sequential-thinking.git
cd mcp-sequential-thinking
# Install dependencies with uv
uv sync
# Install with dev dependencies for testing
uv sync --all-extras
用法
运行服务器
# Run with stdio transport (default, for local MCP clients)
uv run mcp-sequential-thinking
# Or using the FastMCP CLI
uv run fastmcp run src/mcp_sequential_thinking/server.py:mcp
# Run with HTTP transport for remote access
uv run fastmcp run src/mcp_sequential_thinking/server.py:mcp --transport http --port 8000
Claude桌面配置
添加到您的Claude桌面配置(~/.config/claude/claude_desktop_config.json):
{
"mcpServers": {
"sequential-thinking": {
"command": "uv",
"args": ["run", "--directory", "/path/to/mcp-sequential-thinking", "mcp-sequential-thinking"]
}
}
}
程序化使用
from mcp_sequential_thinking import create_server, ThoughtManager, InMemoryThoughtChainStore
# Create a server with custom configuration
store = InMemoryThoughtChainStore()
server = create_server(name="My Thinking Server", store=store)
# Run the server
server.run()
发展
运行测试
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run with coverage
uv run pytest --cov=mcp_sequential_thinking
# Run specific test file
uv run pytest tests/test_thought_manager.py -v
代码质量
该项目遵循Python最佳实践,包括:
- 坚实的原则:单一职责、开放/封闭、Liskov替换、接口隔离、依赖倒置
- 类型提示:贯穿全文的完整类型注释
- Pydantic模型:经过验证的数据结构
- 异步/等待:非阻塞I/O操作
- 依赖注入:灵活的组件组成
项目结构
mcp-sequential-thinking/
├── pyproject.toml
├── README.md
├── src/
│ └── mcp_sequential_thinking/
│ ├── __init__.py
│ ├── server.py
│ ├── thought_manager.py
│ ├── models.py
│ └── store/
│ ├── __init__.py
│ ├── base.py
│ └── memory.py
├── tests/
└── design/
└── ARCHITECTURE.md
用例
1.复杂代码架构决策
在设计新的系统架构时,人工智能可以使用顺序思维来:
Chain: "Microservices vs Monolith Decision"
├── Step 1: Analyze current team size and expertise
├── Step 2: Evaluate scalability requirements
├── Step 3: Consider deployment complexity
├── Step 4: Assess cost implications
├── Hypothesis: "Microservices better for this use case"
├── Step 5: Identify potential challenges
└── Verify: Hypothesis confirmed with evidence
示例提示: “帮助我为我们的电子商务平台在微服务和单体之间做出选择”
2.调试复杂问题
将调试分解为系统步骤:
Chain: "Memory Leak Investigation"
├── Step 1: Identify symptoms (high memory usage over time)
├── Step 2: Review recent code changes
├── Step 3: Analyze heap dumps
│ └── Branch: "Investigate connection pool"
├── Step 4: Narrow down to specific module
├── Hypothesis: "Unclosed database connections"
├── Step 5: Write test to reproduce
└── Verify: Hypothesis confirmed - fix applied
示例提示: “我们的Node.js应用程序在生产环境中泄漏内存,请帮我调查”
3.算法设计与优化
有条不紊地进行算法开发:
Chain: "Search Algorithm Optimization"
├── Step 1: Define problem constraints (1M records, <100ms)
├── Step 2: Evaluate brute force approach - O(n)
├── Step 3: Consider binary search - O(log n)
│ └── Branch: "What if data is unsorted?"
├── Step 4: Explore hash-based approach - O(1)
├── Hypothesis: "Hash map with caching optimal"
├── Step 5: Analyze memory trade-offs
├── Revise Step 4: Add LRU eviction for memory bounds
└── Verify: Benchmarks confirm 50ms average
示例提示: “使用自动补全功能为我们的产品目录设计高效搜索”
4.安全漏洞评估
系统安全分析:
Chain: "API Security Audit"
├── Step 1: Map all API endpoints
├── Step 2: Check authentication mechanisms
├── Step 3: Analyze authorization logic
├── Hypothesis: "IDOR vulnerability in /users/{id}"
├── Step 4: Test hypothesis with different user contexts
├── Step 5: Review rate limiting
│ └── Branch: "Check for enumeration attacks"
├── Verify: IDOR confirmed - recommend fix
└── Step 6: Document findings and remediation
示例提示: “针对安全漏洞审核我们的REST API”
5.数据库模式设计
迭代模式细化:
Chain: "E-commerce Database Schema"
├── Step 1: Identify core entities (User, Product, Order)
├── Step 2: Define relationships
├── Step 3: Normalize to 3NF
├── Hypothesis: "Denormalize order_items for read performance"
├── Step 4: Consider query patterns
│ └── Branch: "Evaluate NoSQL for product catalog"
├── Revise Step 3: Add strategic denormalization
├── Step 5: Plan indexing strategy
└── Verify: Query benchmarks meet SLA
示例提示: “为多供应商市场设计数据库模式”
6.代码审查和重构
结构化代码改进:
Chain: "Legacy Code Refactoring"
├── Step 1: Understand current functionality
├── Step 2: Identify code smells (God class, 2000 lines)
├── Step 3: Map dependencies
├── Hypothesis: "Extract 3 service classes"
├── Step 4: Plan incremental refactoring steps
│ └── Branch: "Consider strangler fig pattern"
├── Step 5: Write tests for current behavior
├── Step 6: Execute refactoring with test coverage
└── Verify: All tests pass, complexity reduced 60%
示例提示: “帮助我重构这个2000行UserService类”
7.技术决策文件
创建可审计的决策记录:
Chain: "Frontend Framework Selection"
├── Step 1: Define requirements (SSR, TypeScript, team skills)
├── Step 2: Evaluate React/Next.js
├── Step 3: Evaluate Vue/Nuxt
├── Step 4: Evaluate Svelte/SvelteKit
│ └── Branch: "Consider learning curve impact"
├── Hypothesis: "Next.js best fits requirements"
├── Step 5: Prototype critical features in Next.js
├── Step 6: Gather team feedback
└── Verify: Team consensus achieved, Next.js selected
示例提示: “帮助我们为仪表板选择前端框架”
8.事件响应和RCA
根本原因分析工作流程:
Chain: "Production Outage RCA"
├── Step 1: Document timeline of events
├── Step 2: Identify affected systems
├── Step 3: Analyze logs and metrics
├── Hypothesis: "Database connection pool exhausted"
├── Step 4: Correlate with recent deployments
│ └── Branch: "Check for query performance regression"
├── Step 5: Identify contributing factors
├── Verify: Connection leak in new feature confirmed
└── Step 6: Document preventive measures
示例提示: “帮我对昨晚的停电进行根因分析”
运作原理
- 人工智能创造思维链 在处理复杂问题时
- 每个推理步骤都被记录下来 带有时间戳和元数据
- 思想可以修正 随着理解的加深
- 分支机构探索替代方案 而不会失去主线
- 提出并验证了假设 有证据
- 完整的审计跟踪 可供复习和学习
许可证
麻省理工学院