ContextTree
FreeNot checkedEnables AI coding assistants to perform local semantic code search using AST parsing and embeddings, finding code by meaning with exact file and line locations,
About
Enables AI coding assistants to perform local semantic code search using AST parsing and embeddings, finding code by meaning with exact file and line locations, plus AST-based usage lookup.
README
🌳 ContextTree MCP
Local Deep Semantic & Hybrid Code Search Engine for AI Assistants
Powered by tree-sitter AST logical parsing, local embeddings, 3-layer RRF ranking & Cross-Encoder re-ranking.
GitHub Release Python Version MCP Protocol Tests Code Style License: MIT Privacy: 100% Offline README in Russian
Key Features • Languages • Architecture • Quick Start • Client Configs • MCP Tools • Search Algorithm
💡 Why ContextTree MCP?
Standard semantic search tools split code into arbitrary line or token windows, breaking function contexts and hallucinating definitions. ContextTree MCP provides LLMs with true structural intelligence of your codebase:
- 🧩 AST Logical Block Extraction: Indexes complete, meaningful units (functions, methods, classes, structs, traits) preserving docstrings and signatures.
- 🏢 Multi-Repository Unified Indexing: Seamlessly index and search across multiple repositories or multi-root workspaces in a single session.
- 🗜️ Embedding Quantization (INT8 & Binary): 4x to 32x RAM and storage compression with scalar/binary quantized vector representations.
- 🔌 Language Server Protocol (LSP) Bridge: Compiler-grade symbol definitions, hover documentation, and references across local language servers.
- ⚡ 3-Layer Hybrid Search (RRF): Blends dense vectors (
sentence-transformers/all-MiniLM-L6-v2), BM25 lexical token matching (camelCase/snake_case), and Call-Graph In-Degree Ranking. - 🎯 Cross-Encoder 2nd-Stage Re-ranking: Joint cross-attention re-scoring (
rerank=True) for maximum precision on nuanced queries. - 🔍 Zero-Hallucination Code Navigation: Real AST call-site tracking (
find_ast_usages) and cross-file definition jump (go_to_definition). - 🔄 Incremental Indexing & Watch Mode: SHA-256 state tracking with 500ms debounced filesystem watcher across multiple workspaces.
- 🌐 Flexible Transports: Standard
stdio,SSEover HTTP, andStreamable HTTP. - 🔒 100% Offline & Private: Zero cloud dependencies, zero external API calls, zero telemetry.
🌐 Supported Languages (12 Languages)
| Language | Extensions | Extracted AST Constructs |
|---|---|---|
| Python | .py |
Functions, decorated definitions, classes, methods, docstrings (PEP-257) |
| TypeScript / TSX | .ts, .tsx, .mts, .cts |
Functions, arrow functions, methods, class/interface signatures, JSDoc |
| JavaScript / JSX | .js, .jsx, .mjs, .cjs |
Functions, arrow functions, methods, class signatures, JSDoc |
| Go | .go |
Functions, receiver methods, struct/interface types, package comments |
| Rust | .rs |
Functions, impl methods, structs, traits, /// documentation |
| C# | .cs |
Methods, constructors, classes, interfaces, structs, /// <summary> XML-docs |
| Java | .java |
Methods, constructors, classes, interfaces, records, Javadoc |
| C | .c, .h |
Functions, structs, unions, enums, declarator unpacking, comments |
| C++ | .cpp, .hpp, .cc, .cxx, .hh, .hxx |
Methods, classes, structs, namespaces, destructors, doc comments |
| Kotlin | .kt, .kts |
Functions, classes, objects, member methods, KDoc comments |
| Swift | .swift |
Functions, methods, classes, structs, protocols, enums, Swift-doc |
🏗️ Architecture
flowchart TB
subgraph Client["🤖 AI Assistant Client"]
Claude["Claude Desktop / Cursor / Antigravity / OpenCode"]
end
subgraph Server["🌳 ContextTree MCP Server"]
Transport["Transport Layer (Stdio / SSE / HTTP)"]
Tools["MCP Tools (search, usages, definition, index)"]
subgraph Pipeline["Indexing & Search Pipeline"]
TreeSitter["Tree-sitter AST Parser (12 Grammars)"]
Chunker["Logical Block Chunker (Signatures + Docs)"]
BM25["In-Memory BM25 Index (Cached)"]
VectorStore["ChromaDB Vector Store (384d Embeddings)"]
CallGraph["Call-Graph In-Degree Frequency"]
RRF["3-Layer Reciprocal Rank Fusion"]
CrossEncoder["Cross-Encoder Re-ranker (ms-marco-MiniLM)"]
end
end
subgraph Workspace["💻 Local Workspace Files"]
SourceFiles["Source Code (.py, .ts, .go, .rs, .cpp, .kt, ...)"]
State[".chroma/index_state.json (SHA-256 Fast Path)"]
end
Claude <--> Transport
Transport <--> Tools
Tools <--> Pipeline
Pipeline <--> Workspace
🚀 Quick Start
Prerequisites
- Python 3.12+
- uv (strongly recommended) or standard
pip
1. Installation
# Clone the repository
git clone https://github.com/chelslava/mcp-context-tree.git
cd mcp-context-tree
# Install dependencies and local package via uv
uv sync
2. Running ContextTree MCP
# Standard MCP stdio mode (default for AI desktop clients)
uv run context-tree
# Server-Sent Events (SSE) HTTP transport on port 8000
uv run context-tree --transport sse --host 127.0.0.1 --port 8000
# Streamable HTTP transport
uv run context-tree --transport streamable-http --port 8000
# Standalone Watch Mode (continuously indexes workspace on save)
uv run context-tree --watch /path/to/project
⚙️ Client Configuration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"context-tree": {
"command": "uv",
"args": [
"run",
"--directory",
"D:/Repo/mcp-context-tree",
"context-tree"
]
}
}
}
Cursor IDE / Windsurf
Add to .cursor/mcp.json or Cursor MCP Settings:
{
"mcpServers": {
"context-tree": {
"command": "uv",
"args": ["run", "--directory", "/absolute/path/to/mcp-context-tree", "context-tree"]
}
}
}
Google Antigravity / Remote SSE Setup
If using network transport (--transport sse):
{
"mcpServers": {
"context-tree": {
"url": "http://127.0.0.1:8000/sse"
}
}
}
🛠️ MCP Tools Reference
1. index_workspace
Scans the project directory, computes SHA-256 hashes, applies .gitignore rules, and incrementally updates the local ChromaDB vector store.
// Parameters
{
"directory_path": "."
}
// Response
{
"status": "ok",
"workspace": "/path/to/project",
"added": 12,
"modified": 2,
"deleted": 0,
"unchanged": 85,
"indexed_chunks": 340,
"total_in_store": 340
}
2. semantic_search
Executes deep code search across the workspace with live snippet resolution from disk.
// Parameters
{
"query": "how to verify and refresh JWT authentication tokens",
"directory_path": ".",
"limit": 5,
"mode": "hybrid", // "hybrid" | "semantic" | "keyword"
"rerank": true // Optional 2nd-stage Cross-Encoder re-ranking
}
// Response
{
"results": [
{
"file": "src/auth/service.py",
"type": "method",
"class": "AuthService",
"name": "verify_jwt_token",
"start_line": 45,
"end_line": 68,
"score": 0.9624,
"code": "def verify_jwt_token(self, token: str) -> Claims:\n ..."
}
]
}
3. find_ast_usages
Performs true AST-level call-site resolution for functions, methods, and classes, ignoring string literals and comments.
// Parameters
{
"symbol_name": "AuthService.verify_jwt_token",
"directory_path": ".",
"limit": 50
}
// Response
{
"usages": [
{
"file": "src/api/routes.py",
"line": 104,
"preview": "claims = auth_service.verify_jwt_token(token)"
}
]
}
4. go_to_definition
Instantly resolves the exact AST declaration/definition location of a symbol across all 12 supported languages.
// Parameters
{
"symbol_name": "UserRepo.getUser",
"directory_path": ".",
"limit": 20
}
// Response
{
"definitions": [
{
"file": "src/models/User.kt",
"language": "kotlin",
"type": "method",
"name": "getUser",
"class": "UserRepo",
"start_line": 14,
"end_line": 22,
"code": "fun getUser(id: String): User? {\n ...",
"docstring": "/** Retrieve user by identifier */"
}
]
}
🔬 Search & Ranking Algorithm
ContextTree MCP uses a 3-Layer Reciprocal Rank Fusion (RRF) formula to merge dense semantic embeddings, exact lexical matches, and architectural importance:
$$RRF(d) = \frac{w_{vec}}{k + rank_{vec}(d)} + \frac{w_{bm25}}{k + rank_{bm25}(d)} + \frac{w_{graph}}{k + rank_{graph}(d)}$$
Where:
- $k = 60$ (smoothing constant)
- $w_{vec} = 1.0$ (dense semantic similarity via
all-MiniLM-L6-v2) - $w_{bm25} = 1.0$ (Robertson-Spärck Jones BM25 with
camelCase/snake_casetokenization) - $w_{graph} = 0.5$ (in-degree call frequency boost: heavily referenced core symbols float to the top)
- Cross-Encoder Layer: When
rerank=True, candidate chunks pass through joint self-attention (cross-encoder/ms-marco-MiniLM-L-6-v2) for fine-grained semantic scoring.
🔒 Privacy & Security
- 100% Local Execution: All parsing, embedding generation, and vector indexing happen entirely on your machine.
- Zero Cloud Network Calls: Never transmits source code or embeddings to external APIs.
- Respects Ignore Rules: Honors root and nested
.gitignorerules alongside built-in filters fortarget/,node_modules/,bin/,obj/,.git/,.venv/.
🧪 Testing & Quality
ContextTree MCP maintains 100% pass rate across its test suite and strict linting:
# Run test suite (60 unit & integration tests)
uv run pytest
# Run linter and formatting check
uv run ruff check .
uv run ruff format --check .
📄 License
Distributed under the MIT License. See LICENSE for details.
Install ContextTree in Claude Desktop, Claude Code & Cursor
unyly install contexttree-mcpInstalls into Claude Desktop, Claude Code, Cursor & VS Code — handles npx, uvx and build-from-source repos for you.
First time? Get the CLI: curl -fsSL https://unyly.org/install | sh
Or configure manually
Run in your terminal:
claude mcp add contexttree-mcp -- uvx --from git+https://github.com/chelslava/mcp-context-tree context-tree-mcpStep-by-step: how to install ContextTree
FAQ
Is ContextTree MCP free?
Yes, ContextTree MCP is free — one-click install via Unyly at no cost.
Does ContextTree need an API key?
No, ContextTree runs without API keys or environment variables.
Is ContextTree hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install ContextTree in Claude Desktop, Claude Code or Cursor?
Open ContextTree on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
GitHub
PRs, issues, code search, CI status
by GitHubFilesystem
Secure file operations with configurable access controls.
Memory
Knowledge graph-based persistent memory system.
Unyly Deploy
Deploy sites and MCP servers to Unyly straight from your AI agent
by UnylyTemplate MCP Server
A CLI tool to create a new Model Context Protocol server project with TypeScript support, dual transport options, and an extensible structure
by mcpdotdirectServer Sequential Thinking
MCP server for sequential thinking and problem solving
by GitHub ActionsAmap Maps Mcp Server
MCP server for using the AMap Maps API
by duxiaohuiPayMCP
Lightweight payments layer for MCP servers: turn tools into paid endpoints with a two-line decorator. [PyPI](https://pypi.org/project/paymcp/) · [npm](https://w
by blustAIdemo
demo — MCP server via Smithery
by yoojoohans-jpgServer For Power BI
Enables exploring Microsoft Fabric / Power BI workspaces and semantic models, and executing ad-hoc DAX queries.
by Mitsubishi-FusoCompare ContextTree with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All development MCPs
