local-code-index

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.

Category
Visit Server

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-service repo. Do we have a specific method handling webhook signatures?"

AI Interaction: The model implicitly runs search_codebase against 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_codebases to search across your microservices. It highlights a match found under a shared-java-utils directory, 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_repositories to 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:

  1. Directories Skipped: .git, .github, node_modules, dist, build, .vscode, target, bin, vendor.
  2. Extensions Tracked: .js, .jsx, .ts, .tsx, .java.
  3. Blacklisted Configuration Profiles: package-lock.json, .env, .env.local, tsconfig.json.
  4. Size Caps: Any source code file larger than 2MB is automatically skipped to prevent execution bottlenecks.

šŸ’” How the Safeguard Works

  1. Context Window Safety: The default token budget for single-repo searches is set to 4000 tokens, and global cross-repo searches are capped at 6000 tokens.
  2. 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...).
  3. 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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured