Skip to content

Commit 4f949cb

Browse files
authored
Merge pull request #4 from Helweg/feature/mcp-server
feat: add MCP server for Cursor, Claude Code, and Windsurf support
2 parents d73de49 + cdc0f38 commit 4f949cb

File tree

16 files changed

+2654
-20
lines changed

16 files changed

+2654
-20
lines changed

AGENTS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ cd native && cargo build --release && napi build --release --platform
3636
```
3737
src/
3838
├── index.ts # Plugin entry: exports tools + slash commands
39+
├── mcp-server.ts # MCP server: wraps Indexer for Cursor/Claude Code/Windsurf
40+
├── cli.ts # CLI entry point for MCP stdio transport
3941
├── config/ # Config schema (Zod) + parsing
4042
├── embeddings/ # Provider detection (auto/github/openai/google/ollama)
4143
├── indexer/ # Core: Indexer class, delta tracking
@@ -72,6 +74,7 @@ skill/ # OpenCode skill guidance
7274
| Add database operation | `native/src/db.rs` + expose in `lib.rs` |
7375
| Add slash command | `commands/` + register in `src/index.ts` config() |
7476

77+
| Add/modify MCP tool | `src/mcp-server.ts` (createMcpServer) |
7578
## CODE MAP
7679

7780
### TypeScript Exports (`src/index.ts`)
@@ -87,6 +90,16 @@ skill/ # OpenCode skill guidance
8790
| `index_metrics` | Tool | Get performance metrics (requires debug.enabled + debug.metrics) |
8891
| `index_logs` | Tool | Get debug logs (requires debug.enabled) |
8992

93+
94+
### MCP Server Exports (`src/mcp-server.ts`)
95+
| Symbol | Type | Purpose |
96+
|--------|------|---------|
97+
| `createMcpServer` | fn | Creates MCP Server with 8 tools + 4 prompts, lazy Indexer init |
98+
99+
### CLI Entry (`src/cli.ts`)
100+
| Symbol | Type | Purpose |
101+
|--------|------|---------|
102+
| `main` | fn | Parses --project/--config args, starts stdio transport, handles shutdown |
90103
### Rust NAPI Exports (`native/src/lib.rs`)
91104
| Symbol | Type | Purpose |
92105
|--------|------|---------|
@@ -204,6 +217,7 @@ afterEach(() => { fs.rmSync(tempDir, { recursive: true, force: true }); });
204217
| `commands.test.ts` | Slash command loader, frontmatter parsing |
205218
| `logger.test.ts` | Logger utility, metrics collection |
206219

220+
| `mcp-server.test.ts` | MCP server: tool/prompt registration, execution via InMemoryTransport |
207221
### Benchmarks
208222
```bash
209223
npx tsx benchmarks/run.ts # Performance testing for native operations

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
> **Stop grepping for concepts. Start searching for meaning.**
1010
11-
**opencode-codebase-index** brings semantic understanding to your [OpenCode](https://opencode.ai) workflow. Instead of guessing function names or grepping for keywords, ask your codebase questions in plain English.
11+
**opencode-codebase-index** brings semantic understanding to your [OpenCode](https://opencode.ai) workflow — and now to any MCP-compatible client like Cursor, Claude Code, and Windsurf. Instead of guessing function names or grepping for keywords, ask your codebase questions in plain English.
1212

1313
## 🚀 Why Use This?
1414

1515
- 🧠 **Semantic Search**: Finds "user authentication" logic even if the function is named `check_creds`.
1616
-**Blazing Fast Indexing**: Powered by a Rust native module using `tree-sitter` and `usearch`. Incremental updates take milliseconds.
1717
- 🌿 **Branch-Aware**: Seamlessly handles git branch switches — reuses embeddings, filters stale results.
1818
- 🔒 **Privacy Focused**: Your vector index is stored locally in your project.
19-
- 🔌 **Model Agnostic**: Works out-of-the-box with GitHub Copilot, OpenAI, Gemini, or local Ollama models.
19+
🔌 **Model Agnostic**: Works out-of-the-box with GitHub Copilot, OpenAI, Gemini, or local Ollama models.
20+
🌐 **MCP Server**: Use with Cursor, Claude Code, Windsurf, or any MCP-compatible client — index once, search from anywhere.
2021

2122
## ⚡ Quick Start
2223

@@ -39,6 +40,52 @@
3940
Ask:
4041
> "Find the function that handles credit card validation errors"
4142
43+
## 🌐 MCP Server (Cursor, Claude Code, Windsurf, etc.)
44+
45+
Use the same semantic search from any MCP-compatible client. Index once, search from anywhere.
46+
47+
1. **Install dependencies**
48+
```bash
49+
npm install opencode-codebase-index @modelcontextprotocol/sdk zod
50+
```
51+
52+
2. **Configure your MCP client**
53+
54+
**Cursor** (`.cursor/mcp.json`):
55+
```json
56+
{
57+
"mcpServers": {
58+
"codebase-index": {
59+
"command": "npx",
60+
"args": ["opencode-codebase-index-mcp", "--project", "/path/to/your/project"]
61+
}
62+
}
63+
}
64+
```
65+
66+
**Claude Code** (`claude_desktop_config.json`):
67+
```json
68+
{
69+
"mcpServers": {
70+
"codebase-index": {
71+
"command": "npx",
72+
"args": ["opencode-codebase-index-mcp", "--project", "/path/to/your/project"]
73+
}
74+
}
75+
}
76+
```
77+
78+
3. **CLI options**
79+
```bash
80+
npx opencode-codebase-index-mcp --project /path/to/repo # specify project root
81+
npx opencode-codebase-index-mcp --config /path/to/config # custom config file
82+
npx opencode-codebase-index-mcp # uses current directory
83+
```
84+
85+
The MCP server exposes all 8 tools (`codebase_search`, `codebase_peek`, `find_similar`, `index_codebase`, `index_status`, `index_health_check`, `index_metrics`, `index_logs`) and 4 prompts (`search`, `find`, `index`, `status`).
86+
87+
The MCP dependencies (`@modelcontextprotocol/sdk`, `zod`) are optional peer dependencies — they're only needed if you use the MCP server.
88+
4289
## 🔍 See It In Action
4390

4491
**Scenario**: You're new to a codebase and need to fix a bug in the payment flow.
@@ -494,6 +541,8 @@ CI will automatically run tests and type checking on your PR.
494541
```
495542
├── src/
496543
│ ├── index.ts # Plugin entry point
544+
│ ├── mcp-server.ts # MCP server (Cursor, Claude Code, Windsurf)
545+
│ ├── cli.ts # CLI entry for MCP stdio transport
497546
│ ├── config/ # Configuration schema
498547
│ ├── embeddings/ # Provider detection and API calls
499548
│ ├── indexer/ # Core indexing logic + inverted index

0 commit comments

Comments
 (0)