mcp-vector-search 0.12.6__py3-none-any.whl

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 (68) hide show
  1. mcp_vector_search/__init__.py +10 -0
  2. mcp_vector_search/cli/__init__.py +1 -0
  3. mcp_vector_search/cli/commands/__init__.py +1 -0
  4. mcp_vector_search/cli/commands/auto_index.py +397 -0
  5. mcp_vector_search/cli/commands/config.py +393 -0
  6. mcp_vector_search/cli/commands/demo.py +358 -0
  7. mcp_vector_search/cli/commands/index.py +744 -0
  8. mcp_vector_search/cli/commands/init.py +645 -0
  9. mcp_vector_search/cli/commands/install.py +675 -0
  10. mcp_vector_search/cli/commands/install_old.py +696 -0
  11. mcp_vector_search/cli/commands/mcp.py +1182 -0
  12. mcp_vector_search/cli/commands/reset.py +393 -0
  13. mcp_vector_search/cli/commands/search.py +773 -0
  14. mcp_vector_search/cli/commands/status.py +549 -0
  15. mcp_vector_search/cli/commands/uninstall.py +485 -0
  16. mcp_vector_search/cli/commands/visualize.py +1467 -0
  17. mcp_vector_search/cli/commands/watch.py +287 -0
  18. mcp_vector_search/cli/didyoumean.py +500 -0
  19. mcp_vector_search/cli/export.py +320 -0
  20. mcp_vector_search/cli/history.py +295 -0
  21. mcp_vector_search/cli/interactive.py +342 -0
  22. mcp_vector_search/cli/main.py +461 -0
  23. mcp_vector_search/cli/output.py +412 -0
  24. mcp_vector_search/cli/suggestions.py +375 -0
  25. mcp_vector_search/config/__init__.py +1 -0
  26. mcp_vector_search/config/constants.py +24 -0
  27. mcp_vector_search/config/defaults.py +200 -0
  28. mcp_vector_search/config/settings.py +134 -0
  29. mcp_vector_search/core/__init__.py +1 -0
  30. mcp_vector_search/core/auto_indexer.py +298 -0
  31. mcp_vector_search/core/connection_pool.py +360 -0
  32. mcp_vector_search/core/database.py +1214 -0
  33. mcp_vector_search/core/directory_index.py +318 -0
  34. mcp_vector_search/core/embeddings.py +294 -0
  35. mcp_vector_search/core/exceptions.py +89 -0
  36. mcp_vector_search/core/factory.py +318 -0
  37. mcp_vector_search/core/git_hooks.py +345 -0
  38. mcp_vector_search/core/indexer.py +1002 -0
  39. mcp_vector_search/core/models.py +294 -0
  40. mcp_vector_search/core/project.py +333 -0
  41. mcp_vector_search/core/scheduler.py +330 -0
  42. mcp_vector_search/core/search.py +952 -0
  43. mcp_vector_search/core/watcher.py +322 -0
  44. mcp_vector_search/mcp/__init__.py +5 -0
  45. mcp_vector_search/mcp/__main__.py +25 -0
  46. mcp_vector_search/mcp/server.py +733 -0
  47. mcp_vector_search/parsers/__init__.py +8 -0
  48. mcp_vector_search/parsers/base.py +296 -0
  49. mcp_vector_search/parsers/dart.py +605 -0
  50. mcp_vector_search/parsers/html.py +413 -0
  51. mcp_vector_search/parsers/javascript.py +643 -0
  52. mcp_vector_search/parsers/php.py +694 -0
  53. mcp_vector_search/parsers/python.py +502 -0
  54. mcp_vector_search/parsers/registry.py +223 -0
  55. mcp_vector_search/parsers/ruby.py +678 -0
  56. mcp_vector_search/parsers/text.py +186 -0
  57. mcp_vector_search/parsers/utils.py +265 -0
  58. mcp_vector_search/py.typed +1 -0
  59. mcp_vector_search/utils/__init__.py +40 -0
  60. mcp_vector_search/utils/gitignore.py +250 -0
  61. mcp_vector_search/utils/monorepo.py +277 -0
  62. mcp_vector_search/utils/timing.py +334 -0
  63. mcp_vector_search/utils/version.py +47 -0
  64. mcp_vector_search-0.12.6.dist-info/METADATA +754 -0
  65. mcp_vector_search-0.12.6.dist-info/RECORD +68 -0
  66. mcp_vector_search-0.12.6.dist-info/WHEEL +4 -0
  67. mcp_vector_search-0.12.6.dist-info/entry_points.txt +2 -0
  68. mcp_vector_search-0.12.6.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1182 @@
