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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。