](https://mseep.ai/app/angrysky56-mcts-mcp-server)
MCTS MCP服务器
一种模型上下文协议(MCP)服务器,它公开了一个高级贝叶斯蒙特卡洛树搜索(MCTS)引擎,用于人工智能辅助分析和推理。
概述
此MCP服务器使Claude能够使用蒙特卡洛树搜索(MCTS)算法对主题、问题或文本输入进行深入的探索性分析。MCTS算法使用贝叶斯方法系统地探索不同的角度和解释,通过多次迭代产生有见地的分析。
特性
- 贝叶斯MCTS:在分析过程中使用概率方法来平衡勘探与开采
- 多次迭代分析:支持多次迭代思维,每次迭代进行多次模拟
- 状态持久性:在同一聊天中记住关键结果、不合适的方法和回合之间的先验
- 方法分类学:将产生的思想分为不同的哲学方法和家族
- 汤普森采样:可以使用Thompson采样或UCT进行节点选择
- 意外检测:确定令人惊讶或新颖的分析方向
- 意图分类:了解用户何时想要开始新的分析或继续之前的分析
- 多LLM支持:支持Ollama、OpenAI、Anthropic和Google Gemini模型。
快速启动安装
MCTS MCP服务器现在包括适用于Windows、macOS和Linux的跨平台设置脚本。
先决条件
- Python 3.10+ (必填)
- Internet连接 (用于下载依赖项)
自动设置
选项1:跨平台Python设置(推荐)
# Clone the repository
git clone https://github.com/angrysky56/mcts-mcp-server.git
cd mcts-mcp-server
# Run the setup script
python setup.py选项2:特定于平台的脚本
Linux/macOS:
chmod +x setup.sh
./setup.sh窗户:
setup_windows.bat安装程序的作用
安装脚本会自动执行以下操作:
- ✅ 检查Python版本兼容性(需要3.10+)
- ✅ 安装UV包管理器(如果不存在)
- ✅ 创建虚拟环境
- ✅ 安装所有依赖项,包括谷歌genai
- ✅ 创建
.env模板文件 - ✅ 生成Claude桌面配置
- ✅ 创建状态目录
- ✅ 验证安装
验证安装
设置后,验证一切正常:
python verify_installation.py这会进行全面检查,并告诉您是否有任何需要修复的地方。
配置
1.API密钥设置
编辑 .env 安装过程中创建的文件:
# Add your API keys (remove quotes and add real keys)
OPENAI_API_KEY=sk-your-openai-key-here
ANTHROPIC_API_KEY=sk-ant-your-anthropic-key-here
GEMINI_API_KEY=your-gemini-api-key-here
# Set default provider and model (optional)
DEFAULT_LLM_PROVIDER=gemini
DEFAULT_MODEL_NAME=gemini-2.0-flash获取API密钥:
- OpenAI: https://platform.openai.com/api-keys
- Anthropic: https://console.anthropic.com/
- 谷歌双子座: https://aistudio.google.com/app/apikey
- 奥拉马:不需要API密钥(本地模型)
2.克劳德桌面集成
设置创建 claude_desktop_config.json。将其内容添加到您的Claude Desktop配置中:
Linux/macOS:
# Config location
~/.config/claude/claude_desktop_config.json窗户:
# Config location
%APPDATA%\Claude\claude_desktop_config.json配置结构示例:
{
"mcpServers": {
"mcts-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcts-mcp-server/src",
"run",
"mcts-mcp-server"
],
"env": {
"UV_PROJECT_ENVIRONMENT": "/path/to/mcts-mcp-server"
}
}
}
}重要提示: 更新路径以匹配您的安装目录。
3.重新启动克劳德桌面
添加配置后,重新启动Claude Desktop以加载MCTS服务器。
用法
服务器以可复制粘贴的格式向您的LLM公开了许多工具,详细信息如下,用于您的系统提示。
当你让Claude对一个主题或问题进行深入分析时,它会自动利用这些工具,使用 MCTS算法和分析工具。
运作原理
MCTS MCP服务器使用本地推理方法,而不是尝试直接调用LLM。这与MCP协议兼容 是为人工智能助手(如克劳德)调用工具而设计的,而不是为工具本身调用人工智能模型而设计的。
当Claude要求服务器执行分析时,服务器:
- 用问题初始化MCTS系统
- 使用MCTS算法进行多次迭代探索
- 为各种分析任务生成确定性响应
- 返回搜索过程中找到的最佳分析
手动安装(高级)
如果您更喜欢手动设置或自动设置失败:
1.安装UV包管理器
Linux/macOS:
curl -LsSf https://astral.sh/uv/install.sh | shWindows(PowerShell):
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"2.设置项目
# Clone repository
git clone https://github.com/angrysky56/mcts-mcp-server.git
cd mcts-mcp-server
# Create virtual environment
uv venv .venv
# Activate virtual environment
# Linux/macOS:
source .venv/bin/activate
# Windows:
.venv\Scripts\activate
# Install dependencies
uv pip install .
uv pip install .[dev] # Optional development dependencies
# Install Gemini package specifically (if not in pyproject.toml)
uv pip install google-genai>=1.20.03.创建配置文件
# Copy environment file
cp .env.example .env
# Edit .env file with your API keys
nano .env # or use your preferred editor
# Create state directory
mkdir -p ~/.mcts_mcp_server故障排除
常见问题
1.Python版本错误
Solution: Install Python 3.10+ from python.org2.安装后未找到UV
# Add UV to PATH manually
export PATH="$HOME/.cargo/bin:$PATH"
# Or on Windows: Add %USERPROFILE%\.cargo\bin to PATH3.谷歌Gemini导入错误
# Install Gemini package manually
uv pip install google-genai4.权限被拒绝(Linux/macOS)
# Make scripts executable
chmod +x setup.sh setup_unix.sh5.克劳德桌面未检测到服务器
- 验证配置文件位置和语法
- 检查配置中的路径是否绝对正确
- 完全重新启动克劳德桌面
- 检查Claude Desktop日志是否有错误
获取帮助
- 运行验证:
python verify_installation.py - 检查日志:查看Claude Desktop的开发工具
- 测试组件:在存储库中运行单个测试
- 审查文件:有关详细说明,请查看USAGE_GUIDE.md
API密钥管理
对于使用像OpenAI、Anthropic和Google Gemini这样的LLM提供商,您需要提供API密钥。此服务器从 .env 位于存储库根目录的文件。
- 复制示例文件:
cp .env.example .env - 编辑
.env:打开.env文件,并将占位符密钥替换为实际的API密钥:
OPENAI_API_KEY="your_openai_api_key_here"
ANTHROPIC_API_KEY="your_anthropic_api_key_here"
GEMINI_API_KEY="your_google_gemini_api_key_here"- 设置默认值(可选):您还可以在
.env文件:
# Default LLM Provider to use (e.g., "ollama", "openai", "anthropic", "gemini")
DEFAULT_LLM_PROVIDER="ollama"
# Default Model Name for the selected provider
DEFAULT_MODEL_NAME="cogito:latest"如果未设置这些,系统将默认为“ollama”,并尝试使用“cogito:latest”等模型或其他特定于提供商的默认值。
这 .env 文件包含在 .gitignore,因此您的实际密钥将不会提交到存储库。
建议的系统提示和更新工具
______________________________________________________________________
# MCTS server and usage instructions:
# List available Ollama models (if using Ollama)
list_ollama_models()
# Set the active LLM provider and model
# provider_name can be "ollama", "openai", "anthropic", "gemini"
# model_name is specific to the provider (e.g., "cogito:latest" for ollama, "gpt-4" for openai)
set_active_llm(provider_name="openai", model_name="gpt-3.5-turbo")
# Or, to use defaults from .env or provider-specific defaults:
# set_active_llm(provider_name="openai")
# Initialize analysis (can also specify provider and model here to override active settings for this run)
initialize_mcts(question="Your question here", chat_id="unique_id", provider_name="openai", model_name="gpt-4")
# Or using the globally set active LLM:
# initialize_mcts(question="Your question here", chat_id="unique_id")
run_mcts(iterations=1, simulations_per_iteration=5)
After run_mcts is called it can take quite a long time ie minutes to hours
- so you may discuss any ideas or questions or await user confirmation of the process finishing,
- then proceed to synthesis and analysis tools on resumption of chat.
## MCTS-MCP Tools Overview
### Core MCTS Tools:
- `initialize_mcts`: Start a new MCTS analysis with a specific question. Can optionally specify `provider_name` and `model_name` to override defaults for this run.
- `run_mcts`: Run the MCTS algorithm for a set number of iterations/simulations.
- `generate_synthesis`: Generate a final summary of the MCTS results.
- `get_config`: View current MCTS configuration parameters, including active LLM provider and model.
- `update_config`: Update MCTS configuration parameters (excluding provider/model, use `set_active_llm` for that).
- `get_mcts_status`: Check the current status of the MCTS system.
- `set_active_llm(provider_name: str, model_name: Optional[str])`: Select which LLM provider and model to use for MCTS.
- `list_ollama_models()`: Show all available local Ollama models (if using Ollama provider).
Default configuration prioritizes speed and exploration, but you can customize parameters like exploration_weight, beta_prior_alpha/beta, surprise_threshold.
## Configuration
You can customize the MCTS parameters in the config dictionary or through Claude's `update_config` tool. Key parameters include:
- `max_iterations`: Number of MCTS iterations to run
- `simulations_per_iteration`: Number of simulations per iteration
- `exploration_weight`: Controls exploration vs. exploitation balance (in UCT)
- `early_stopping`: Whether to stop early if a high-quality solution is found
- `use_bayesian_evaluation`: Whether to use Bayesian evaluation for node scores
- `use_thompson_sampling`: Whether to use Thompson sampling for selection
Articulating Specific Pathways:
Delving into the best_path nodes (using mcts_instance.get_best_path_nodes() if you have the instance) and examining the sequence of thought and content
at each step can provide a fascinating micro-narrative of how the core insight evolved.
Visualizing the tree (even a simplified version based on export_tree_summary) could also be illuminating and I will try to set up this feature.
Modifying Parameters: This is a great way to test the robustness of the finding or explore different "cognitive biases" of the system.
Increasing Exploration Weight: Might lead to more diverse, less obviously connected ideas.
Decreasing Exploration Weight: Might lead to deeper refinement of the initial dominant pathways.
Changing Priors (if Bayesian): You could bias the system towards certain approaches (e.g., increase alpha for 'pragmatic') to see how it influences the
outcome.
More Iterations/Simulations: Would allow for potentially deeper convergence or exploration of more niche pathways.
### Results Collection:
- Automatically stores results in `/home/ty/Repositories/ai_workspace/mcts-mcp-server/results` (path might be system-dependent or configurable)
- Organizes by provider, model name, and run ID
- Stores metrics, progress info, and final outputs
# MCTS Analysis Tools
This extension adds powerful analysis tools to the MCTS-MCP Server, making it easy to extract insights and understand results from your MCTS runs.
The MCTS Analysis Tools provide a suite of integrated functions to:
1. List and browse MCTS runs
2. Extract key concepts, arguments, and conclusions
3. Generate comprehensive reports
4. Compare results across different runs
5. Suggest improvements for better performance
## Available Run Analysis Tools
### Browsing and Basic Information
- `list_mcts_runs(count=10, model=None)`: List recent MCTS runs with key metadata
- `get_mcts_run_details(run_id)`: Get detailed information about a specific run
- `get_mcts_solution(run_id)`: Get the best solution from a run
### Analysis and Insights
- `analyze_mcts_run(run_id)`: Perform a comprehensive analysis of a run
- `get_mcts_insights(run_id, max_insights=5)`: Extract key insights from a run
- `extract_mcts_conclusions(run_id)`: Extract conclusions from a run
- `suggest_mcts_improvements(run_id)`: Get suggestions for improvement
### Reporting and Comparison
- `get_mcts_report(run_id, format='markdown')`: Generate a comprehensive report (formats: 'markdown', 'text', 'html')
- `get_best_mcts_runs(count=5, min_score=7.0)`: Get the best runs based on score
- `compare_mcts_runs(run_ids)`: Compare multiple runs to identify similarities and differences
## Usage Examples
# To list your recent MCTS runs:
list_mcts_runs()
# To get details about a specific run:
get_mcts_run_details('ollama_cogito:latest_1745979984') # Example run_id format
### Extracting Insights
# To get key insights from a run:
get_mcts_insights(run_id='ollama_cogito:latest_1745979984')
### Generating Reports
# To generate a comprehensive markdown report:
get_mcts_report(run_id='ollama_cogito:latest_1745979984', format='markdown')
### Improving Results
# To get suggestions for improving a run:
suggest_mcts_improvements(run_id='ollama_cogito:latest_1745979984')
### Comparing Runs
To compare multiple runs:
compare_mcts_runs(['ollama_cogito:latest_1745979984', 'openai_gpt-3.5-turbo_1745979584']) # Example run_ids
## Understanding the Results
The analysis tools extract several key elements from MCTS runs:
1. **Key Concepts**: The core ideas and frameworks in the analysis
2. **Arguments For/Against**: The primary arguments on both sides of a question
3. **Conclusions**: The synthesized conclusions or insights from the analysis
4. **Tags**: Automatically generated topic tags from the content
## Troubleshooting
If you encounter any issues with the analysis tools:
1. Check that your MCTS run completed successfully (status: "completed")
2. Verify that the run ID you're using exists and is correct
3. Try listing all runs to see what's available: `list_mcts_runs()`
4. Make sure the `.best_solution.txt` file exists in the run's directory
## Advanced Example Usage
### Customizing Reports
You can generate reports in different formats:
# Generate a markdown report
report = get_mcts_report(run_id='ollama_cogito:latest_1745979984', format='markdown')
# Generate a text report
report = get_mcts_report(run_id='ollama_cogito:latest_1745979984', format='text')
# Generate an HTML report
report = get_mcts_report(run_id='ollama_cogito:latest_1745979984', format='html')
### Finding the Best Runs
To find your best-performing runs:
best_runs = get_best_mcts_runs(count=3, min_score=8.0)
This returns the top 3 runs with a score of at least 8.0.
## Simple Usage Instructions
1. **Setting the LLM Provider and Model**:
# For Ollama:
list_ollama_models() # See available Ollama models
set_active_llm(provider_name="ollama", model_name="cogito:latest")
# For OpenAI:
set_active_llm(provider_name="openai", model_name="gpt-4")
# For Anthropic:
set_active_llm(provider_name="anthropic", model_name="claude-3-opus-20240229")
# For Gemini:
set_active_llm(provider_name="gemini", model_name="gemini-1.5-pro-latest")
2. **Starting a New Analysis**:
# Uses the LLM set by set_active_llm, or defaults from .env
initialize_mcts(question="Your question here", chat_id="unique_identifier")
# Alternatively, specify provider/model for this specific analysis:
# initialize_mcts(question="Your question here", chat_id="unique_identifier", provider_name="openai", model_name="gpt-4-turbo")
3. **Running the Analysis**:
run_mcts(iterations=3, simulations_per_iteration=10)
4. **Comparing Performance (Ollama specific example)**:
run_model_comparison(question="Your question", iterations=2)
5. **Getting Results**:
generate_synthesis() # Final summary of results
get_mcts_status() # Current status and metrics
______________________________________________________________________
示例提示
- “分析人工智能对人类创造力的影响”
- “继续探索这一主题的伦理维度”
- “你在上次运行中发现的最佳分析是什么?”
- “这个MCTS流程是如何工作的?”
- “显示当前MCTS配置”
对于开发者
开发设置
# Activate virtual environment
source .venv/bin/activate
# Install development dependencies
uv pip install .[dev]
# Run the server directly (for testing)
uv run server.py
# OR use the MCP CLI tools
uv run -m mcp dev server.py测试服务器
要测试服务器是否正常工作,请执行以下操作:
# Activate the virtual environment
source .venv/bin/activate
# Run the verification script
python verify_installation.py
# Run the test script
python test_server.py这将测试LLM适配器,以确保其正常工作。
项目结构
mcts-mcp-server/
├── src/mcts_mcp_server/ # Main package
│ ├── adapters/ # LLM adapters
│ ├── analysis_tools/ # Analysis and reporting tools
│ ├── mcts_core.py # Core MCTS algorithm
│ ├── tools.py # MCP tools
│ └── server.py # MCP server
├── setup.py # Cross-platform setup script
├── setup.sh # Unix setup script
├── setup_windows.bat # Windows setup script
├── verify_installation.py # Installation verification
├── pyproject.toml # Project configuration
├── .env.example # Environment template
└── README.md # This file贡献
欢迎为改进MCTS MCP服务器做出贡献。一些潜在的改进领域:
- 改进本地推理适配器以进行更复杂的分析
- 添加更复杂的思维模式和评估策略
- 增强树可视化和结果报告
- 优化MCTS算法参数
开发工作流程
- 分叉存储库
- 运行安装程序:
python setup.py - 验证安装:
python verify_installation.py - 进行更改
- 测试更改:
python test_server.py - 提交拉取请求
