使用说明
UltraThink MCP服务器
用于顺序思维和问题解决的Python MCP服务器
增强的Python端口 的 顺序思维MCP服务器 通过Anthropic。 添加时保持完全兼容性 信心评分, 自动分配的思维编号,以及 多会话支持.
[!提示] 使用克劳德代码? 安装 UltraThink插件 无缝集成-无需设置MCP服务器!
# Via terminal claude plugin marketplace add husniadil/ekstend claude plugin install ultrathink@ekstend # Or interactively in Claude Code /plugin marketplace add husniadil/ekstend /plugin install ultrathink@ekstend
[!注意] 元:此MCP服务器是使用UltraThink本身迭代构建的,这是该工具分解复杂问题、管理架构决策和维护开发会话上下文能力的一个实际例子。
特性
- UltraThink:将复杂问题分解为可管理的步骤
- 动态调整:随着理解的加深,修改和完善想法
- 分支探索其他推理路径
- 信心评分:显式不确定性跟踪(0.0-1.0标度)
- 自动调整:如果需要,自动调整总想法
- 多会话支持:使用会话ID管理多个并发思考会话
- 格式化测井:彩色终端输出,格式丰富(可禁用)
- 100%测试覆盖率:具有完整代码覆盖率的全面测试套件
- 类型安全:对生产代码进行完整的mypy严格模式类型检查
- 简单分层架构:与模型、服务和接口层进行干净的分离
安装
快速安装(推荐)
直接从GitHub使用uvx运行(无需安装):
uvx --from git+https://github.com/husniadil/ultrathink ultrathink
开发设置
对于当地发展:
# Clone the repository
git clone https://github.com/husniadil/ultrathink.git
cd ultrathink
# Install all dependencies (including dev dependencies)
uv sync
用法
任务命令(类似npm)
# List all available tasks
uv run task --list
# Run the server
uv run task run
# Run tests with coverage
uv run task test
# Run tests without coverage (quick)
uv run task test-quick
# Run the test client
uv run task client
# Format code (ruff + prettier)
uv run task format
# Lint code
uv run task lint
# Type check with mypy
uv run task typecheck
# Clean cache files
uv run task clean
直接命令(替代)
对于没有任务运行器的直接执行:
# Run the server directly
uv run ultrathink
# Run the test client directly
uv run python examples/client.py
注: 对于测试、linting和格式化,最好使用 uv run task 上面显示的命令。
工具:超薄
该服务器通过结构化思维为动态和反思性问题解决提供了一个单一的工具。
参数
必修的:
thought(str):你目前的思考步骤total_thoughts(int):估计所需的总想法数(>=1)
可选:
thought_number(int):当前思想编号-如果省略,则按顺序自动分配(1、2、3…),或为分支/语义控制提供明确的编号next_thought_needed(bool):是否需要另一个思考步骤。自动分配为thought_number < total_thoughts如果省略。显式设置以覆盖默认行为session_id(str):用于管理多个思考会话的会话标识符(无=创建新会话,提供ID以继续会话)is_revision(bool):这是否改变了之前的想法revises_thought(int):正在重新考虑哪个思维数branch_from_thought(int):分支点思想数branch_id(str):分支标识符needs_more_thoughts(bool):如果需要更多思考confidence(浮动):置信水平(0.0-1.0,例如,0.7表示70%的置信度)uncertainty_notes(str):对这一想法的怀疑或担忧的可选解释outcome(str):这个想法的结果是什么assumptions(列表[假设]):在这个想法中做出的假设(id、文本、置信度、批判性、可验证性)depends_on_assumptions(list[str]):这个想法所依赖的假设ID(例如,[“A1”,“A2”])invalidates_assumptions(list[str]):假设ID被证明为假(例如,[“A3”])
响应
返回一个JSON对象:
session_id:用于继续的会话标识符thought_number:当前思想数total_thoughts:总想法(必要时自动调整)next_thought_needed:是否需要更多思考branches:分支ID列表thought_history_length:本次会议处理的想法数量confidence:此想法的置信度(0.0-1.0,可选)uncertainty_notes:对疑问或疑虑的解释(可选)outcome:已实现或预期的目标(可选)all_assumptions:本次会议中跟踪的所有假设(按ID键入)risky_assumptions:风险假设的ID(关键+低置信度+未经证实)falsified_assumptions:假设的ID被证明是错误的
示例
基本用法
from fastmcp import Client
from ultrathink import mcp
async with Client(mcp) as client:
# Simple sequential thinking with auto-assigned fields
result = await client.call_tool("ultrathink", {
"thought": "Let me analyze this problem step by step",
"total_thoughts": 3
# thought_number auto-assigned: 1
# next_thought_needed auto-assigned: True (1 < 3)
})
具有增强功能
async with Client(mcp) as client:
# With confidence scoring and explicit session
result = await client.call_tool("ultrathink", {
"thought": "Initial hypothesis - this approach might work",
"total_thoughts": 5,
"confidence": 0.6, # 60% confident
# next_thought_needed auto-assigned: True
"session_id": "problem-solving-session-1"
})
# Continue the same session with higher confidence
result2 = await client.call_tool("ultrathink", {
"thought": "After analysis, I'm more certain about this solution",
"total_thoughts": 5,
"confidence": 0.9, # 90% confident
# next_thought_needed auto-assigned: True
"session_id": "problem-solving-session-1" # Same session
})
# Branch from a previous thought
result3 = await client.call_tool("ultrathink", {
"thought": "Let me explore an alternative approach",
"total_thoughts": 6,
"confidence": 0.7,
"branch_from_thought": 1,
"branch_id": "alternative-path",
# next_thought_needed auto-assigned: True
"session_id": "problem-solving-session-1"
})
不确定性注释和结果
async with Client(mcp) as client:
# Track uncertainty and outcomes
result = await client.call_tool("ultrathink", {
"thought": "Testing the authentication fix",
"total_thoughts": 5,
"confidence": 0.8,
"uncertainty_notes": "Haven't tested under high load yet",
"outcome": "Login flow works for standard users"
})
# Response includes the new fields
print(result["confidence"]) # 0.8
print(result["uncertainty_notes"]) # "Haven't tested under high load yet"
print(result["outcome"]) # "Login flow works for standard users"
假设跟踪
async with Client(mcp) as client:
# Thought 1: State assumptions explicitly
result = await client.call_tool("ultrathink", {
"thought": "Redis should meet our performance requirements",
"total_thoughts": 4,
"assumptions": [
{
"id": "A1",
"text": "Network latency to Redis < 5ms",
"confidence": 0.8,
"critical": True,
"verifiable": True,
"evidence": "Based on preliminary network tests in staging environment"
}
]
})
# Thought 2: Build on previous assumptions
result2 = await client.call_tool("ultrathink", {
"thought": "Based on low latency, Redis can handle 10K req/sec",
"total_thoughts": 4,
"depends_on_assumptions": ["A1"],
"session_id": result["session_id"]
})
# Thought 3: Invalidate if proven false
result3 = await client.call_tool("ultrathink", {
"thought": "After testing, latency is 15ms, not 5ms!",
"total_thoughts": 4,
"invalidates_assumptions": ["A1"],
"session_id": result["session_id"]
})
# Track all assumptions and detect risky ones
print(result3["all_assumptions"]) # {"A1": {...}}
print(result3["falsified_assumptions"]) # ["A1"]
配置
环境变量
DISABLE_THOUGHT_LOGGING:设置为"true"禁用stderr的彩色思维记录
使用Claude Desktop
添加到您的 claude_desktop_config.json:
使用GitHub上的uvx(推荐)
{
"mcpServers": {
"UltraThink": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/husniadil/ultrathink",
"ultrathink"
]
}
}
}
地方发展
从源头上促进当地发展:
{
"mcpServers": {
"UltraThink": {
"command": "uv",
"args": ["--directory", "/path/to/ultrathink", "run", "ultrathink"]
}
}
}
本地配置文件
对于本地开发和测试,您可以创建 .mcp.json 文件(参见 .mcp.json.example):
# Copy the example file
cp .mcp.json.example .mcp.json
# Edit to match your local path
# Change /path/to/ultrathink to your actual directory
配置示例(.mcp.json.example):
{
"mcpServers": {
"UltraThink": {
"command": "uv",
"args": ["--directory", "/path/to/ultrathink", "run", "ultrathink"],
"env": {
"DISABLE_THOUGHT_LOGGING": "false"
}
}
}
}
此配置:
- 默认情况下启用思想记录(
DISABLE_THOUGHT_LOGGING: "false") - 可与支持以下功能的MCP客户端一起使用
.mcp.json配置 - 可用于在启用彩色输出的情况下在本地测试服务器
- 注:
.mcp.json是否为gitignored-根据您的本地设置进行自定义
会话管理
会话生命周期
重要提示: 会话已存储 仅在内存中 并且当服务器重新启动或终止时将丢失。每个会话都由一个唯一的会话ID标识,并维护:
- 那次会议的思想史
- 分行跟踪
- 顺序思维编号
启示:
- 会话在服务器重新启动后不会持续
- 当服务器停止时,所有思考上下文都会丢失
- 对于需要持久会话的生产用例,您需要实现自定义会话持久性(例如,到磁盘、数据库或外部状态管理)
最佳实践:
- 如果需要重新创建会话上下文,请使用自定义会话ID(而不是自动生成的UUID)进行弹性恢复
- 如果需要持久性,请将会话关键信息保存在应用层
- 将会话视为主动解决问题任务的短暂工作记忆
建筑
内置于 简单分层架构 关注点和可维护代码的干净分离原则。
文件
src/超薄/ (三层结构)
模型层 (models/)
- thought.py:思考、思考请求、思考响应模型
- 会话.py:ThinkingSession模型
服务层 (services/)
- thinking_service.py:UltraThinkService业务逻辑
界面层 (interface/)
- mcp_server.py:带有FastMCP工具注册的MCP服务器入口点
包裹入口点
- __init__.py:包装出口
- __主__.py:CLI入口点(启用
uv run ultrathink)
测试/ (100%覆盖,镜像源结构)
模型测试 (models/)
- test_thought.py:思维模型测试(属性、格式)
- test_session.py:会话日志记录和格式化测试
服务测试 (services/)
- test_thinking_service.py:服务测试(验证、功能、分支、多会话)
接口测试 (interface/)
- test_mcp_server.py:MCP工具功能测试
根测试文件
- test_cli.py:CLI入口点测试
示例/
- 客户端.py:测试客户端演示工具使用
架构层
1.模型层
用于数据表示和验证的Pydantic模型:
思想:核心模型表示具有验证和行为的单一思想 思考请求:来自MCP客户端的输入模型,并经过验证 思考回应:使用结构化数据向MCP客户端输出模型 思考环节:管理思想史和分支的会话模型
# Type-safe model usage
request = ThoughtRequest(
thought="My thinking step",
thought_number=1,
total_thoughts=3,
next_thought_needed=True
)
response = ThoughtResponse(
thought_number=1,
total_thoughts=3,
next_thought_needed=True,
branches=[],
thought_history_length=1
)
2.服务层
业务逻辑和编排:
UltraThinkService:协调思维过程
责任:
- 模型翻译:
ThoughtRequest → Thought模型(输入) - 业务逻辑:代表
ThinkingSession - 响应大楼:会话状态→
ThoughtResponse模型(输出) - 验证:利用Pydantic进行自动验证
- 会话管理:创建和管理多个思考环节
关键方法:
process_thought(request: ThoughtRequest) → ThoughtResponse:主编排
service = UltraThinkService()
# Full flow:
# 1. Receives ThoughtRequest from interface layer
# 2. Translates to Thought model
# 3. Calls session.add_thought() (business logic)
# 4. Builds ThoughtResponse from session state
# 5. Returns response
request = ThoughtRequest(thought="...", thought_number=1, ...)
response = service.process_thought(request)
3.接口层
使用FastMCP的外部接口:
mcp_server.py:MCP服务器工具注册
责任:
- 使用定义MCP工具
@mcp.tool装饰器 - 将工具参数映射到模型类型
- 呼叫服务层进行处理
- 向MCP客户端返回响应
@mcp.tool
def ultrathink(thought: str, total_thoughts: int, ...) -> ThoughtResponse:
request = ThoughtRequest(thought=thought, total_thoughts=total_thoughts, ...)
return thinking_service.process_thought(request)
类型安全优势:
- 对所有输入/输出进行Pydantic验证
- 没有任意的字典-全程严格打字
- 自动验证错误
- 接口和业务逻辑之间的明确分离
架构优势
-
明确区分关注点:
- 模型层=具有验证和行为的数据模型
- 服务层=业务逻辑和编排
- 接口层=外部API(MCP工具)
-
结构更简单:更平坦的文件夹层次结构(2级而不是3级)
-
更容易进口:相对导入路径更短(
..modelsvs...domain.entities) -
合并模型:相关模型组合在一起(Thought、ThoughtRequest、ThoughtResponse在一个文件中)
-
可测试的:易于单独测试每一层
-
可维护性:
- 更改界面? → 仅更新接口层
- 更改业务规则? → 仅更新服务层
- 更改验证? → 仅更新模型层
-
可扩展:易于添加新模型、服务或工具
-
接口独立性:可以使用不同的接口(REST API、gRPC、CLI等)重用服务
-
类型安全:Pydantic模型始终确保在所有边界进行验证
发展
运行测试
# Run all tests with coverage (recommended)
uv run task test
# Run tests without coverage (quick)
uv run task test-quick
# Coverage is 100%
类型检查
# Run mypy type checker on all code
uv run task typecheck
# Mypy runs in strict mode on entire codebase
该项目使用 mypy处于严格模式 在整个代码库中(src/, tests/, examples/)以确保完全的类型安全。
测试组织
测试按层组织,反映源结构(100%覆盖率):
模型层测试 (tests/models/)
- test_thought.py:模型属性、自动调整、格式、验证和置信度评分
- test_session.py:会话日志记录和格式化输出
服务层测试 (tests/services/)
- test_thinking_service.py:服务验证、功能、分支、边缘情况、响应格式、引用验证和多会话支持
接口层测试 (tests/interface/)
- test_mcp_server.py:MCP工具函数调用
根测试
- test_cli.py:CLI入口点
学分
这个项目是Python移植的 顺序思维MCP服务器 Anthropic,模型上下文协议服务器集合的一部分。原始实现为结构化思维和解决问题提供了基础。
新功能
在保持与原始设计完全兼容的同时,UltraThink添加了几个增强功能:
- 信心评分 -每种思维都有0.0-1.0的显式不确定性跟踪
- 自动分配的思维编号 -可选思维编号(如果省略,则自动递增)
- 多会话支持 -使用会话ID管理多个并发思考会话
- 假设跟踪 -通过明确的假设、依赖关系和无效跟踪使推理透明
