mcp-beacon 0.4.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Wilber Turcios
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.
@@ -0,0 +1,510 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-beacon
3
+ Version: 0.4.0
4
+ Summary: A fast, token-efficient MCP server for codebase search. AST parsing, semantic search, linting, git integration. Multi-language support.
5
+ Author-email: Wilber Turcios <wilberturcios123@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/WilTurcios/mcp-beacon
8
+ Project-URL: Bug Tracker, https://github.com/WilTurcios/mcp-beacon/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Build Tools
15
+ Classifier: Topic :: Text Processing :: Indexing
16
+ Classifier: Topic :: Utilities
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: mcp[cli]>=1.0.0
21
+ Requires-Dist: diskcache
22
+ Requires-Dist: uvicorn
23
+ Requires-Dist: tree-sitter>=0.21.0
24
+ Requires-Dist: gitpython>=3.1.0
25
+ Requires-Dist: ruff>=0.1.0
26
+ Provides-Extra: semantic
27
+ Requires-Dist: sentence-transformers>=2.0.0; extra == "semantic"
28
+ Requires-Dist: chromadb>=0.4.0; extra == "semantic"
29
+ Provides-Extra: lsp
30
+ Requires-Dist: python-lsp-server[all]>=1.7.0; extra == "lsp"
31
+ Provides-Extra: all
32
+ Requires-Dist: sentence-transformers>=2.0.0; extra == "all"
33
+ Requires-Dist: chromadb>=0.4.0; extra == "all"
34
+ Requires-Dist: python-lsp-server[all]>=1.7.0; extra == "all"
35
+ Dynamic: license-file
36
+
37
+ # MCP Beacon
38
+
39
+ **A fast, token-efficient MCP server for codebase search with 30+ tools. Multi-language AST parsing, semantic search, linting, and git integration.**
40
+
41
+ MCP Beacon exposes powerful codebase search tools to AI assistants (OpenCode, Claude Desktop, Cursor, Antigravity, etc.) via the Model Context Protocol. Instead of LLMs writing ad-hoc scripts to explore codebases, they use these optimized tools directly — saving tokens and time.
42
+
43
+ **Author:** Wilber Turcios ([@WilTurcios](https://github.com/WilTurcios))
44
+
45
+ ## Why This Exists
46
+
47
+ LLMs often write ad-hoc Python/bash scripts to explore codebases. This wastes tokens on boilerplate, risks errors, and floods context with raw output. MCP Codebase Searcher replaces that with:
48
+
49
+ - **30+ optimized tools** — search, definitions, AST, git, lint, semantic search, and more
50
+ - **Zero LLM calls** — the MCP server never calls external APIs; your AI client does the thinking
51
+ - **Multi-language** — Python, TypeScript, JavaScript, C#, Rust, Go, Java, Kotlin, and more
52
+ - **Token-efficient** — `ast_structure` returns ~200 tokens instead of ~5000 for full file reads
53
+ - **Persistent semantic search** — ChromaDB index with nomic-embed-text-v1.5 embeddings
54
+
55
+ ## Quick Install
56
+
57
+ ```bash
58
+ pip install mcp-beacon
59
+ ```
60
+
61
+ ### Optional Extras
62
+
63
+ ```bash
64
+ # Semantic search (embeddings + vector database)
65
+ pip install mcp-beacon[semantic]
66
+
67
+ # Full install (semantic + LSP)
68
+ pip install mcp-beacon[all]
69
+ ```
70
+
71
+ Requires Python 3.8+.
72
+
73
+ ### Install from .whl file
74
+
75
+ If you have the package as a `.whl` file (e.g., downloaded or built locally):
76
+
77
+ ```bash
78
+ # Install the base package
79
+ pip install dist/mcp_codebase_searcher-0.4.0-py3-none-any.whl
80
+
81
+ # Install with semantic extras (edit the .whl name if needed)
82
+ pip install "dist/mcp_codebase_searcher-0.4.0-py3-none-any.whl[semantic]"
83
+
84
+ # Install with all extras
85
+ pip install "dist/mcp_codebase_searcher-0.4.0-py3-none-any.whl[all]"
86
+ ```
87
+
88
+ **Building the .whl file:**
89
+
90
+ ```bash
91
+ # Install build tools
92
+ pip install build
93
+
94
+ # Build the package
95
+ python -m build
96
+
97
+ # The .whl file will be in dist/
98
+ ls dist/
99
+ # mcp_codebase_searcher-0.4.0-py3-none-any.whl
100
+ ```
101
+
102
+ **Offline install (no internet):**
103
+
104
+ ```bash
105
+ # Download all dependencies first (on a machine with internet)
106
+ pip download mcp-beacon -d ./packages
107
+
108
+ # Transfer the packages folder to the target machine, then:
109
+ pip install --no-index --find-links=./packages mcp-beacon
110
+ ```
111
+
112
+ ## Installation for MCP Clients
113
+
114
+ ### OpenCode
115
+
116
+ **Local (STDIO)** — `opencode.jsonc`:
117
+ ```json
118
+ {
119
+ "mcp": {
120
+ "codebase-searcher": {
121
+ "type": "local",
122
+ "command": ["python", "-m", "mcp_codebase_search"],
123
+ "enabled": true
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ **Remote (Streamable HTTP)** — `opencode.jsonc`:
130
+ ```json
131
+ {
132
+ "mcp": {
133
+ "codebase-searcher": {
134
+ "type": "remote",
135
+ "url": "http://localhost:8000/mcp"
136
+ }
137
+ }
138
+ }
139
+ ```
140
+
141
+ ### Claude Desktop
142
+
143
+ `claude_desktop_config.json`:
144
+ ```json
145
+ {
146
+ "mcpServers": {
147
+ "codebase-searcher": {
148
+ "command": "python",
149
+ "args": ["-m", "mcp_codebase_search"]
150
+ }
151
+ }
152
+ }
153
+ ```
154
+
155
+ ### Antigravity / Web Clients (SSE)
156
+
157
+ Start the server:
158
+ ```bash
159
+ mcp-searcher-server --transport sse --port 8000
160
+ ```
161
+
162
+ Connect to `http://localhost:8000/sse`.
163
+
164
+ ### With Custom Workspace Root
165
+
166
+ If auto-detection doesn't work, set the env var in your client config:
167
+
168
+ ```json
169
+ {
170
+ "command": "python",
171
+ "args": ["-m", "mcp_codebase_search"],
172
+ "env": {
173
+ "MCP_WORKSPACE_ROOT": "/path/to/your/project"
174
+ }
175
+ }
176
+ ```
177
+
178
+ ## MCP Tools (30+)
179
+
180
+ ### Core Search Tools
181
+
182
+ | Tool | Description | Token Cost |
183
+ |------|-------------|------------|
184
+ | `search_codebase` | Text/regex search with context snippets | Medium |
185
+ | `search_codebase_count` | Count matches per file (no snippets) | Low |
186
+ | `search_codebase_multi` | Multi-query search (single scan) | Low |
187
+ | `search_definitions` | Find function/class definitions by name | Low |
188
+ | `search_by_pattern` | Structural search (signatures, classes) | Low |
189
+ | `search_and_replace` | Search + replace with dry-run preview | Medium |
190
+
191
+ ### AST & Structure Tools
192
+
193
+ | Tool | Description | Token Cost |
194
+ |------|-------------|------------|
195
+ | `ast_structure` | File outline (functions, classes, imports) | **~200 tokens** |
196
+ | `ast_query` | Tree-sitter query for precise structure | Low |
197
+
198
+ ### Reference & Relationship Tools
199
+
200
+ | Tool | Description | Token Cost |
201
+ |------|-------------|------------|
202
+ | `search_imports` | Dependency graph (what imports what) | Low |
203
+ | `search_references` | Find all usages of a function/variable | Medium |
204
+ | `find_tests` | Find tests for a function or uncovered code | Low |
205
+
206
+ ### Git Tools
207
+
208
+ | Tool | Description | Token Cost |
209
+ |------|-------------|------------|
210
+ | `git_blame` | Who wrote each line | Low |
211
+ | `git_history` | Structured commit history | Medium |
212
+ | `git_conflicts` | Find merge conflicts | Low |
213
+ | `git_branches` | List branches | Low |
214
+ | `git_status` | Working tree status | Low |
215
+
216
+ ### Quality Tools
217
+
218
+ | Tool | Description | Token Cost |
219
+ |------|-------------|------------|
220
+ | `lint_code` | Run ruff linter | Low |
221
+ | `lint_fix` | Auto-fix lint issues | Low |
222
+ | `lint_format` | Format code with ruff | Low |
223
+
224
+ ### Semantic Search (Optional)
225
+
226
+ | Tool | Description | Token Cost |
227
+ |------|-------------|------------|
228
+ | `semantic_index` | Build/update semantic index | N/A |
229
+ | `semantic_search` | Search by meaning with embeddings | Low |
230
+ | `semantic_stats` | Index statistics | Low |
231
+
232
+ ### Analysis Tools
233
+
234
+ | Tool | Description | Token Cost |
235
+ |------|-------------|------------|
236
+ | `codebase_summary` | Project overview (languages, files, modules) | Low |
237
+ | `code_metrics` | File sizes, line counts, complexity | Low |
238
+ | `codebase_diff` | Git changes, history, statistics | Medium |
239
+ | `search_docs` | Search documentation and comments | Medium |
240
+ | `find_similar` | Find similar code blocks | Medium |
241
+
242
+ ### File Navigation Tools
243
+
244
+ | Tool | Description | Token Cost |
245
+ |------|-------------|------------|
246
+ | `find_files` | Glob pattern file discovery | Low |
247
+ | `list_files` | Directory listing | Low |
248
+ | `read_file` | Read file content with line ranges | Variable |
249
+
250
+ ## Token Efficiency
251
+
252
+ The `ast_structure` tool is the key win — instead of reading a full file (~5000 tokens), you get a structural outline (~200 tokens) showing functions, classes, methods, and imports with line numbers.
253
+
254
+ | Operation | Traditional | MCP Codebase Searcher | Savings |
255
+ |-----------|-------------|----------------------|---------|
256
+ | Understand file structure | `read_file` (500 lines) | `ast_structure` | **95%** |
257
+ | Find function definition | grep + read | `search_definitions` | **80%** |
258
+ | Find all usages | grep + filter | `search_references` | **70%** |
259
+ | Check test coverage | manual search | `find_tests` | **90%** |
260
+
261
+ ## Workspace Root Detection
262
+
263
+ The server auto-detects the workspace root using this priority:
264
+
265
+ 1. **`MCP_WORKSPACE_ROOT`** env var (set by MCP client config)
266
+ 2. **`WORKSPACE_ROOT`** env var
267
+ 3. **Current working directory** (when the client spawns the server from the project dir)
268
+
269
+ No configuration file is needed. If auto-detection fails, pass absolute paths to tools.
270
+
271
+ ## Transport Configuration
272
+
273
+ The server supports three transport protocols:
274
+
275
+ | Transport | Flag | Use Case |
276
+ |-----------|------|----------|
277
+ | **STDIO** | `--transport stdio` | Claude Desktop, Cursor, local tools (default) |
278
+ | **SSE** | `--transport sse` | Web clients, Antigravity |
279
+ | **Streamable HTTP** | `--transport streamable-http` | OpenCode, modern MCP clients |
280
+
281
+ CLI flags:
282
+ ```bash
283
+ mcp-searcher-server --transport sse --host 127.0.0.1 --port 8000
284
+ ```
285
+
286
+ Environment variables:
287
+ ```bash
288
+ MCP_TRANSPORT=sse MCP_HOST=127.0.0.1 MCP_PORT=8000 mcp-searcher-server
289
+ ```
290
+
291
+ ## CLI Usage
292
+
293
+ The `mcp-searcher` CLI provides direct terminal access without an MCP client:
294
+
295
+ ```bash
296
+ # Search for a function
297
+ mcp-searcher search "def my_function" /path/to/project
298
+
299
+ # Regex search with file filter
300
+ mcp-searcher search "class \w+:" src --regex --file-pattern "*.py"
301
+
302
+ # Case-sensitive search with limited results
303
+ mcp-searcher search "TODO" . --case-sensitive --max-results 10
304
+
305
+ # JSON output
306
+ mcp-searcher search "import" src --output-format json --output-file results.json
307
+ ```
308
+
309
+ **CLI Options:**
310
+ - `--no-cache` — Disable caching for this run
311
+ - `--clear-cache` — Clear all cached data
312
+ - `--cache-dir DIR` — Custom cache directory
313
+ - `--cache-expiry DAYS` — Cache expiry (default: 7)
314
+ - `--cache-size-limit MB` — Cache size limit (default: 100)
315
+ - `--file-pattern GLOB` — Filter by file type (e.g., `*.py`)
316
+ - `--max-results N` — Limit number of results
317
+ - `--output-format FORMAT` — `console`, `json`, or `md`
318
+
319
+ ## Semantic Search Setup
320
+
321
+ Semantic search provides meaning-based code discovery (e.g., "find the authentication handler" finds auth code regardless of naming).
322
+
323
+ ### Install
324
+
325
+ ```bash
326
+ pip install mcp-beacon[semantic]
327
+ ```
328
+
329
+ This installs:
330
+ - `sentence-transformers` — nomic-embed-text-v1.5 model (~200MB)
331
+ - `chromadb` — Persistent vector database
332
+
333
+ ### Usage
334
+
335
+ 1. **Build the index** (first time or after code changes):
336
+ ```
337
+ semantic_index(paths=["/path/to/project"])
338
+ ```
339
+
340
+ 2. **Search by meaning**:
341
+ ```
342
+ semantic_search(query="authentication middleware")
343
+ semantic_search(query="error handling", language="python")
344
+ ```
345
+
346
+ 3. **Check index stats**:
347
+ ```
348
+ semantic_stats()
349
+ ```
350
+
351
+ ### How It Works
352
+
353
+ - Uses **nomic-embed-text-v1.5** (256 dimensions) for embeddings
354
+ - Stores embeddings in **ChromaDB** (persistent at `~/.cache/mcp_codebase_searcher/chroma/`)
355
+ - **Incremental indexing** — only re-embeds changed files (SHA256 tracking)
356
+ - **Task prefixes** — `search_document:` for code, `search_query:` for queries
357
+
358
+ ## Language Support
359
+
360
+ ### Core Tools (regex-based)
361
+ All languages with file extensions: Python, TypeScript, JavaScript, C#, Rust, Go, Java, Kotlin, Ruby, PHP, Swift, C/C++, and more.
362
+
363
+ ### AST Tools (tree-sitter)
364
+ | Language | Package | Status |
365
+ |----------|---------|--------|
366
+ | Python | `tree-sitter-python` | ✅ Full |
367
+ | TypeScript | `tree-sitter-typescript` | ✅ Full |
368
+ | JavaScript | `tree-sitter-javascript` | ✅ Full |
369
+ | C# | `tree-sitter-c-sharp` | ✅ Full |
370
+ | Rust | `tree-sitter-rust` | ✅ Full |
371
+ | Go | `tree-sitter-go` | ✅ Full |
372
+ | Java | `tree-sitter-java` | ✅ Full |
373
+
374
+ ### Linting (ruff)
375
+ Python, TypeScript, JavaScript
376
+
377
+ ## Caching
378
+
379
+ Search results are cached using SQLite (`diskcache`) for faster repeated queries.
380
+
381
+ - **Default location:** `~/.cache/mcp_codebase_searcher`
382
+ - **Default expiry:** 7 days
383
+ - **Default size limit:** 100 MB
384
+
385
+ ## Uninstallation
386
+
387
+ ### Remove the package
388
+
389
+ ```bash
390
+ pip uninstall mcp-beacon
391
+ ```
392
+
393
+ To also remove all optional dependencies:
394
+
395
+ ```bash
396
+ pip uninstall mcp-beacon sentence-transformers chromadb tree-sitter gitpython ruff einops
397
+ ```
398
+
399
+ ### Remove cached data
400
+
401
+ ```bash
402
+ # Search cache (SQLite)
403
+ rm -rf ~/.cache/mcp_codebase_searcher
404
+
405
+ # Semantic search index (ChromaDB embeddings)
406
+ rm -rf ~/.cache/mcp_codebase_searcher/chroma
407
+ ```
408
+
409
+ ### Remove the embeddings model
410
+
411
+ The nomic-embed-text-v1.5 model is stored in Hugging Face's cache:
412
+
413
+ ```bash
414
+ # Remove the model (~200MB)
415
+ rm -rf ~/.cache/huggingface/hub/models--nomic-ai--nomic-embed-text-v1.5
416
+ rm -rf ~/.cache/huggingface/hub/models--nomic-ai--nomic-bert-2048
417
+ ```
418
+
419
+ Or remove the entire Hugging Face cache (⚠️ removes ALL downloaded models):
420
+
421
+ ```bash
422
+ rm -rf ~/.cache/huggingface
423
+ ```
424
+
425
+ ### Remove tree-sitter language packages
426
+
427
+ ```bash
428
+ pip uninstall tree-sitter-python tree-sitter-typescript tree-sitter-javascript \
429
+ tree-sitter-c-sharp tree-sitter-rust tree-sitter-go tree-sitter-java
430
+ ```
431
+
432
+ ### Full cleanup
433
+
434
+ ```bash
435
+ # Remove package + dependencies
436
+ pip uninstall mcp-beacon sentence-transformers chromadb tree-sitter \
437
+ gitpython ruff einops tree-sitter-python tree-sitter-typescript \
438
+ tree-sitter-javascript tree-sitter-c-sharp tree-sitter-rust \
439
+ tree-sitter-go tree-sitter-java
440
+
441
+ # Remove all caches
442
+ rm -rf ~/.cache/mcp_codebase_searcher
443
+ rm -rf ~/.cache/huggingface
444
+ ```
445
+
446
+ ## Project Structure
447
+
448
+ ```
449
+ src/
450
+ ├── mcp_codebase_search.py # MCP server, 30+ tool definitions
451
+ ├── mcp_search.py # Core regex/text search engine + AST patterns
452
+ ├── file_scanner.py # Directory walker with exclusion rules
453
+ ├── cache_manager.py # SQLite-backed disk caching
454
+ ├── workspace.py # Workspace root auto-detection
455
+ ├── mcp_searcher.py # CLI entry point
456
+ ├── output_generator.py # Console/JSON/Markdown output formatting
457
+ ├── ast_tools.py # Tree-sitter AST parsing (multi-language)
458
+ ├── git_tools.py # GitPython integration (blame, history)
459
+ ├── lint_tools.py # Ruff linting integration
460
+ └── semantic_tools.py # Sentence-transformers + ChromaDB
461
+
462
+ tests/
463
+ ├── test_mcp_server.py # MCP tool tests
464
+ ├── test_workspace.py # Workspace detection tests
465
+ ├── test_mcp_search.py # Search engine tests
466
+ ├── test_file_scanner.py # File scanner tests
467
+ ├── test_cache_manager.py # Cache tests
468
+ ├── test_mcp_searcher.py # CLI tests
469
+ └── test_output_generator.py # Output format tests
470
+ ```
471
+
472
+ ## Dependencies
473
+
474
+ ### Core
475
+ ```
476
+ mcp[cli]>=1.0.0
477
+ diskcache
478
+ uvicorn
479
+ tree-sitter>=0.21.0
480
+ gitpython>=3.1.0
481
+ ruff>=0.1.0
482
+ ```
483
+
484
+ ### Optional (Semantic)
485
+ ```
486
+ sentence-transformers>=2.0.0
487
+ chromadb>=0.4.0
488
+ ```
489
+
490
+ ### Optional (LSP)
491
+ ```
492
+ python-lsp-server[all]>=1.7.0
493
+ ```
494
+
495
+ ## Running Tests
496
+
497
+ ```bash
498
+ python -m unittest discover -s tests
499
+ ```
500
+
501
+ ## Building
502
+
503
+ ```bash
504
+ pip install build
505
+ python -m build
506
+ ```
507
+
508
+ ## License
509
+
510
+ MIT License — see [LICENSE](./LICENSE).