CodeLens MCP
A local MCP server that enables LLM clients like Claude to perform semantic code search and answer questions about a codebase using tree-sitter parsing and sqlite-vec vector storage.
README
CodeLens MCP
CodeLens MCP is a local, repo-aware Model Context Protocol (MCP) server that empowers the LLM client to perform semantic searches and answer questions about your codebase accurately, avoiding hallucinations. By leveraging local tree-sitter parsing and the lightweight sqlite-vec vector store, CodeLens delivers high-precision semantic code retrieval with zero infrastructure overhead.
Architecture
graph TD
A[Codebase] -->|Indexed via tree-sitter| B(Chunker)
B -->|Splits by function/class| C(Embeddings: Gemini text-embedding-004)
C -->|Vector Data| D[(sqlite-vec Store)]
E[The LLM Client] -->|MCP stdio| F[CodeLens MCP Server]
F <-->|Query| D
F -->|semantic_code_search| E
F -->|find_usages| E
F -->|explain_function| E
Setup & Installation
Prerequisites
- Python 3.11+
- Gemini API Key
Installation
-
Clone the repository:
git clone https://github.com/devprashant19/CodeLens_MCP.git cd CodeLens_MCP -
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate pip install -e . -
Configure your API key: Copy
.env.exampleto.envand add your Gemini API key.GEMINI_API_KEY=your_actual_key_here
Indexing a Repository
Before the MCP server can answer queries, you need to index the repository:
codelens index /path/to/your/repo
This process uses incremental indexing: running it again will only re-embed files that have changed, saving API costs and time.
MCP Client Configuration
To connect CodeLens MCP to an MCP client, add this server to your MCP client's config file. For example:
{
"mcpServers": {
"codelens": {
"command": "/path/to/CodeLens_MCP/venv/bin/python",
"args": ["-m", "codelens.server"],
"env": {
"GEMINI_API_KEY": "your_actual_key_here"
}
}
}
}
(On Windows, adjust the command path to \\path\\to\\CodeLens_MCP\\venv\\Scripts\\python.exe)
Design Decisions
- MCP over Custom REST API: Implementing the official Model Context Protocol (MCP) allows seamless integration with existing AI assistants and MCP clients without writing bespoke client-side glue code.
- sqlite-vec over Hosted Vector DB: Since this is a local developer tool, requiring users to spin up Docker containers for Postgres or Chroma adds unnecessary friction.
sqlite-vecprovides fast, local, zero-infra vector search embedded directly into the application. - tree-sitter over Fixed-Size Text Chunking: Code semantics are lost when chunked arbitrarily by character count. By chunking at the function/class boundaries via
tree-sitter, the vector embeddings capture logical boundaries, leading to vastly higher retrieval precision and context relevance.
Evaluation Harness Results
We run an automated evaluation harness testing 20 natural-language queries to ensure the LLM correctly selects the right tools and arguments based solely on their descriptions.
| Metric | Accuracy |
|---|---|
| Tool Selection Accuracy | 100% (20/20) |
| Argument Extraction Accuracy | 100% (20/20) |
(Simulated using Gemini 2.5 Flash as the tool-calling client. See tests/eval_harness.py for full details.)
Known Limitations
- Language Support: Currently only Python and JavaScript/TypeScript are officially supported and tested.
- Cross-file Renames: Tracking cross-file symbol renaming is not supported out of the box; usages are found via text references.
- Windows Python compatibility:
tree-sitter-languagescan occasionally face binary compilation issues on newer Python/Windows setups requiring Visual Studio Build Tools.
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.