1
+ """MCP integration commands for multiple AI tools."""
2
+
3
+ import json
4
+ import os
5
+ import shutil
6
+ import subprocess
7
+ import sys
8
+ import tomllib
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ import typer
13
+ from rich.console import Console
14
+ from rich.panel import Panel
15
+ from rich.table import Table
16
+
17
+ from ...core.exceptions import ProjectNotFoundError
18
+ from ...core.project import ProjectManager
19
+ from ..didyoumean import create_enhanced_typer
20
+ from ..output import print_error, print_info, print_success, print_warning
21
+
22
+ # Create MCP subcommand app with "did you mean" functionality
23
+ mcp_app = create_enhanced_typer(
24
+ help="""🤖 Manage MCP integration for AI tools
25
+
26
+ Configure mcp-vector-search as an MCP server for various AI coding assistants.
27
+ Each tool has its own configuration format and location.
28
+
29
+ [bold cyan]Supported Tools:[/bold cyan]
30
+ • [green]auggie[/green] - Augment Code AI assistant
31
+ • [green]claude-code[/green] - Claude Code (project-scoped)
32
+ • [green]codex[/green] - OpenAI Codex CLI
33
+ • [green]gemini[/green] - Google Gemini CLI
34
+
35
+ [bold cyan]Quick Start:[/bold cyan]
36
+ 1. List tools: [green]mcp-vector-search mcp list[/green]
37
+ 2. Configure tool: [green]mcp-vector-search mcp <tool>[/green]
38
+ 3. Test setup: [green]mcp-vector-search mcp test[/green]
39
+
40
+ [dim]Use --force to overwrite existing configurations[/dim]
41
+ """
42
+ )
43
+
44
+ console = Console()
45
+
46
+ # Supported AI tools and their configuration details
47
+ SUPPORTED_TOOLS = {
48
+ "auggie": {
49
+ "name": "Auggie",
50
+ "config_path": "~/.augment/settings.json",
51
+ "format": "json",
52
+ "description": "Augment Code AI assistant",
53
+ },
54
+ "claude-code": {
55
+ "name": "Claude Code",
56
+ "config_path": ".mcp.json",
57
+ "format": "json",
58
+ "description": "Claude Code (project-scoped)",
59
+ },
60
+ "codex": {
61
+ "name": "Codex",
62
+ "config_path": "~/.codex/config.toml",
63
+ "format": "toml",
64
+ "description": "OpenAI Codex CLI",
65
+ },
66
+ "gemini": {
67
+ "name": "Gemini",
68
+ "config_path": "~/.gemini/mcp.json",
69
+ "format": "json",
70
+ "description": "Google Gemini CLI",
71
+ },
72
+ }
73
+
74
+
75
+ def get_claude_command() -> str | None:
76
+ """Get the Claude Code command path."""
77
+ # Check if claude command is available
78
+ claude_cmd = shutil.which("claude")
79
+ if claude_cmd:
80
+ return "claude"
81
+
82
+ # Check common installation paths
83
+ possible_paths = [
84
+ "/usr/local/bin/claude",
85
+ "/opt/homebrew/bin/claude",
86
+ os.path.expanduser("~/.local/bin/claude"),
87
+ ]
88
+
89
+ for path in possible_paths:
90
+ if os.path.exists(path) and os.access(path, os.X_OK):
91
+ return path
92
+
93
+ return None
94
+
95
+
96
+ def check_claude_code_available() -> bool:
97
+ """Check if Claude Code is available."""
98
+ claude_cmd = get_claude_command()
99
+ if not claude_cmd:
100
+ return False
101
+
102
+ try:
103
+ result = subprocess.run(
104
+ [claude_cmd, "--version"], capture_output=True, text=True, timeout=10
105
+ )
106
+ return result.returncode == 0
107
+ except (subprocess.TimeoutExpired, FileNotFoundError):
108
+ return False
109
+
110
+
111
+ def get_mcp_server_command(
112
+ project_root: Path, enable_file_watching: bool = True
113
+ ) -> str:
114
+ """Get the command to run the MCP server.
115
+
116
+ Args:
117
+ project_root: Path to the project root directory
118
+ enable_file_watching: Whether to enable file watching (default: True)
119
+ """
120
+ # Always use the current Python executable for project-scoped installation
121
+ python_exe = sys.executable
122
+ watch_flag = "" if enable_file_watching else " --no-watch"
123
+ return f"{python_exe} -m mcp_vector_search.mcp.server{watch_flag} {project_root}"
124
+
125
+
126
+ def get_mcp_server_config_for_tool(
127
+ project_root: Path,
128
+ tool_name: str,
129
+ server_name: str,
130
+ enable_file_watching: bool = True,
131
+ ) -> dict[str, Any]:
132
+ """Generate MCP server configuration for a specific tool."""
133
+ base_config = {
134
+ "command": "uv",
135
+ "args": ["run", "mcp-vector-search", "mcp"],
136
+ "env": {
137
+ "MCP_ENABLE_FILE_WATCHING": "true" if enable_file_watching else "false"
138
+ },
139
+ }
140
+
141
+ if tool_name == "auggie":
142
+ # Auggie uses stdio transport
143
+ return base_config
144
+ elif tool_name == "claude-code":
145
+ # Claude Code requires type: stdio and no cwd
146
+ return {"type": "stdio", **base_config}
147
+ elif tool_name == "codex":
148
+ # Codex uses TOML format with different structure
149
+ return {
150
+ "command": base_config["command"],
151
+ "args": base_config["args"],
152
+ "env": base_config["env"],
153
+ }
154
+ elif tool_name == "gemini":
155
+ # Gemini uses standard format with cwd
156
+ return {**base_config, "cwd": str(project_root.absolute())}
157
+ else:
158
+ # Default configuration
159
+ return {**base_config, "cwd": str(project_root.absolute())}
160
+
161
+
162
+ def create_project_claude_config(
163
+ project_root: Path, server_name: str, enable_file_watching: bool = True
164
+ ) -> None:
165
+ """Create or update project-level .mcp.json file.
166
+
167
+ Args:
168
+ project_root: Path to the project root directory
169
+ server_name: Name for the MCP server
170
+ enable_file_watching: Whether to enable file watching (default: True)
171
+ """
172
+ # Path to .mcp.json in project root (recommended by Claude Code)
173
+ mcp_config_path = project_root / ".mcp.json"
174
+
175
+ # Load existing config or create new one
176
+ if mcp_config_path.exists():
177
+ with open(mcp_config_path) as f:
178
+ config = json.load(f)
179
+ else:
180
+ config = {}
181
+
182
+ # Ensure mcpServers section exists
183
+ if "mcpServers" not in config:
184
+ config["mcpServers"] = {}
185
+
186
+ # Use uv for better compatibility, with proper args structure
187
+ config["mcpServers"][server_name] = {
188
+ "type": "stdio",
189
+ "command": "uv",
190
+ "args": ["run", "mcp-vector-search", "mcp"],
191
+ "env": {
192
+ "MCP_ENABLE_FILE_WATCHING": "true" if enable_file_watching else "false"
193
+ },
194
+ }
195
+
196
+ # Write the config
197
+ with open(mcp_config_path, "w") as f:
198
+ json.dump(config, f, indent=2)
199
+
200
+ print_success("Created project-level .mcp.json with MCP server configuration")
201
+ if enable_file_watching:
202
+ print_info("File watching is enabled for automatic reindexing")
203
+ else:
204
+ print_info("File watching is disabled")
205
+
206
+
207
+ def configure_tool_mcp(
208
+ tool_name: str,
209
+ project_root: Path,
210
+ server_name: str = "mcp-vector-search",
211
+ enable_file_watching: bool = True,
212
+ force: bool = False,
213
+ ) -> bool:
214
+ """Configure MCP integration for a specific AI tool."""
215
+ if tool_name not in SUPPORTED_TOOLS:
216
+ print_error(f"Unsupported tool: {tool_name}")
217
+ print_info(f"Supported tools: {', '.join(SUPPORTED_TOOLS.keys())}")
218
+ return False
219
+
220
+ tool_info = SUPPORTED_TOOLS[tool_name]
221
+ config_path_str = tool_info["config_path"]
222
+
223
+ # Handle path expansion
224
+ if config_path_str.startswith("~/"):
225
+ config_path = Path.home() / config_path_str[2:]
226
+ elif config_path_str.startswith("."):
227
+ config_path = project_root / config_path_str
228
+ else:
229
+ config_path = Path(config_path_str)
230
+
231
+ try:
232
+ if tool_name == "auggie":
233
+ return configure_auggie_mcp(
234
+ config_path, project_root, server_name, enable_file_watching, force
235
+ )
236
+ elif tool_name == "claude-code":
237
+ return configure_claude_code_mcp(
238
+ config_path, project_root, server_name, enable_file_watching, force
239
+ )
240
+ elif tool_name == "codex":
241
+ return configure_codex_mcp(
242
+ config_path, project_root, server_name, enable_file_watching, force
243
+ )
244
+ elif tool_name == "gemini":
245
+ return configure_gemini_mcp(
246
+ config_path, project_root, server_name, enable_file_watching, force
247
+ )
248
+ else:
249
+ print_error(f"Configuration for {tool_name} not implemented yet")
250
+ return False
251
+ except Exception as e:
252
+ print_error(f"Failed to configure {tool_name}: {e}")
253
+ return False
254
+
255
+
256
+ def configure_auggie_mcp(
257
+ config_path: Path,
258
+ project_root: Path,
259
+ server_name: str,
260
+ enable_file_watching: bool,
261
+ force: bool,
262
+ ) -> bool:
263
+ """Configure Auggie MCP integration."""
264
+ # Create backup if file exists
265
+ backup_path = config_path.with_suffix(config_path.suffix + ".backup")
266
+
267
+ # Load existing config or create new one
268
+ if config_path.exists():
269
+ if not force:
270
+ with open(config_path) as f:
271
+ config = json.load(f)
272
+ if config.get("mcpServers", {}).get(server_name):
273
+ print_warning(
274
+ f"MCP server '{server_name}' already exists in Auggie config"
275
+ )
276
+ print_info("Use --force to overwrite")
277
+ return False
278
+ shutil.copy2(config_path, backup_path)
279
+ with open(config_path) as f:
280
+ config = json.load(f)
281
+ else:
282
+ config_path.parent.mkdir(parents=True, exist_ok=True)
283
+ config = {}
284
+
285
+ # Ensure mcpServers section exists
286
+ if "mcpServers" not in config:
287
+ config["mcpServers"] = {}
288
+
289
+ # Get server configuration
290
+ server_config = get_mcp_server_config_for_tool(
291
+ project_root, "auggie", server_name, enable_file_watching
292
+ )
293
+ config["mcpServers"][server_name] = server_config
294
+
295
+ # Write updated config
296
+ with open(config_path, "w") as f:
297
+ json.dump(config, f, indent=2)
298
+
299
+ print_success(f"✅ Configured Auggie at {config_path}")
300
+ return True
301
+
302
+
303
+ def configure_claude_code_mcp(
304
+ config_path: Path,
305
+ project_root: Path,
306
+ server_name: str,
307
+ enable_file_watching: bool,
308
+ force: bool,
309
+ ) -> bool:
310
+ """Configure Claude Code MCP integration."""
311
+ # Use existing function for Claude Code
312
+ if config_path.exists() and not force:
313
+ with open(config_path) as f:
314
+ config = json.load(f)
315
+ if config.get("mcpServers", {}).get(server_name):
316
+ print_warning(
317
+ f"MCP server '{server_name}' already exists in Claude Code config"
318
+ )
319
+ print_info("Use --force to overwrite")
320
+ return False
321
+
322
+ create_project_claude_config(project_root, server_name, enable_file_watching)
323
+ print_success(f"✅ Configured Claude Code at {config_path}")
324
+ return True
325
+
326
+
327
+ def configure_codex_mcp(
328
+ config_path: Path,
329
+ project_root: Path,
330
+ server_name: str,
331
+ enable_file_watching: bool,
332
+ force: bool,
333
+ ) -> bool:
334
+ """Configure Codex MCP integration."""
335
+ # Create backup if file exists
336
+ backup_path = config_path.with_suffix(config_path.suffix + ".backup")
337
+
338
+ # Load existing config or create new one
339
+ if config_path.exists():
340
+ if not force:
341
+ try:
342
+ with open(config_path, "rb") as f:
343
+ config = tomllib.load(f)
344
+ if config.get("mcp_servers", {}).get(server_name):
345
+ print_warning(
346
+ f"MCP server '{server_name}' already exists in Codex config"
347
+ )
348
+ print_info("Use --force to overwrite")
349
+ return False
350
+ except Exception as e:
351
+ print_warning(f"Could not parse existing Codex config: {e}")
352
+
353
+ shutil.copy2(config_path, backup_path)
354
+ # Read as text to preserve existing content
355
+ with open(config_path) as f:
356
+ config_text = f.read()
357
+ else:
358
+ config_path.parent.mkdir(parents=True, exist_ok=True)
359
+ config_text = ""
360
+
361
+ # Get server configuration
362
+ server_config = get_mcp_server_config_for_tool(
363
+ project_root, "codex", server_name, enable_file_watching
364
+ )
365
+
366
+ # Generate TOML section for the server
367
+ toml_section = f"\n[mcp_servers.{server_name}]\n"
368
+ toml_section += f'command = "{server_config["command"]}"\n'
369
+ toml_section += f"args = {server_config['args']}\n"
370
+
371
+ if server_config.get("env"):
372
+ toml_section += f"\n[mcp_servers.{server_name}.env]\n"
373
+ for key, value in server_config["env"].items():
374
+ toml_section += f'{key} = "{value}"\n'
375
+
376
+ # Append or replace the section
377
+ if f"[mcp_servers.{server_name}]" in config_text:
378
+ # Replace existing section (simple approach)
379
+ lines = config_text.split("\n")
380
+ new_lines = []
381
+ skip_section = False
382
+
383
+ for line in lines:
384
+ if line.strip() == f"[mcp_servers.{server_name}]":
385
+ skip_section = True
386
+ continue
387
+ elif line.strip().startswith("[") and skip_section:
388
+ skip_section = False
389
+ new_lines.append(line)
390
+ elif not skip_section:
391
+ new_lines.append(line)
392
+
393
+ config_text = "\n".join(new_lines) + toml_section
394
+ else:
395
+ config_text += toml_section
396
+
397
+ # Write updated config
398
+ with open(config_path, "w") as f:
399
+ f.write(config_text)
400
+
401
+ print_success(f"✅ Configured Codex at {config_path}")
402
+ return True
403
+
404
+
405
+ def configure_gemini_mcp(
406
+ config_path: Path,
407
+ project_root: Path,
408
+ server_name: str,
409
+ enable_file_watching: bool,
410
+ force: bool,
411
+ ) -> bool:
412
+ """Configure Gemini MCP integration."""
413
+ # Create backup if file exists
414
+ backup_path = config_path.with_suffix(config_path.suffix + ".backup")
415
+
416
+ # Load existing config or create new one
417
+ if config_path.exists():
418
+ if not force:
419
+ with open(config_path) as f:
420
+ config = json.load(f)
421
+ if config.get("mcpServers", {}).get(server_name):
422
+ print_warning(
423
+ f"MCP server '{server_name}' already exists in Gemini config"
424
+ )
425
+ print_info("Use --force to overwrite")
426
+ return False
427
+ shutil.copy2(config_path, backup_path)
428
+ with open(config_path) as f:
429
+ config = json.load(f)
430
+ else:
431
+ config_path.parent.mkdir(parents=True, exist_ok=True)
432
+ config = {}
433
+
434
+ # Ensure mcpServers section exists
435
+ if "mcpServers" not in config:
436
+ config["mcpServers"] = {}
437
+
438
+ # Get server configuration
439
+ server_config = get_mcp_server_config_for_tool(
440
+ project_root, "gemini", server_name, enable_file_watching
441
+ )
442
+ config["mcpServers"][server_name] = server_config
443
+
444
+ # Write updated config
445
+ with open(config_path, "w") as f:
446
+ json.dump(config, f, indent=2)
447
+
448
+ print_success(f"✅ Configured Gemini at {config_path}")
449
+ return True
450
+
451
+
452
+ # Tool-specific commands
453
+ @mcp_app.command("auggie")
454
+ def configure_auggie(
455
+ ctx: typer.Context,
456
+ server_name: str = typer.Option(
457
+ "mcp-vector-search",
458
+ "--name",
459
+ help="Name for the MCP server",
460
+ rich_help_panel="📁 Configuration",
461
+ ),
462
+ force: bool = typer.Option(
463
+ False,
464
+ "--force",
465
+ "-f",
466
+ help="Force installation even if server already exists",
467
+ rich_help_panel="⚙️ Advanced Options",
468
+ ),
469
+ no_watch: bool = typer.Option(
470
+ False,
471
+ "--no-watch",
472
+ help="Disable file watching for automatic reindexing",
473
+ rich_help_panel="⚙️ Advanced Options",
474
+ ),
475
+ ) -> None:
476
+ """🤖 Configure MCP integration for Auggie AI.
477
+
478
+ Sets up mcp-vector-search as an MCP server for Auggie AI assistant.
479
+ Configuration is stored in ~/.augment/settings.json.
480
+
481
+ [bold cyan]Examples:[/bold cyan]
482
+
483
+ [green]Configure with defaults:[/green]
484
+ $ mcp-vector-search mcp auggie
485
+
486
+ [green]Force overwrite existing config:[/green]
487
+ $ mcp-vector-search mcp auggie --force
488
+
489
+ [green]Disable file watching:[/green]
490
+ $ mcp-vector-search mcp auggie --no-watch
491
+ """
492
+ try:
493
+ project_root = ctx.obj.get("project_root") or Path.cwd()
494
+ project_manager = ProjectManager(project_root)
495
+ if not project_manager.is_initialized():
496
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
497
+ raise typer.Exit(1)
498
+
499
+ enable_file_watching = not no_watch
500
+ success = configure_tool_mcp(
501
+ "auggie", project_root, server_name, enable_file_watching, force
502
+ )
503
+
504
+ if success:
505
+ print_info("Auggie will automatically detect the server when restarted")
506
+ else:
507
+ raise typer.Exit(1)
508
+
509
+ except Exception as e:
510
+ print_error(f"Configuration failed: {e}")
511
+ raise typer.Exit(1)
512
+
513
+
514
+ @mcp_app.command("claude-code")
515
+ def configure_claude_code(
516
+ ctx: typer.Context,
517
+ server_name: str = typer.Option(
518
+ "mcp-vector-search",
519
+ "--name",
520
+ help="Name for the MCP server",
521
+ rich_help_panel="📁 Configuration",
522
+ ),
523
+ force: bool = typer.Option(
524
+ False,
525
+ "--force",
526
+ "-f",
527
+ help="Force installation even if server already exists",
528
+ rich_help_panel="⚙️ Advanced Options",
529
+ ),
530
+ no_watch: bool = typer.Option(
531
+ False,
532
+ "--no-watch",
533
+ help="Disable file watching for automatic reindexing",
534
+ rich_help_panel="⚙️ Advanced Options",
535
+ ),
536
+ ) -> None:
537
+ """🤖 Configure MCP integration for Claude Code.
538
+
539
+ Creates .mcp.json to enable semantic code search in Claude Code.
540
+ Configuration is project-scoped for team sharing.
541
+
542
+ [bold cyan]Examples:[/bold cyan]
543
+
544
+ [green]Configure with defaults:[/green]
545
+ $ mcp-vector-search mcp claude-code
546
+
547
+ [green]Force overwrite existing config:[/green]
548
+ $ mcp-vector-search mcp claude-code --force
549
+
550
+ [green]Disable file watching:[/green]
551
+ $ mcp-vector-search mcp claude-code --no-watch
552
+ """
553
+ try:
554
+ project_root = ctx.obj.get("project_root") or Path.cwd()
555
+ project_manager = ProjectManager(project_root)
556
+ if not project_manager.is_initialized():
557
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
558
+ raise typer.Exit(1)
559
+
560
+ enable_file_watching = not no_watch
561
+ success = configure_tool_mcp(
562
+ "claude-code", project_root, server_name, enable_file_watching, force
563
+ )
564
+
565
+ if success:
566
+ print_info(
567
+ "Claude Code will automatically detect the server when you open this project"
568
+ )
569
+ else:
570
+ raise typer.Exit(1)
571
+
572
+ except Exception as e:
573
+ print_error(f"Configuration failed: {e}")
574
+ raise typer.Exit(1)
575
+
576
+
577
+ @mcp_app.command("codex")
578
+ def configure_codex(
579
+ ctx: typer.Context,
580
+ server_name: str = typer.Option(
581
+ "mcp-vector-search",
582
+ "--name",
583
+ help="Name for the MCP server",
584
+ rich_help_panel="📁 Configuration",
585
+ ),
586
+ force: bool = typer.Option(
587
+ False,
588
+ "--force",
589
+ "-f",
590
+ help="Force installation even if server already exists",
591
+ rich_help_panel="⚙️ Advanced Options",
592
+ ),
593
+ no_watch: bool = typer.Option(
594
+ False,
595
+ "--no-watch",
596
+ help="Disable file watching for automatic reindexing",
597
+ rich_help_panel="⚙️ Advanced Options",
598
+ ),
599
+ ) -> None:
600
+ """🤖 Configure MCP integration for OpenAI Codex.
601
+
602
+ Sets up mcp-vector-search as an MCP server for OpenAI Codex CLI.
603
+ Configuration is stored in ~/.codex/config.toml.
604
+
605
+ [bold cyan]Examples:[/bold cyan]
606
+
607
+ [green]Configure with defaults:[/green]
608
+ $ mcp-vector-search mcp codex
609
+
610
+ [green]Force overwrite existing config:[/green]
611
+ $ mcp-vector-search mcp codex --force
612
+
613
+ [green]Disable file watching:[/green]
614
+ $ mcp-vector-search mcp codex --no-watch
615
+ """
616
+ try:
617
+ project_root = ctx.obj.get("project_root") or Path.cwd()
618
+ project_manager = ProjectManager(project_root)
619
+ if not project_manager.is_initialized():
620
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
621
+ raise typer.Exit(1)
622
+
623
+ enable_file_watching = not no_watch
624
+ success = configure_tool_mcp(
625
+ "codex", project_root, server_name, enable_file_watching, force
626
+ )
627
+
628
+ if success:
629
+ print_info("Codex will automatically detect the server when restarted")
630
+ else:
631
+ raise typer.Exit(1)
632
+
633
+ except Exception as e:
634
+ print_error(f"Configuration failed: {e}")
635
+ raise typer.Exit(1)
636
+
637
+
638
+ @mcp_app.command("gemini")
639
+ def configure_gemini(
640
+ ctx: typer.Context,
641
+ server_name: str = typer.Option(
642
+ "mcp-vector-search",
643
+ "--name",
644
+ help="Name for the MCP server",
645
+ rich_help_panel="📁 Configuration",
646
+ ),
647
+ force: bool = typer.Option(
648
+ False,
649
+ "--force",
650
+ "-f",
651
+ help="Force installation even if server already exists",
652
+ rich_help_panel="⚙️ Advanced Options",
653
+ ),
654
+ no_watch: bool = typer.Option(
655
+ False,
656
+ "--no-watch",
657
+ help="Disable file watching for automatic reindexing",
658
+ rich_help_panel="⚙️ Advanced Options",
659
+ ),
660
+ ) -> None:
661
+ """🤖 Configure MCP integration for Google Gemini.
662
+
663
+ Sets up mcp-vector-search as an MCP server for Google Gemini CLI.
664
+ Configuration is stored in ~/.gemini/mcp.json.
665
+
666
+ [bold cyan]Examples:[/bold cyan]
667
+
668
+ [green]Configure with defaults:[/green]
669
+ $ mcp-vector-search mcp gemini
670
+
671
+ [green]Force overwrite existing config:[/green]
672
+ $ mcp-vector-search mcp gemini --force
673
+
674
+ [green]Disable file watching:[/green]
675
+ $ mcp-vector-search mcp gemini --no-watch
676
+ """
677
+ try:
678
+ project_root = ctx.obj.get("project_root") or Path.cwd()
679
+ project_manager = ProjectManager(project_root)
680
+ if not project_manager.is_initialized():
681
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
682
+ raise typer.Exit(1)
683
+
684
+ enable_file_watching = not no_watch
685
+ success = configure_tool_mcp(
686
+ "gemini", project_root, server_name, enable_file_watching, force
687
+ )
688
+
689
+ if success:
690
+ print_info("Gemini will automatically detect the server when restarted")
691
+ else:
692
+ raise typer.Exit(1)
693
+
694
+ except Exception as e:
695
+ print_error(f"Configuration failed: {e}")
696
+ raise typer.Exit(1)
697
+
698
+
699
+ # Legacy install command (deprecated)
700
+ @mcp_app.command("install", hidden=True)
701
+ @mcp_app.command("init", hidden=True) # Add 'init' as an alias
702
+ def install_mcp_integration(
703
+ ctx: typer.Context,
704
+ server_name: str = typer.Option(
705
+ "mcp-vector-search",
706
+ "--name",
707
+ help="Name for the MCP server",
708
+ rich_help_panel="📁 Configuration",
709
+ ),
710
+ force: bool = typer.Option(
711
+ False,
712
+ "--force",
713
+ "-f",
714
+ help="Force installation even if server already exists",
715
+ rich_help_panel="⚙️ Advanced Options",
716
+ ),
717
+ no_watch: bool = typer.Option(
718
+ False,
719
+ "--no-watch",
720
+ help="Disable file watching for automatic reindexing",
721
+ rich_help_panel="⚙️ Advanced Options",
722
+ ),
723
+ ) -> None:
724
+ """[DEPRECATED] Use tool-specific commands instead.
725
+
726
+ This command is deprecated. Use the tool-specific commands instead:
727
+
728
+ [bold cyan]New Commands:[/bold cyan]
729
+
730
+ [green]For Auggie:[/green]
731
+ $ mcp-vector-search mcp auggie
732
+
733
+ [green]For Claude Code:[/green]
734
+ $ mcp-vector-search mcp claude-code
735
+
736
+ [green]For Codex:[/green]
737
+ $ mcp-vector-search mcp codex
738
+
739
+ [green]For Gemini:[/green]
740
+ $ mcp-vector-search mcp gemini
741
+ """
742
+ print_warning("⚠️ The 'mcp install' command is deprecated.")
743
+ print_info("Use tool-specific commands instead:")
744
+ print_info(" • mcp-vector-search mcp auggie")
745
+ print_info(" • mcp-vector-search mcp claude-code")
746
+ print_info(" • mcp-vector-search mcp codex")
747
+ print_info(" • mcp-vector-search mcp gemini")
748
+ print_info("")
749
+ print_info("Defaulting to Claude Code configuration...")
750
+
751
+ try:
752
+ project_root = ctx.obj.get("project_root") or Path.cwd()
753
+ project_manager = ProjectManager(project_root)
754
+ if not project_manager.is_initialized():
755
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
756
+ raise typer.Exit(1)
757
+
758
+ enable_file_watching = not no_watch
759
+ success = configure_tool_mcp(
760
+ "claude-code", project_root, server_name, enable_file_watching, force
761
+ )
762
+
763
+ if success:
764
+ print_info(
765
+ "Claude Code will automatically detect the server when you open this project"
766
+ )
767
+
768
+ # Test the server (using project_root for the server command)
769
+ print_info("Testing server startup...")
770
+
771
+ # Get the server command
772
+ server_command = get_mcp_server_command(project_root, enable_file_watching)
773
+ test_process = subprocess.Popen(
774
+ server_command.split(),
775
+ stdin=subprocess.PIPE,
776
+ stdout=subprocess.PIPE,
777
+ stderr=subprocess.PIPE,
778
+ text=True,
779
+ )
780
+
781
+ # Send a simple initialization request
782
+ init_request = {
783
+ "jsonrpc": "2.0",
784
+ "id": 1,
785
+ "method": "initialize",
786
+ "params": {
787
+ "protocolVersion": "2024-11-05",
788
+ "capabilities": {},
789
+ "clientInfo": {"name": "test", "version": "1.0.0"},
790
+ },
791
+ }
792
+
793
+ try:
794
+ test_process.stdin.write(json.dumps(init_request) + "\n")
795
+ test_process.stdin.flush()
796
+
797
+ # Wait for response with timeout
798
+ test_process.wait(timeout=5)
799
+
800
+ if test_process.returncode == 0:
801
+ print_success("✅ MCP server starts successfully")
802
+ else:
803
+ stderr_output = test_process.stderr.read()
804
+ print_warning(f"⚠️ Server startup test inconclusive: {stderr_output}")
805
+
806
+ except subprocess.TimeoutExpired:
807
+ test_process.terminate()
808
+ print_success("✅ MCP server is responsive")
809
+
810
+ # Show available tools
811
+ table = Table(title="Available MCP Tools")
812
+ table.add_column("Tool", style="cyan")
813
+ table.add_column("Description", style="white")
814
+
815
+ table.add_row("search_code", "Search for code using semantic similarity")
816
+ table.add_row(
817
+ "search_similar", "Find code similar to a specific file or function"
818
+ )
819
+ table.add_row(
820
+ "search_context", "Search for code based on contextual description"
821
+ )
822
+ table.add_row(
823
+ "get_project_status", "Get project indexing status and statistics"
824
+ )
825
+ table.add_row("index_project", "Index or reindex the project codebase")
826
+
827
+ if enable_file_watching:
828
+ console.print(
829
+ "\n[green]✅ File watching is enabled[/green] - Changes will be automatically indexed"
830
+ )
831
+ else:
832
+ console.print(
833
+ "\n[yellow]⚠️ File watching is disabled[/yellow] - Manual reindexing required for changes"
834
+ )
835
+
836
+ console.print(table)
837
+
838
+ print_info("\nTo test the integration, run: mcp-vector-search mcp test")
839
+
840
+ except ProjectNotFoundError:
841
+ print_error(f"Project not initialized at {project_root}")
842
+ print_info("Run 'mcp-vector-search init' in the project directory first")
843
+ raise typer.Exit(1)
844
+ except Exception as e:
845
+ print_error(f"Installation failed: {e}")
846
+ raise typer.Exit(1)
847
+
848
+
849
+ @mcp_app.command("list")
850
+ def list_tools() -> None:
851
+ """📋 List supported AI tools and their configuration status.
852
+
853
+ Shows all supported AI tools, their configuration paths, and whether
854
+ they are currently configured with mcp-vector-search.
855
+
856
+ [bold cyan]Examples:[/bold cyan]
857
+
858
+ [green]List all tools:[/green]
859
+ $ mcp-vector-search mcp list
860
+ """
861
+ console.print("\n[bold blue]🤖 Supported AI Tools[/bold blue]\n")
862
+
863
+ table = Table(show_header=True, header_style="bold magenta")
864
+ table.add_column("Tool", style="cyan", no_wrap=True)
865
+ table.add_column("Name", style="white")
866
+ table.add_column("Config Path", style="dim")
867
+ table.add_column("Status", justify="center")
868
+
869
+ for tool_id, tool_info in SUPPORTED_TOOLS.items():
870
+ config_path_str = tool_info["config_path"]
871
+
872
+ # Handle path expansion
873
+ if config_path_str.startswith("~/"):
874
+ config_path = Path.home() / config_path_str[2:]
875
+ elif config_path_str.startswith("."):
876
+ config_path = Path.cwd() / config_path_str
877
+ else:
878
+ config_path = Path(config_path_str)
879
+
880
+ # Check if configured
881
+ status = "❌ Not configured"
882
+ try:
883
+ if config_path.exists():
884
+ if tool_info["format"] == "json":
885
+ with open(config_path) as f:
886
+ config = json.load(f)
887
+ if config.get("mcpServers", {}).get("mcp-vector-search"):
888
+ status = "✅ Configured"
889
+ else:
890
+ status = "⚠️ Config exists"
891
+ elif tool_info["format"] == "toml":
892
+ with open(config_path, "rb") as f:
893
+ config = tomllib.load(f)
894
+ if config.get("mcp_servers", {}).get("mcp-vector-search"):
895
+ status = "✅ Configured"
896
+ else:
897
+ status = "⚠️ Config exists"
898
+ else:
899
+ status = "❌ No config file"
900
+ except Exception:
901
+ status = "❓ Unknown"
902
+
903
+ table.add_row(tool_id, tool_info["name"], str(config_path), status)
904
+
905
+ console.print(table)
906
+ console.print(
907
+ "\n[dim]💡 Use 'mcp-vector-search mcp <tool>' to configure a specific tool[/dim]"
908
+ )
909
+
910
+
911
+ @mcp_app.command("tools")
912
+ def list_tools_alias() -> None:
913
+ """📋 Alias for 'list' command."""
914
+ list_tools()
915
+
916
+
917
+ @mcp_app.command("test")
918
+ def test_mcp_integration(
919
+ ctx: typer.Context,
920
+ server_name: str = typer.Option(
921
+ "mcp-vector-search",
922
+ "--name",
923
+ help="Name of the MCP server to test",
924
+ rich_help_panel="📁 Configuration",
925
+ ),
926
+ ) -> None:
927
+ """🧪 Test the MCP integration.
928
+
929
+ Verifies that the MCP server is properly configured and can start successfully.
930
+ Use this to diagnose integration issues.
931
+
932
+ [bold cyan]Examples:[/bold cyan]
933
+
934
+ [green]Test default server:[/green]
935
+ $ mcp-vector-search mcp test
936
+
937
+ [green]Test custom server:[/green]
938
+ $ mcp-vector-search mcp test --name my-search-server
939
+
940
+ [dim]💡 Tip: Run this after installation to verify everything works.[/dim]
941
+ """
942
+ try:
943
+ # Get project root
944
+ project_root = ctx.obj.get("project_root") or Path.cwd()
945
+
946
+ # Check if Claude Code is available
947
+ if not check_claude_code_available():
948
+ print_error("Claude Code not found. Please install Claude Code first.")
949
+ raise typer.Exit(1)
950
+
951
+ claude_cmd = get_claude_command()
952
+
953
+ # Check if server exists
954
+ print_info(f"Testing MCP server '{server_name}'...")
955
+
956
+ try:
957
+ result = subprocess.run(
958
+ [claude_cmd, "mcp", "get", server_name],
959
+ capture_output=True,
960
+ text=True,
961
+ timeout=10,
962
+ )
963
+
964
+ if result.returncode != 0:
965
+ print_error(f"MCP server '{server_name}' not found.")
966
+ print_info(
967
+ "Run 'mcp-vector-search mcp install' or 'mcp-vector-search mcp init' first"
968
+ )
969
+ raise typer.Exit(1)
970
+
971
+ print_success(f"✅ MCP server '{server_name}' is configured")
972
+
973
+ # Test if we can run the server directly
974
+ print_info("Testing server startup...")
975
+
976
+ server_command = get_mcp_server_command(project_root)
977
+ test_process = subprocess.Popen(
978
+ server_command.split(),
979
+ stdin=subprocess.PIPE,
980
+ stdout=subprocess.PIPE,
981
+ stderr=subprocess.PIPE,
982
+ text=True,
983
+ )
984
+
985
+ # Send a simple initialization request
986
+ init_request = {
987
+ "jsonrpc": "2.0",
988
+ "id": 1,
989
+ "method": "initialize",
990
+ "params": {
991
+ "protocolVersion": "2024-11-05",
992
+ "capabilities": {},
993
+ "clientInfo": {"name": "test", "version": "1.0.0"},
994
+ },
995
+ }
996
+
997
+ try:
998
+ test_process.stdin.write(json.dumps(init_request) + "\n")
999
+ test_process.stdin.flush()
1000
+
1001
+ # Wait for response with timeout
1002
+ test_process.wait(timeout=5)
1003
+
1004
+ if test_process.returncode == 0:
1005
+ print_success("✅ MCP server starts successfully")
1006
+ else:
1007
+ stderr_output = test_process.stderr.read()
1008
+ print_warning(
1009
+ f"⚠️ Server startup test inconclusive: {stderr_output}"
1010
+ )
1011
+
1012
+ except subprocess.TimeoutExpired:
1013
+ test_process.terminate()
1014
+ print_success("✅ MCP server is responsive")
1015
+
1016
+ print_success("🎉 MCP integration test completed!")
1017
+ print_info("You can now use the vector search tools in Claude Code.")
1018
+
1019
+ except subprocess.TimeoutExpired:
1020
+ print_error("Timeout testing MCP server")
1021
+ raise typer.Exit(1)
1022
+
1023
+ except Exception as e:
1024
+ print_error(f"Test failed: {e}")
1025
+ raise typer.Exit(1)
1026
+
1027
+
1028
+ @mcp_app.command("remove")
1029
+ def remove_mcp_integration(
1030
+ ctx: typer.Context,
1031
+ server_name: str = typer.Option(
1032
+ "mcp-vector-search", "--name", help="Name of the MCP server to remove"
1033
+ ),
1034
+ confirm: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
1035
+ ) -> None:
1036
+ """Remove MCP integration from the current project.
1037
+
1038
+ Removes the server configuration from .mcp.json in the project root.
1039
+ """
1040
+ try:
1041
+ # Get project root
1042
+ project_root = ctx.obj.get("project_root") or Path.cwd()
1043
+ mcp_config_path = project_root / ".mcp.json"
1044
+
1045
+ # Check if .mcp.json exists
1046
+ if not mcp_config_path.exists():
1047
+ print_warning(f"No .mcp.json found at {mcp_config_path}")
1048
+ return
1049
+
1050
+ # Load configuration
1051
+ with open(mcp_config_path) as f:
1052
+ config = json.load(f)
1053
+
1054
+ # Check if server exists in configuration
1055
+ if "mcpServers" not in config or server_name not in config["mcpServers"]:
1056
+ print_warning(f"MCP server '{server_name}' not found in .mcp.json")
1057
+ return
1058
+
1059
+ # Confirm removal
1060
+ if not confirm:
1061
+ confirmed = typer.confirm(
1062
+ f"Remove MCP server '{server_name}' from .mcp.json?"
1063
+ )
1064
+ if not confirmed:
1065
+ print_info("Removal cancelled.")
1066
+ return
1067
+
1068
+ # Remove the MCP server from configuration
1069
+ print_info(f"Removing MCP server '{server_name}' from .mcp.json...")
1070
+
1071
+ del config["mcpServers"][server_name]
1072
+
1073
+ # Clean up empty mcpServers section
1074
+ if not config["mcpServers"]:
1075
+ del config["mcpServers"]
1076
+
1077
+ # Write updated configuration
1078
+ with open(mcp_config_path, "w") as f:
1079
+ json.dump(config, f, indent=2)
1080
+
1081
+ print_success(f"✅ MCP server '{server_name}' removed from .mcp.json!")
1082
+ print_info("The server is no longer available for this project")
1083
+
1084
+ except Exception as e:
1085
+ print_error(f"Removal failed: {e}")
1086
+ raise typer.Exit(1)
1087
+
1088
+
1089
+ @mcp_app.command("status")
1090
+ def show_mcp_status(
1091
+ ctx: typer.Context,
1092
+ server_name: str = typer.Option(
1093
+ "mcp-vector-search",
1094
+ "--name",
1095
+ help="Name of the MCP server to check",
1096
+ rich_help_panel="📁 Configuration",
1097
+ ),
1098
+ ) -> None:
1099
+ """📊 Show MCP integration status.
1100
+
1101
+ Displays comprehensive status of MCP integration including Claude Code availability,
1102
+ server configuration, and project status.
1103
+
1104
+ [bold cyan]Examples:[/bold cyan]
1105
+
1106
+ [green]Check integration status:[/green]
1107
+ $ mcp-vector-search mcp status
1108
+
1109
+ [green]Check specific server:[/green]
1110
+ $ mcp-vector-search mcp status --name my-search-server
1111
+
1112
+ [dim]💡 Tip: Use this to verify Claude Code can detect the MCP server.[/dim]
1113
+ """
1114
+ try:
1115
+ # Check if Claude Code is available
1116
+ claude_available = check_claude_code_available()
1117
+
1118
+ # Create status panel
1119
+ status_lines = []
1120
+
1121
+ if claude_available:
1122
+ status_lines.append("✅ Claude Code: Available")
1123
+ else:
1124
+ status_lines.append("❌ Claude Code: Not available")
1125
+ status_lines.append(" Install from: https://claude.ai/download")
1126
+
1127
+ # Check project configuration
1128
+ project_root = ctx.obj.get("project_root") or Path.cwd()
1129
+ mcp_config_path = project_root / ".mcp.json"
1130
+ if mcp_config_path.exists():
1131
+ with open(mcp_config_path) as f:
1132
+ project_config = json.load(f)
1133
+
1134
+ if (
1135
+ "mcpServers" in project_config
1136
+ and server_name in project_config["mcpServers"]
1137
+ ):
1138
+ status_lines.append(
1139
+ f"✅ Project Config (.mcp.json): Server '{server_name}' installed"
1140
+ )
1141
+ server_info = project_config["mcpServers"][server_name]
1142
+ if "command" in server_info:
1143
+ status_lines.append(f" Command: {server_info['command']}")
1144
+ if "args" in server_info:
1145
+ status_lines.append(f" Args: {' '.join(server_info['args'])}")
1146
+ if "env" in server_info:
1147
+ file_watching = server_info["env"].get(
1148
+ "MCP_ENABLE_FILE_WATCHING", "true"
1149
+ )
1150
+ if file_watching.lower() in ("true", "1", "yes", "on"):
1151
+ status_lines.append(" File Watching: ✅ Enabled")
1152
+ else:
1153
+ status_lines.append(" File Watching: ❌ Disabled")
1154
+ else:
1155
+ status_lines.append(
1156
+ f"❌ Project Config (.mcp.json): Server '{server_name}' not found"
1157
+ )
1158
+ else:
1159
+ status_lines.append("❌ Project Config (.mcp.json): Not found")
1160
+
1161
+ # Check project status
1162
+ project_root = ctx.obj.get("project_root") or Path.cwd()
1163
+ project_manager = ProjectManager(project_root)
1164
+
1165
+ if project_manager.is_initialized():
1166
+ status_lines.append(f"✅ Project: Initialized at {project_root}")
1167
+ else:
1168
+ status_lines.append(f"❌ Project: Not initialized at {project_root}")
1169
+
1170
+ # Display status
1171
+ panel = Panel(
1172
+ "\n".join(status_lines), title="MCP Integration Status", border_style="blue"
1173
+ )
1174
+ console.print(panel)
1175
+
1176
+ except Exception as e:
1177
+ print_error(f"Status check failed: {e}")
1178
+ raise typer.Exit(1)
1179
+
1180
+
1181
+ if __name__ == "__main__":
1182
+ mcp_app()