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.
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
- Python 3.9+
- 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
- Add tool function to
filesystem_tools.py - Register in
create_filesystem_tools() - Update MCP server if needed
Extending Memory
- Add namespace in
MemoryManager.__init__ - Create storage/retrieval methods
- 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
- Adjust max_depth: Lower for faster results
- Limit iterations: Reduce for quicker investigations
- Use memory: Leverages past investigations
- Parallel search: Batch multiple queries
- Target searches: Provide specific directories
Contributing
- Fork the repository
- Create feature branch
- Add tests for new features
- Update documentation
- 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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.