@esankhan3/code-search-mcp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +333 -0
  3. package/dist/core/ast-graph-builder.js +800 -0
  4. package/dist/core/chunker.js +368 -0
  5. package/dist/core/claude-runner.js +173 -0
  6. package/dist/core/config.js +59 -0
  7. package/dist/core/cross-repo-detector.js +887 -0
  8. package/dist/core/embedder.js +334 -0
  9. package/dist/core/env-config.js +86 -0
  10. package/dist/core/file-walker.js +186 -0
  11. package/dist/core/git-diff.js +160 -0
  12. package/dist/core/graph-metrics.js +233 -0
  13. package/dist/core/indexer.js +552 -0
  14. package/dist/core/project-graph-builder.js +202 -0
  15. package/dist/core/query-classifier.js +144 -0
  16. package/dist/core/query-router.js +210 -0
  17. package/dist/core/rag-evaluator.js +213 -0
  18. package/dist/core/repo-profiler.js +383 -0
  19. package/dist/core/reranker.js +218 -0
  20. package/dist/core/retriever.js +242 -0
  21. package/dist/core/semantic-edge-detector.js +147 -0
  22. package/dist/core/service-mesh-inferrer.js +241 -0
  23. package/dist/core/structural-hasher.js +316 -0
  24. package/dist/core/tree-sitter-parser.js +539 -0
  25. package/dist/core/types.js +0 -0
  26. package/dist/core/vector-store.js +259 -0
  27. package/dist/core/workspace-detector.js +481 -0
  28. package/dist/index.js +177 -0
  29. package/dist/middleware/auth.js +109 -0
  30. package/dist/resources/resources.js +79 -0
  31. package/dist/server.js +242 -0
  32. package/dist/sources/github-org.js +109 -0
  33. package/dist/sources/local-path.js +44 -0
  34. package/dist/tools/graph.js +193 -0
  35. package/dist/tools/index-tools.js +43 -0
  36. package/dist/tools/profile.js +88 -0
  37. package/dist/tools/search.js +84 -0
  38. package/dist/transports/http-transport.js +162 -0
  39. package/dist/transports/remote-proxy.js +152 -0
  40. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Esan Mohammad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ <div align="center">
