local-code-index
A local MCP server that indexes codebases using Tree-sitter AST parsing and LanceDB, enabling AI models to search across repositories with sub-second latency.
README
Local Code Index - MCP Server š
A high-performance, fully local, open-source Model Context Protocol (MCP) server built to index massive codebases into an easily searchable format for AI models.
This tool is explicitly optimized for TypeScript, JavaScript, and Java, utilizing official Tree-sitter AST parsing to capture complete code structures (classes, methods, decorators, annotations, and Javadoc comments) instead of blind text fragments. It runs entirely on your machine via Ollama and LanceDB, requiring zero API keys and protecting your intellectual property.
š ļø Features
- AST-Aware Structural Chunking: Groups methods, classes, and relevant context (like
@Get()decorators in NestJS or Javadoc strings in Spring Boot) into unified semantic records. - Scalable Multi-Repo Architecture: Automatically provisions isolated database tables per repository. Scale up to 100+ codebases incrementally without performance or query degradation.
- Cross-Repository Search: Allows AI models to scan one repository or run a global matrix query across all indexed projects simultaneously.
- Production-Grade File Filtering: Automatically skips
node_modules, build outputs, binaries, lockfiles, and environment secrets (.env). - Sub-Second Latency: Automatically compiles localized IVF-PQ vector indexes on larger repositories to keep query speeds under a second.
šļø Architecture Design
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Your Massive Codebase (TS, JS, Java) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā (Tree-sitter AST Parsing)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Semantic Chunks (Functions, Classes, Decorators) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā (Local Ollama nomic-embed-text)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Isolated LanceDB Tables (repo_A, repo_B, etc.) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
āāāāāāāāāāā“āāāāāāāāāā
ā¼ ā¼
[ search_codebase ] [ search_all_codebases ]
ā² ā²
āāāāāāāāāāā¬āāāāāāāāāā
ā (Model Context Protocol)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Your AI Workspace Environment (Cursor / Cline) ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š¦ Project Structure
Ensure your local project directory matches this setup:
local-code-index/
āāā pyproject.toml # Pin-point environment and tool configurations
āāā parser_utils.py # Official Tree-sitter AST parsing layer
āāā server.py # FastMCP server tool and LanceDB engine
āāā README.md # Project documentation
š Quick Start & Installation
1. Start Your Local Embedding Model
Make sure Ollama is installed and active on your machine, then download the code-optimized embedding vector weights:
ollama pull nomic-embed-text
2. Install the Project Package
Navigate to your project directory and run the compilation step using uv (or standard pip):
cd local-code-index
uv pip install -e .
3. Register the VS Code / Editor Extension
To connect this local tool to your AI chat interface, register it inside your favorite editor extension configurations.
For Cursor (Cursor Settings -> Features -> MCP)
- Name:
local-multi-repo-indexer - Type:
command - Command:
uv --directory "/absolute/path/to/local-code-index" run server.py
For Cline (cline_mcp_settings.json)
Add this configuration snippet inside your mcpServers settings payload:
{
"mcpServers": {
"local-multi-repo-indexer": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/local-code-index",
"run",
"server.py"
],
"disabled": false
}
}
}
š» Integrated VS Code Terminal Shortcuts
To manage and index codebases directly from your editor's built-in terminal, paste these quick-actions into your shell profile config (~/.zshrc or ~/.bashrc):
# Index your current terminal repository folder path
idx() {
TARGET_DIR="\${1:-.}"
ABS_PATH=(cd "TARGET_DIR" && pwd)
echo "ā” Indexing codebase to local vector DB: \$ABS_PATH"
uv --directory "/absolute/path/to/local-code-index" run python -c "import server; print(server.index_repository('\$ABS_PATH'))"
}
# Remove an old or deleted repository from the vector index
idx-rm() {
TARGET_DIR="\${1:-.}"
ABS_PATH=(cd "TARGET_DIR" && pwd)
echo "šļø Removing vector entries for: \$ABS_PATH"
uv --directory "/absolute/path/to/local-code-index" run python -c "import server; print(server.delete_repository('\$ABS_PATH'))"
}
# Query across all repositories globally
idx-find() {
uv --directory "/absolute/path/to/local-code-index" run python -c "import server; print(server.search_all_codebases('\$1'))"
}
Run source ~/.zshrc or source ~/.bashrc to update your active shell context.
š„ Practical Examples & Usage
Workflow 1: From the Integrated Terminal
Simply step into any repository folder on your system and type idx:
cd ~/dev/projects/my-nest-api
idx
# Output: Success: Codebase 'my-nest-api' indexed completely (420 nodes with basic vector direct lookup).
If you want to run a quick query across everything you've saved:
idx-find "JwtAuthGuard validation logic"
Workflow 2: Conversational Prompts via AI Agents (Cursor / Cline)
Once the server status bar is green inside your editor panel, the underlying LLM gains access to your protocol tools natively. You can now use fluid language to ask complex architectural questions.
š” Example 1: Isolating Features in a Specific Repo
User: "Check my
payment-servicerepo. Do we have a specific method handling webhook signatures?"AI Interaction: The model implicitly runs
search_codebaseagainst your project, targeting keyword vectors. It receives the whole relevant function block and returns a complete synthesis of your webhook logic.
š” Example 2: Cross-Repository Code Archeology
User: "I need to implement a data-stream handler in this repo. Scan all our indexed codebases to see if we've written a reuseable utility class for this elsewhere so I can copy its pattern."
AI Interaction: The model triggers
search_all_codebasesto search across your microservices. It highlights a match found under ashared-java-utilsdirectory, complete with its accompanying Javadocs.
š” Example 3: Auditing Active Deployments
User: "List our indexed repositories and tell me which ones are running on our old database schema patterns."
AI Interaction: The model runs
list_indexed_repositoriesto find all your project paths and walks through them to identify outdated code conventions.
š Security & Performance Exclusions
To safeguard memory, protect confidential keys, and maximize performance, files that match the following attributes are omitted from processing:
- Directories Skipped:
.git,.github,node_modules,dist,build,.vscode,target,bin,vendor. - Extensions Tracked:
.js,.jsx,.ts,.tsx,.java. - Blacklisted Configuration Profiles:
package-lock.json,.env,.env.local,tsconfig.json. - Size Caps: Any source code file larger than 2MB is automatically skipped to prevent execution bottlenecks.
š” How the Safeguard Works
- Context Window Safety: The default token budget for single-repo searches is set to
4000tokens, and global cross-repo searches are capped at6000tokens. - Dynamic Truncation: When the model requests information, the server maps out the top search matches. If a large block threatens to exceed the remaining budget, the engine stops adding data and appends a clean warning flag (
ā ļø WARNING: Global cross-repo results truncated...). - Model Autonomy: Because these limits are exposed as parameterized inputs (
token_budget: int = 6000), sophisticated AI agents like Cursor or Cline can choose to scale the budget up or down depending on their specific model limits.
Your multi-repo local indexer is now complete, optimized, and fully protected against token overflow issues. If you would like to proceed, let me know if you need help setting up a daily automated task to automatically refresh modified code definitions across your workspace.
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.