ContextTree MCP
This MCP server lets AI assistants index a local codebase and perform deep code navigation and hybrid semantic search entirely offline.
Index a workspace: scan a project directory, detect changed files via SHA-256 hashes, and incrementally update a local ChromaDB vector store.
Semantic search: search code by meaning, keywords, or both (hybrid mode), with BM25+vector ranking and optional cross-encoder reranking; results include file, construct type, class, method, line ranges, and code snippets.
Find AST usages: locate real call sites and instantiations of functions/classes while ignoring string literals and comments.
Go to definition: jump to the exact declaration of functions, methods, classes, structs, traits, and interfaces across the workspace.
Multi-language support: works with Python, TypeScript, JavaScript, Go, Rust, C#, Java, C, C++, Kotlin, and Swift.
Flexible operation: supports stdio, SSE, and Streamable HTTP transports, plus incremental watch-mode indexing.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ContextTree MCP Search the codebase for payment retry logic and show me the exact locations."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
๐ณ 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.
๐ก 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.
Related MCP server: smart-coding-mcp
๐ Supported Languages (12 Languages)
Language | Extensions | Extracted AST Constructs |
Python |
| Functions, decorated definitions, classes, methods, docstrings (PEP-257) |
TypeScript / TSX |
| Functions, arrow functions, methods, class/interface signatures, JSDoc |
JavaScript / JSX |
| Functions, arrow functions, methods, class signatures, JSDoc |
Go |
| Functions, receiver methods, struct/interface types, package comments |
Rust |
| Functions, |
C# |
| Methods, constructors, classes, interfaces, structs, |
Java |
| Methods, constructors, classes, interfaces, records, Javadoc |
C |
| Functions, structs, unions, enums, declarator unpacking, comments |
C++ |
| Methods, classes, structs, namespaces, destructors, doc comments |
Kotlin |
| Functions, classes, objects, member methods, KDoc comments |
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 standardpip
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 sync2. 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.
Available Tools
4 toolsfind_ast_usagesA
AST-based lookup of real call sites / instantiations of a function or class. Filters out string literals, comments, and non-call occurrences.
Inputs: symbol_name (required), limit, directory_path. Returns: result
go_to_definitionA
Finds the exact definition/declaration location of a symbol (function, method, class, struct, trait, interface) across workspace files.
Inputs: symbol_name (required), limit, directory_path. Returns: result
index_workspaceA
Walks the project, detects changed files by SHA-256 hash, and incrementally updates the persistent local ChromaDB vector store.
Inputs: directory_path. Returns: result
semantic_searchA
Search code by meaning and keywords (hybrid BM25+vectors, semantic, or keyword). Returns ranked code fragments with exact file, class, method, start_line, end_line, and code snippets. Supports optional Cross-Encoder re-ranking (rerank=True).
Inputs: query (required), mode, limit, rerank, +1 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
TDQS
Scored across 4 tools
Each tool targets a distinct part of code navigation: semantic search vs. exact definitions vs. AST usages vs. index maintenance. There is no realistic confusion between their purposes.
Three of four tools use imperative verb-first names (find_ast_usages, index_workspace, go_to_definition), and all are snake_case. semantic_search breaks the pattern slightly by starting with an adjective instead of a verb, but the naming remains readable and predictable.
With 4 tools, the server is well-scoped and each tool earns its place in the code indexing/search/navigation workflow. There is no redundancy or bloat.
The core lifecycle is covered: index the workspace, search semantically, go to definitions, and find AST usages. Minor gaps such as no explicit index status or reset operation prevent a perfect score, but agents can work around them.
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Search indexed code, trace dependencies, assess change impact, and recall repository memory.
Versioned documentation registry and semantic search for AI tools and coding assistants.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables semantic code search for AI assistants by indexing codebases with embeddings and Tree-sitter, returning relevant snippets via natural language queries.15MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to perform intelligent semantic code search across codebases using local AI embeddings for meaning-based retrieval.624 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI coding agents to perform semantic code search locally, finding code by meaning rather than exact keywords.3MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI coding assistants to search codebases by meaning using local AI embeddings, with tools for indexing, cache management, workspace switching, status checks, and package version lookup. It supports incremental and progressive indexing with configurable embedding dimensions to find relevant code even when terminology differs.24 npmMIT