LATS MCP Server

LATS MCP Server

Enables systematic code investigation using Monte Carlo Tree Search to explore codebases, analyze files, and provide intelligent insights. It features persistent memory and pattern learning for improved investigations.

Category
访问服务器

README

LATS MCP Server

A sophisticated code investigation agent that uses Language Agent Tree Search (LATS) with Monte Carlo Tree Search to systematically explore codebases and provide intelligent insights.

Features

  • 🌳 Monte Carlo Tree Search: Systematic parallel exploration of solution space
  • 🧠 Reasoning Transparency: Full chain-of-thought with gpt-oss model
  • 💾 Persistent Memory: Learn from past investigations using langmem
  • 🔍 Smart Code Analysis: AST-based structure analysis and dependency extraction
  • 🚀 MCP Integration: Easy integration with Claude and other LLMs
  • 📊 Pattern Recognition: Learns successful investigation patterns over time

Quick Start

Prerequisites

  1. Python 3.9+
  2. Ollama with gpt-oss model:
# Install Ollama (if not installed)
curl -fsSL https://ollama.com/install.sh | sh

# Pull the gpt-oss model
ollama pull gpt-oss

# Start Ollama server
ollama serve

Installation

# Clone the repository
git clone <repository-url>
cd lats

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Running the Server

# Make the server executable
chmod +x lats_mcp_server.py

# Run the MCP server
python lats_mcp_server.py

Integration with Claude

Add to your Claude MCP configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "lats": {
      "command": "python",
      "args": ["/absolute/path/to/lats_mcp_server.py"],
      "transport": "stdio"
    }
  }
}

Usage Examples

Basic Investigation

# Via MCP in Claude
"Investigate where error handling is implemented in the authentication module"

# Response includes:
# - Solution path with scored steps
# - File references with line numbers
# - Explored branches
# - Confidence score
# - Actionable suggestions

Quick File Analysis

# Analyze a specific file
"Analyze the structure of auth/login.py"

# Returns:
# - File content preview
# - Code structure (classes, functions)
# - Dependencies and imports

Parallel Search

# Search for multiple patterns simultaneously
"Search for 'login', 'authenticate', and 'session' in the codebase"

# Returns matches for each pattern with context

Available MCP Tools

investigate

Full LATS investigation of a task

  • Args: task (str), max_depth (int), max_iterations (int), use_memory (bool)
  • Returns: Solution path, file references, confidence score

get_status

Get current investigation status

  • Returns: Task, status, progress, current branch

search_memory

Search past investigations

  • Args: query (str), limit (int)
  • Returns: Similar investigations with solutions

get_insights

Retrieve relevant insights

  • Args: context (str)
  • Returns: List of relevant insights

analyze_file

Quick single-file analysis

  • Args: file_path (str)
  • Returns: Content, structure, dependencies

parallel_search

Search multiple patterns in parallel

  • Args: patterns (List[str]), directory (str)
  • Returns: Matches for each pattern

How LATS Works

1. Tree Search Process

Root Node
├── Action 1 (Score: 6.5)
│   ├── Action 1.1 (Score: 7.8) ← Best path
│   └── Action 1.2 (Score: 5.2)
└── Action 2 (Score: 4.3)
    └── Action 2.1 (Score: 3.9)

2. Node Selection

Uses Upper Confidence Bound (UCT) to balance:

  • Exploitation: Choose high-scoring paths
  • Exploration: Try less-visited branches

3. Reflection & Scoring

Each action is evaluated on:

  • Relevance to task (0-10 scale)
  • Information quality
  • Progress toward solution

4. Memory & Learning

  • Stores successful investigations
  • Extracts action patterns
  • Provides suggestions for similar tasks

Configuration

Edit LATSConfig in lats_core.py:

class LATSConfig:
    model_name = "gpt-oss"          # Ollama model
    base_url = "http://localhost:11434"  # Ollama URL
    temperature = 0.7                # Model temperature
    max_depth = 5                    # Max tree depth
    max_iterations = 10              # Max search iterations
    num_expand = 5                   # Actions per expansion
    c_param = 1.414                  # UCT exploration parameter
    min_score_threshold = 7.0        # Solution threshold

Architecture

┌─────────────────┐
│   MCP Client    │
│    (Claude)     │
└────────┬────────┘
         │ MCP Protocol
┌────────▼────────┐
│  FastMCP Server │
└────────┬────────┘
         │
┌────────▼────────┐
│  LATS Algorithm │
├─────────────────┤
│ • Tree Search   │
│ • Node Selection│
│ • Reflection    │
└────────┬────────┘
         │
┌────────▼────────────┐
│   Core Components   │
├────────┬────────────┤
│Filesystem│  Memory  │
│  Tools   │ Manager  │
└──────────┴──────────┘
         │
┌────────▼────────┐
│     Ollama      │
│   (gpt-oss)     │
└─────────────────┘

Development

Running Tests

# Run unit tests
python -m pytest tests/

# Run with coverage
python -m pytest --cov=. tests/

Adding New Tools

  1. Add tool function to filesystem_tools.py
  2. Register in create_filesystem_tools()
  3. Update MCP server if needed

Extending Memory

  1. Add namespace in MemoryManager.__init__
  2. Create storage/retrieval methods
  3. Integrate with investigation flow

Troubleshooting

Ollama Connection Issues

# Check Ollama is running
curl http://localhost:11434/api/tags

# Verify model is available
ollama list | grep gpt-oss

Memory Store Errors

  • Check write permissions in directory
  • Verify langmem is properly installed
  • Review error namespace for details

Tool Execution Failures

  • Check file permissions
  • Verify path existence
  • Review size limits (1MB max)

Performance Tips

  1. Adjust max_depth: Lower for faster results
  2. Limit iterations: Reduce for quicker investigations
  3. Use memory: Leverages past investigations
  4. Parallel search: Batch multiple queries
  5. Target searches: Provide specific directories

Contributing

  1. Fork the repository
  2. Create feature branch
  3. Add tests for new features
  4. Update documentation
  5. Submit pull request

License

MIT License - See LICENSE file for details

Acknowledgments

  • LangChain/LangGraph for agent framework
  • Anthropic for MCP protocol
  • OpenAI for gpt-oss model
  • langmem for memory management

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选