Content
# code-rag-mcp
[](https://myhits.vercel.app)
[](https://docs.anthropic.com/en/docs/claude-code)
[](https://modelcontextprotocol.io)
[](https://www.python.org)
## Overview
A local embedding-based code search MCP plugin.
Once a project is indexed, you can search the code base in natural language in Claude Code,
and also ask code questions by mentioning a bot in Slack.
<br>
<br>
It runs locally without external APIs, using the **Jina Code Embeddings 1.5B model** to create embeddings and store them in ChromaDB.
It automatically detects the type of query (natural language/code/error) and changes the search strategy,
so it can handle natural language queries like "How is the login logic?" as well as stack trace-based questions.
<br>
## Key Features
- **Natural Language Code Search**: Find relevant code with questions like "How is the login logic?"
- **AST-based Code Chunking**: Meaningfully split code into functions/classes using tree-sitter
- **Local Embedding**: Create embeddings locally without external APIs (Jina Code Embeddings 1.5B)
- **Automatic Query Type Detection**: Choose search strategy based on query type (natural language/code/error)
- **Claude Code Integration**: Search directly from Claude Code using MCP server
- **Slack Bot**: Ask code questions by mentioning a bot in Slack
- **Multi-Project**: Index multiple projects and search by project or globally
<br>
## How It Works
```
1. Indexing (preparation, one-time)
Project source code
→ chunker (AST parsing for function/class-level splitting)
→ indexer (create vectors with Jina Code Embeddings)
→ ChromaDB (store vectors)
2. Search
Natural language query
→ query type detection (nl2code / code2code / techqa)
→ convert query to vector
→ cosine similarity search in ChromaDB
→ return relevant code + confidence
```
<br>
## Installation
### Step 1: Marketplace Registration
Add the marketplace in Claude Code:
```
/plugin marketplace add DongLab-DevTools/code-rag-mcp
```
### Step 2: Plugin Installation
```
/plugin install code-rag-mcp
```
### Step 3: Initial Setup
Python/package installation and embedding model (~3GB) download will be performed once:
```
/init
```
### Step 4: Project Indexing
```
/project-add
```
Enter the project name and path, and it will be automatically indexed,
and a slash command `/search-{name}` will be created.
<br>
### Manual Installation
```bash
git clone https://github.com/DongLab-DevTools/code-rag-mcp.git
cd code-rag-mcp
./init.sh # Automatic setup for Python/venv/packages/model
```
<br>
### Requirements
- **Python 3.10 or higher** (if not available, `init.sh` will automatically install with Homebrew)
- **macOS + Homebrew** (manual Python installation required for Linux/Windows)
- **Disk space 4GB+** (Jina model weights ~3GB + venv)
- **Claude Code CLI** (optional, used for Slack bot response generation)
<br>
## Usage
### Search in Claude Code
Search using the slash command created after indexing:
```
/search-myapp How is the login logic?
/search-myapp payment flow
/search-myapp token renewal in Retrofit interceptor
```
You can also ask in natural language without a command:
```
Find the API for modifying user profile in myapp
Find the Repository pattern implementation in the entire project
```
<br>
### Use as a Slack Bot
Create a `.env` file in the project root:
```
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
```
Start the server:
```bash
./start.sh # background execution
./start.sh --log # foreground (real-time log output)
./stop.sh # shutdown
```
Mention in Slack:
```
@code-rag-mcp How is the login logic?
@code-rag-mcp myapp user information query code
```
Refer to [SETUP.md](./SETUP.md) for detailed Slack app setup.
<br>
### Direct CLI Usage
```bash
source venv/bin/activate
# Indexing
python analysis/indexer.py --name myapp /path/to/project
# List indexed projects
python analysis/indexer.py --list
# Interactive search
python analysis/search.py
```
<br>
## Supported Project Types
| Type | Language | Parser | Chunking Criteria |
|------|------|------|------------------|
| Android | Kotlin, Java | tree-sitter-kotlin, tree-sitter-java | [CHUNKING.md](analysis/chunkers/android/CHUNKING.md) |
| iOS | Swift | tree-sitter-swift | [CHUNKING.md](analysis/chunkers/ios/CHUNKING.md) |
| Common | Settings, documents, XML, etc. | — | [CHUNKING.md](analysis/chunkers/common/CHUNKING.md) |
In all project types, files other than binaries are read as text and indexed.
<br>
## Adding New Project Types
Example: Adding TypeScript support
**1. Create a chunker file** — `analysis/chunkers/web/typescript.py`
```python
import tree_sitter_typescript as ts_typescript
from tree_sitter import Language, Parser
from analysis.chunkers.base import CodeChunk, extract_chunks_from_tree
TYPESCRIPT_LANGUAGE = Language(ts_typescript.language())
typescript_parser = Parser(TYPESCRIPT_LANGUAGE)
CLASS_NODE_TYPES = {"class_declaration", "interface_declaration", ...}
MEMBER_TYPES = {"method_definition", "public_field_definition", ...}
TOP_LEVEL_TYPES = {"function_declaration", "lexical_declaration"} | CLASS_NODE_TYPES
BODY_TYPES = {"class_body", "interface_body"}
def chunk_typescript(file_path: str) -> list[CodeChunk]:
with open(file_path, "r", encoding="utf-8", errors="replace") as f:
source_bytes = f.read().encode("utf-8")
tree = typescript_parser.parse(source_bytes)
return extract_chunks_from_tree(
tree, source_bytes, file_path,
CLASS_NODE_TYPES, TOP_LEVEL_TYPES, MEMBER_TYPES, BODY_TYPES,
)
```
**2. Add export to `__init__.py`** — `analysis/chunkers/web/__init__.py`
```python
from analysis.chunkers.web.typescript import chunk_typescript
```
**3. Add extension branching to `chunker.py`**
```python
elif ext in (".ts", ".tsx"):
chunks = chunk_typescript(full_path)
```
**4. Install package**
```bash
pip install tree-sitter-typescript
```
**5. Write CHUNKING.md** — `analysis/chunkers/web/CHUNKING.md`
<br>
## Tech Stack
| Component | Used |
|------|------|
| Embedding | Jina Code Embeddings 1.5B (local) |
| Vector DB | ChromaDB |
| Code Parsing | tree-sitter |
| MCP Server | FastMCP |
| API Server | FastAPI |
| Slack Bot | slack-bolt (Socket Mode) |
| Response Generation | Claude CLI |
<br>
## Project Structure
```
code-rag-mcp/
├── analysis/ # Code analysis engine
│ ├── chunker.py # Entry point (chunk_project)
│ ├── chunkers/ # Project type-specific chunking
│ │ ├── android/ # Kotlin, Java
│ │ ├── ios/ # Swift
│ │ └── common/ # Settings, documents, resources
│ ├── indexer.py # Create embeddings + store in vector DB
│ └── search.py # Search in vector DB
├── server/ # Server
│ ├── mcp_server.py # MCP server (Claude Code integration)
│ ├── api_server.py # REST API
│ └── slack_bot.py # Slack bot
├── skills/ # Claude Code slash commands (/init, /project-add ...)
├── .claude-plugin/ # Claude Code plugin manifest + marketplace definition
├── init.sh # Initial setup (Python/venv/packages/model)
├── start.sh / stop.sh # Server start/stop
└── SETUP.md # Detailed setup guide
```
<br>
## Contributors
<!-- readme: collaborators,contributors -start -->
<table>
<tbody>
<tr>
<td align="center">
<a href="https://github.com/dongx0915">
<img src="https://avatars.githubusercontent.com/u/63500239?v=4" width="100;" alt="dongx0915"/>
<br />
<sub><b>Donghyeon Kim</b></sub>
</a>
</td>
</tr>
<tbody>
</table>
<!-- readme: collaborators,contributors -end -->
Connection Info
You Might Also Like
No recommendations available