Skip to main content
Glama
LocalCodeRAG-MCP

LocalCodeRAG-MCP

README.md
<p align="center">
  <img src="assets/localcoderag-mcp-logo-512.png" alt="LocalCodeRAG-MCP Logo" width="160" />
</p>

# LocalCodeRAG-MCP

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Offline: 100%](https://img.shields.io/badge/Offline-100%25%20Air--Gapped-success.svg)]()
[![Protocol: MCP](https://img.shields.io/badge/MCP-2024--11--05-blueviolet.svg)](https://modelcontextprotocol.io/)
[![Latency: Sub-10ms](https://img.shields.io/badge/Latency-Sub--10ms-brightgreen.svg)]()

> **100% Offline, Zero-Network Hybrid AST Code Retrieval Engine for AI Coding Assistants (Claude Code, Cursor, Windsurf).**

---

## Why LocalCodeRAG-MCP?

Traditional retrieval solutions for code either **leak intellectual property** to cloud embedding APIs (OpenAI, Voyage, Cohere) or rely on **brittle regex search** that lacks semantic relevance.

**LocalCodeRAG-MCP** solves both problems:
1. **Zero Cloud Egress:** 100% air-gapped; runs entirely in local Python and embedded SQLite. Zero API keys, zero network connections.
2. **AST-Boundary Chunking:** Chunks source files along syntactic boundaries (classes, functions, async methods, module docstrings) rather than arbitrary line counts.
3. **Reciprocal Rank Fusion (RRF):** Fuses SQLite FTS5 BM25 full-text keyword ranking with local sub-word feature-hashed dense vector embeddings ($k=60$).
4. **Sub-10ms Latency:** Delivers instantaneous semantic code lookups in 2ms to 8ms.

---

## Architecture

```
                  +---------------------------------------+
                  |  AI Coding Assistant (Claude, Cursor) |
                  +---------------------------------------+
                                      |
                           JSON-RPC 2.0 (stdio)
                                      v
                  +---------------------------------------+
                  |            LocalCodeRAG-MCP           |
                  +---------------------------------------+
                     /                |                \
                    v                 v                 v
          +-----------------+ +---------------+ +---------------+
          | AST Code Chunker| | Local Embedder| | RRF Ranker    |
          | (Classes/Funcs) | | (128-dim L2)  | | 1/(60+r)      |
          +-----------------+ +---------------+ +---------------+
                     \                |                /
                      +---------------+---------------+
                                      |
                                      v
                  +---------------------------------------+
                  |       SQLite FTS5 Embedded Store      |
                  |             (.coderag.db)             |
                  +---------------------------------------+
```

---

## Flagship MCP Tools

| Tool | Purpose | Latency |
| :--- | :--- | :--- |
| `local_index_codebase` | Recursively chunks and indexes repositories into SQLite FTS5 + vector tables | ~10-20 ms/file |
| `local_search_hybrid` | Reciprocal Rank Fusion of BM25 lexical search and dense cosine similarity | < 8 ms |
| `local_find_definition` | Exact & prefix AST symbol lookup with line ranges and parameters | < 2 ms |
| `local_find_references` | Cross-repository caller and reference discovery | < 5 ms |
| `local_codebase_stats` | Database health metrics (total chunks, functions, classes, file size) | < 1 ms |

---

## Installation & Setup

### 1. Install via pip
```bash
pip install -e .
```

### 2. Standalone CLI Usage
```bash
# Index current repository
coderag index .

# Execute hybrid search
coderag search "AST chunker for functions and classes"

# Locate a symbol definition
coderag def LocalHybridSearchEngine

# View index metrics
coderag stats
```

### 3. Connect to Claude Code
Add to your `~/.claude.json`:
```json
{
  "mcpServers": {
    "localcoderag": {
      "command": "python",
      "args": ["-m", "localcoderag.cli", "serve", "--db", ".coderag.db"]
    }
  }
}
```

### 4. Connect to Cursor
Add to your `.cursor/mcp.json`:
```json
{
  "mcpServers": {
    "localcoderag": {
      "command": "python",
      "args": ["-m", "localcoderag.cli", "serve"]
    }
  }
}
```

---

## Verification & Benchmarks

Run the built-in test suite:
```bash
pytest tests/ -v
```

Run the live interactive demonstration:
```bash
python examples/run_coderag_demo.py
```

### Benchmark Results
- **Codebase Indexing:** 17 files (70 AST chunks, 44 functions, 9 classes) indexed in **129.6 ms**.
- **Search Latency:** Hybrid RRF search executed in **5.23 ms**.
- **Database Footprint:** 4.0 KB SQLite file.

---

## Author & Engineering Leadership

**Chethan Raj D S**  
*Technical Lead / Hands-on Engineering Leader / Principal Solutions Architect*  
- **IIT Delhi Executive CTO Alumnus**
- **B.E. in Electrical & Electronics Engineering (85.60%)**
- GitHub: [@Chethan-Raj-D-S](https://github.com/Chethan-Raj-D-S)
- LinkedIn: [chethan-raj-b511ba1b](https://www.linkedin.com/in/chethan-raj-b511ba1b)

---

## License

This project is licensed under the [MIT License](LICENSE).