2
+
3
+ <br/>
4
+
5
+ # Code Search MCP
6
+
7
+ **Multi-repo code intelligence via the Model Context Protocol**
8
+
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](../../LICENSE)
10
+ [![MCP](https://img.shields.io/badge/protocol-MCP%201.0-7C3AED?style=flat-square)](https://modelcontextprotocol.io)
11
+ [![Node](https://img.shields.io/badge/node-%E2%89%A5%2020-339933?style=flat-square&logo=node.js&logoColor=white)]()
12
+ [![Docker](https://img.shields.io/badge/docker-ready-2496ED?style=flat-square&logo=docker&logoColor=white)]()
13
+
14
+ [Quick Start](#quick-start) · [Tools](#tools) · [Deploy](#deployment) · [Configuration](#configuration)
15
+
16
+ </div>
17
+
18
+ ---
19
+
20
+ ## What You Get
21
+
22
+ Ask questions in natural language. The server searches, traces, and analyzes across all your repos.
23
+
24
+ | Query | Tool | Result |
25
+ |:------|:-----|:-------|
26
+ | "How does authentication work across services?" | `search_code` | 8 results from 3 repos, ranked by relevance |
27
+ | "What calls handlePayment?" | `find_callers` | 12 call sites traced across api-gateway and billing-service |
28
+ | "If I change user.ts, what breaks?" | `impact_analysis` | 4 files in 2 repos identified as affected |
29
+
30
+ Works with Claude Code, Claude Desktop, Cursor, and any MCP client.
31
+
32
+ ---
33
+
34
+ ## Architecture
35
+
36
+ ```mermaid
37
+ graph LR
38
+ A[Your AI Client] -- stdio / http --> B[Code Search MCP Server]
39
+ B --> C[LanceDB vectors]
40
+ B --> D[AST Graph]
41
+ B --> E[Git Repos]
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Quick Start
47
+
48
+ <details open>
49
+ <summary><strong>Local mode</strong> -- run on your machine</summary>
50
+
51
+ ```bash
52
+ claude mcp add code-search -- npx @anvil-dev/code-search-mcp --local /path/to/repos
53
+ ```
54
+
55
+ For GitHub orgs:
56
+
57
+ ```bash
58
+ claude mcp add code-search -- npx @anvil-dev/code-search-mcp --local github:your-org --token ghp_xxx
59
+ ```
60
+
61
+ </details>
62
+
63
+ <details>
64
+ <summary><strong>Connect to a team server</strong></summary>
65
+
66
+ **Claude Code:**
67
+
68
+ ```bash
69
+ claude mcp add code-search \
70
+ -e CODE_SEARCH_SERVER=https://your-server:3100 \
71
+ -e CODE_SEARCH_API_KEY=your-api-key \
72
+ -- npx @anvil-dev/code-search-mcp
73
+ ```
74
+
75
+ **Claude Desktop / Cursor (JSON config):**
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "code-search": {
81
+ "command": "code-search-mcp",
82
+ "env": {
83
+ "CODE_SEARCH_SERVER": "https://your-server:3100",
84
+ "CODE_SEARCH_API_KEY": "your-api-key"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ </details>
92
+
93
+ <details>
94
+ <summary><strong>Deploy the server</strong> (Docker)</summary>
95
+
96
+ ```bash
97
+ cp .env.example .env
98
+ docker compose up
99
+ ```
100
+
101
+ Index repos via the admin API (no restart needed):
102
+
103
+ ```bash
104
+ curl -X POST http://localhost:3100/index \
105
+ -H 'Content-Type: application/json' \
106
+ -d '{"path": "/repos/my-service", "project": "my-project"}'
107
+ ```
108
+
109
+ Enable automatic reindexing:
110
+
111
+ ```bash
112
+ CODE_SEARCH_REINDEX_INTERVAL=1h # 0 = disabled (default)
113
+ ```
114
+
115
+ </details>
116
+
117
+ ---
118
+
119
+ ## Tools
120
+
121
+ **Search** -- `search_code` · `search_semantic` · `search_exact`
122
+ Hybrid vector+BM25, semantic-only, and keyword search across all indexed repos.
123
+
124
+ **Graph** -- `get_repo_graph` · `find_callers` · `find_dependencies` · `impact_analysis` · `get_cross_repo_edges`
125
+ AST knowledge graph, caller tracing, dependency lookup, change impact, and cross-repo connections.
126
+
127
+ **Profiles** -- `list_repos` · `get_repo_profile`
128
+ Indexed repo listing and LLM-generated repo profiles with role, stack, and endpoints.
129
+
130
+ **Index** -- `index_status`
131
+ Chunk count, embedding provider, repo list, and last-indexed timestamp.
132
+
133
+ ### Server Admin API
134
+
135
+ | Endpoint | Description |
136
+ |:---------|:------------|
137
+ | `POST /index` | Index repos at a path. Body: `{"path": "...", "project": "...", "force": false}` |
138
+ | `GET /health` | Server status, active sessions, index readiness |
139
+ | `GET /status` | Live indexing progress, phase, percent, history |
140
+
141
+ ---
142
+
143
+ ## Under the Hood
144
+
145
+ <details>
146
+ <summary>Incremental Indexing -- 4-layer cost optimization</summary>
147
+
148
+ | Layer | Scope | What it does |
149
+ |:------|:------|:-------------|
150
+ | 1. Git SHA skip | Repo | Compares HEAD against last indexed SHA; skips unchanged repos |
151
+ | 2. Git diff via Merkle DAG | File | Only processes added/modified/deleted files from `git diff` |
152
+ | 3. Content hash SHA-256 | File | Fallback dedup when git diff is unavailable |
153
+ | 4. Embedding diff against LanceDB | Chunk | Only new/changed chunks sent to the embedding provider |
154
+
155
+ **Before:** 2 files changed out of 1,000 -- re-embed all 1,000 chunks.
156
+ **After:** 2 files changed -- 5 chunks re-embedded, 995 preserved.
157
+
158
+ Scheduled reindexing (`CODE_SEARCH_REINDEX_INTERVAL=1h`) is practical even with paid providers -- most runs complete in seconds with zero API calls.
159
+
160
+ </details>
161
+
162
+ <details>
163
+ <summary>Embedding Providers</summary>
164
+
165
+ | Provider | Env var | Model |
166
+ |:---------|:--------|:------|
167
+ | Ollama (local, free) | `OLLAMA_HOST` | `bge-m3` |
168
+ | Mistral / Codestral | `MISTRAL_API_KEY` | `codestral-embed-2505` |
169
+ | OpenAI | `OPENAI_API_KEY` | `text-embedding-3-large` |
170
+ | Voyage AI | `VOYAGE_API_KEY` | `voyage-code-3` |
171
+ | Gemini | OAuth via `~/.gemini/` | `text-embedding-004` |
172
+ | Any OpenAI-compatible | `CODE_SEARCH_EMBEDDING_BASE_URL` | Custom |
173
+
174
+ **Bring Your Own Provider** -- any service with an OpenAI-compatible `/v1/embeddings` endpoint:
175
+
176
+ ```bash
177
+ CODE_SEARCH_EMBEDDING_PROVIDER=custom
178
+ CODE_SEARCH_EMBEDDING_BASE_URL=https://api.together.xyz
179
+ CODE_SEARCH_EMBEDDING_MODEL=togethercomputer/m2-bert-80M-8k-retrieval
180
+ CODE_SEARCH_EMBEDDING_API_KEY=your-key
181
+ ```
182
+
183
+ </details>
184
+
185
+ <details>
186
+ <summary>LLM Configuration -- repo profiling and service mesh inference</summary>
187
+
188
+ The server uses an LLM for repo profiling and service mesh detection. Mode is auto-detected:
189
+
190
+ - API key present -- `api` mode
191
+ - Claude CLI available -- `cli` mode
192
+ - Neither -- `none` (LLM features disabled)
193
+
194
+ Override with environment variables:
195
+
196
+ ```bash
197
+ CODE_SEARCH_LLM_MODE=api # api | cli | none
198
+ CODE_SEARCH_LLM_API_KEY=sk-...
199
+ CODE_SEARCH_LLM_PROVIDER=anthropic # anthropic | openai | ollama | custom
200
+ ```
201
+
202
+ </details>
203
+
204
+ <details>
205
+ <summary>Cross-Repo Detection -- 14 automatic strategies</summary>
206
+
207
+ npm dependencies, TypeScript shared types, HTTP route matching, Kafka topics, gRPC services, database tables, environment variables, Docker Compose links, Redis keys, S3 buckets, protobuf imports, shared constants, API schemas (OpenAPI/Swagger), and Kubernetes service references.
208
+
209
+ </details>
210
+
211
+ <details>
212
+ <summary>Supported Languages</summary>
213
+
214
+ **Tree-sitter AST parsing:** TypeScript, JavaScript, Go, Python, Rust, Java, PHP, C/C++
215
+
216
+ All other text files are indexed with BM25 keyword search.
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary>Monitoring -- GET /status</summary>
222
+
223
+ ```json
224
+ {
225
+ "indexing": {
226
+ "status": "indexing",
227
+ "phase": "embedding",
228
+ "message": "Embedding: 12/15 new (~3s remaining)",
229
+ "percent": 85,
230
+ "elapsedMs": 4200,
231
+ "lastSuccess": "2026-04-18T14:30:00Z",
232
+ "lastDurationMs": 8500,
233
+ "history": [
234
+ {"type": "start", "message": "auto-reindex: started..."},
235
+ {"type": "complete", "message": "Completed: 1200 chunks, 4 repos in 8s"}
236
+ ]
237
+ }
238
+ }
239
+ ```
240
+
241
+ </details>
242
+
243
+ ---
244
+
245
+ ## Configuration
246
+
247
+ ### Essential
248
+
249
+ | Variable | Role | Description |
250
+ |:---------|:-----|:------------|
251
+ | `CODE_SEARCH_SERVER` | Client | Remote server URL |
252
+ | `CODE_SEARCH_API_KEY` | Client | API key for remote server |
253
+ | `CODE_SEARCH_EMBEDDING_PROVIDER` | Server | `auto` \| `codestral` \| `openai` \| `voyage` \| `ollama` \| `custom` |
254
+ | `CODE_SEARCH_LLM_API_KEY` | Server | API key for LLM provider (repo profiling, service mesh) |
255
+ | `CODE_SEARCH_AUTH_MODE` | Server | `none` \| `api-key` \| `jwt` |
256
+
257
+ <details>
258
+ <summary>Full Configuration Reference</summary>
259
+
260
+ **Server CLI flags:**
261
+
262
+ ```
263
+ code-search-mcp --serve [options]
264
+ --port <port> HTTP port (default: 3100)
265
+ --auth <mode> none | api-key | jwt
266
+ --transport <mode> streamable-http | sse
267
+
268
+ code-search-mcp --local [source] [options]
269
+ --project <name> Project name (default: derived from source)
270
+ --token <token> GitHub token (or GITHUB_TOKEN env)
271
+ --force Force full re-index
272
+ ```
273
+
274
+ **All environment variables:**
275
+
276
+ | Variable | Description | Default |
277
+ |:---------|:------------|:--------|
278
+ | `CODE_SEARCH_TRANSPORT` | Transport mode | `streamable-http` |
279
+ | `CODE_SEARCH_PORT` | HTTP port | `3100` |
280
+ | `CODE_SEARCH_HOST` | Bind address | `0.0.0.0` |
281
+ | `CODE_SEARCH_AUTH_MODE` | Auth mode | `none` |
282
+ | `CODE_SEARCH_AUTH_API_KEYS` | Comma-separated API keys | -- |
283
+ | `CODE_SEARCH_AUTH_JWT_SECRET` | JWT signing secret | -- |
284
+ | `CODE_SEARCH_EMBEDDING_PROVIDER` | Embedding provider | `auto` |
285
+ | `CODE_SEARCH_EMBEDDING_API_KEY` | Unified embedding API key | -- |
286
+ | `CODE_SEARCH_EMBEDDING_BASE_URL` | Custom embedding endpoint | -- |
287
+ | `CODE_SEARCH_EMBEDDING_MODEL` | Custom embedding model | -- |
288
+ | `CODE_SEARCH_RERANKER_PROVIDER` | `ollama` \| `cohere` \| `voyage` \| `custom` \| `none` | `ollama` |
289
+ | `CODE_SEARCH_RERANKER_BASE_URL` | Custom reranker endpoint | -- |
290
+ | `CODE_SEARCH_RERANKER_MODEL` | Custom reranker model | -- |
291
+ | `CODE_SEARCH_DATA_DIR` | Data directory override | -- |
292
+ | `CODE_SEARCH_REINDEX_INTERVAL` | Auto-reindex schedule (`30m`, `1h`, `6h`, `0`) | `0` |
293
+ | `CODE_SEARCH_RATE_LIMIT_PER_MINUTE` | Rate limit per identity | `100` |
294
+ | `CODE_SEARCH_LLM_MODE` | `cli` \| `api` \| `none` | `cli` |
295
+ | `CODE_SEARCH_LLM_PROVIDER` | `anthropic` \| `openai` \| `ollama` \| `custom` | `anthropic` |
296
+ | `CODE_SEARCH_LLM_API_KEY` | API key for LLM provider | -- |
297
+ | `CODE_SEARCH_LLM_MODEL` | Model for profiling + service mesh | `claude-sonnet-4-6` |
298
+ | `CODE_SEARCH_LLM_BASE_URL` | Custom LLM endpoint | -- |
299
+
300
+ </details>
301
+
302
+ ---
303
+
304
+ ## Requirements
305
+
306
+ - **Node.js >= 20**
307
+ - One embedding provider: Ollama (free, local) or any supported API key
308
+
309
+ ```bash
310
+ # Recommended: Ollama for free local embeddings
311
+ brew install ollama && ollama pull bge-m3
312
+ ```
313
+
314
+ ### Authentication Modes
315
+
316
+ | Mode | How it works |
317
+ |:-----|:-------------|
318
+ | `none` | No auth -- process boundary is the security boundary (default for stdio) |
319
+ | `api-key` | `Authorization: Bearer <key>` checked against allowlist |
320
+ | `jwt` | HS256 JWT verification with expiry and issuer validation |
321
+
322
+ ---
323
+
324
+ ## License
325
+
326
+ MIT
327
+
328
+ <div align="center">
329
+ <br/>
330
+
331
+ Built with [Model Context Protocol](https://modelcontextprotocol.io) · [LanceDB](https://lancedb.com) · [Tree-sitter](https://tree-sitter.github.io) · [Graphology](https://graphology.github.io)
332
+
333
+ </div>