mcp-vector-search 0.15.7__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.

Potentially problematic release.


This version of mcp-vector-search might be problematic. Click here for more details.

Files changed (86) 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/chat.py +534 -0
  6. mcp_vector_search/cli/commands/config.py +393 -0
  7. mcp_vector_search/cli/commands/demo.py +358 -0
  8. mcp_vector_search/cli/commands/index.py +762 -0
  9. mcp_vector_search/cli/commands/init.py +658 -0
  10. mcp_vector_search/cli/commands/install.py +869 -0
  11. mcp_vector_search/cli/commands/install_old.py +700 -0
  12. mcp_vector_search/cli/commands/mcp.py +1254 -0
  13. mcp_vector_search/cli/commands/reset.py +393 -0
  14. mcp_vector_search/cli/commands/search.py +796 -0
  15. mcp_vector_search/cli/commands/setup.py +1133 -0
  16. mcp_vector_search/cli/commands/status.py +584 -0
  17. mcp_vector_search/cli/commands/uninstall.py +404 -0
  18. mcp_vector_search/cli/commands/visualize/__init__.py +39 -0
  19. mcp_vector_search/cli/commands/visualize/cli.py +265 -0
  20. mcp_vector_search/cli/commands/visualize/exporters/__init__.py +12 -0
  21. mcp_vector_search/cli/commands/visualize/exporters/html_exporter.py +33 -0
  22. mcp_vector_search/cli/commands/visualize/exporters/json_exporter.py +29 -0
  23. mcp_vector_search/cli/commands/visualize/graph_builder.py +709 -0
  24. mcp_vector_search/cli/commands/visualize/layout_engine.py +469 -0
  25. mcp_vector_search/cli/commands/visualize/server.py +201 -0
  26. mcp_vector_search/cli/commands/visualize/state_manager.py +428 -0
  27. mcp_vector_search/cli/commands/visualize/templates/__init__.py +16 -0
  28. mcp_vector_search/cli/commands/visualize/templates/base.py +218 -0
  29. mcp_vector_search/cli/commands/visualize/templates/scripts.py +3670 -0
  30. mcp_vector_search/cli/commands/visualize/templates/styles.py +779 -0
  31. mcp_vector_search/cli/commands/visualize.py.original +2536 -0
  32. mcp_vector_search/cli/commands/watch.py +287 -0
  33. mcp_vector_search/cli/didyoumean.py +520 -0
  34. mcp_vector_search/cli/export.py +320 -0
  35. mcp_vector_search/cli/history.py +295 -0
  36. mcp_vector_search/cli/interactive.py +342 -0
  37. mcp_vector_search/cli/main.py +484 -0
  38. mcp_vector_search/cli/output.py +414 -0
  39. mcp_vector_search/cli/suggestions.py +375 -0
  40. mcp_vector_search/config/__init__.py +1 -0
  41. mcp_vector_search/config/constants.py +24 -0
  42. mcp_vector_search/config/defaults.py +200 -0
  43. mcp_vector_search/config/settings.py +146 -0
  44. mcp_vector_search/core/__init__.py +1 -0
  45. mcp_vector_search/core/auto_indexer.py +298 -0
  46. mcp_vector_search/core/config_utils.py +394 -0
  47. mcp_vector_search/core/connection_pool.py +360 -0
  48. mcp_vector_search/core/database.py +1237 -0
  49. mcp_vector_search/core/directory_index.py +318 -0
  50. mcp_vector_search/core/embeddings.py +294 -0
  51. mcp_vector_search/core/exceptions.py +89 -0
  52. mcp_vector_search/core/factory.py +318 -0
  53. mcp_vector_search/core/git_hooks.py +345 -0
  54. mcp_vector_search/core/indexer.py +1002 -0
  55. mcp_vector_search/core/llm_client.py +453 -0
  56. mcp_vector_search/core/models.py +294 -0
  57. mcp_vector_search/core/project.py +350 -0
  58. mcp_vector_search/core/scheduler.py +330 -0
  59. mcp_vector_search/core/search.py +952 -0
  60. mcp_vector_search/core/watcher.py +322 -0
  61. mcp_vector_search/mcp/__init__.py +5 -0
  62. mcp_vector_search/mcp/__main__.py +25 -0
  63. mcp_vector_search/mcp/server.py +752 -0
  64. mcp_vector_search/parsers/__init__.py +8 -0
  65. mcp_vector_search/parsers/base.py +296 -0
  66. mcp_vector_search/parsers/dart.py +605 -0
  67. mcp_vector_search/parsers/html.py +413 -0
  68. mcp_vector_search/parsers/javascript.py +643 -0
  69. mcp_vector_search/parsers/php.py +694 -0
  70. mcp_vector_search/parsers/python.py +502 -0
  71. mcp_vector_search/parsers/registry.py +223 -0
  72. mcp_vector_search/parsers/ruby.py +678 -0
  73. mcp_vector_search/parsers/text.py +186 -0
  74. mcp_vector_search/parsers/utils.py +265 -0
  75. mcp_vector_search/py.typed +1 -0
  76. mcp_vector_search/utils/__init__.py +42 -0
  77. mcp_vector_search/utils/gitignore.py +250 -0
  78. mcp_vector_search/utils/gitignore_updater.py +212 -0
  79. mcp_vector_search/utils/monorepo.py +339 -0
  80. mcp_vector_search/utils/timing.py +338 -0
  81. mcp_vector_search/utils/version.py +47 -0
  82. mcp_vector_search-0.15.7.dist-info/METADATA +884 -0
  83. mcp_vector_search-0.15.7.dist-info/RECORD +86 -0
  84. mcp_vector_search-0.15.7.dist-info/WHEEL +4 -0
  85. mcp_vector_search-0.15.7.dist-info/entry_points.txt +3 -0
  86. mcp_vector_search-0.15.7.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,393 @@
1
+ """Reset and recovery commands for MCP Vector Search."""
2
+
3
+ import asyncio
4
+ import shutil
5
+ from pathlib import Path
6
+
7
+ import typer
8
+ from loguru import logger
9
+ from rich.console import Console
10
+ from rich.panel import Panel
11
+ from rich.prompt import Confirm
12
+
13
+ from ...core.exceptions import DatabaseError, IndexCorruptionError
14
+ from ...core.project import ProjectManager
15
+ from ..output import print_error, print_success, print_warning
16
+
17
+ console = Console()
18
+
19
+ # Create Typer app for reset commands
20
+ reset_app = typer.Typer(
21
+ name="reset",
22
+ help="Reset and recovery operations",
23
+ rich_markup_mode="rich",
24
+ )
25
+
26
+
27
+ @reset_app.command("index")
28
+ def reset_index(
29
+ project_root: Path = typer.Option(
30
+ None,
31
+ "--project-root",
32
+ "-p",
33
+ help="Project root directory",
34
+ ),
35
+ force: bool = typer.Option(
36
+ False,
37
+ "--force",
38
+ "-f",
39
+ help="Skip confirmation prompt",
40
+ ),
41
+ backup: bool = typer.Option(
42
+ True,
43
+ "--backup/--no-backup",
44
+ help="Create backup before resetting",
45
+ ),
46
+ ) -> None:
47
+ """Reset the vector search index (clear corrupted data).
48
+
49
+ This command will:
50
+ - Create a backup of the current index (unless --no-backup)
51
+ - Clear the entire vector database
52
+ - Preserve your configuration settings
53
+
54
+ After reset, run 'mcp-vector-search index' to rebuild.
55
+ """
56
+ root = project_root or Path.cwd()
57
+
58
+ try:
59
+ # Check if project is initialized
60
+ project_manager = ProjectManager(root)
61
+ if not project_manager.is_initialized():
62
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
63
+ raise typer.Exit(1)
64
+
65
+ # Get confirmation unless forced
66
+ if not force:
67
+ console.print(
68
+ Panel(
69
+ "[yellow]⚠️ Warning: This will clear the entire search index![/yellow]\n\n"
70
+ "The following will happen:\n"
71
+ "• All indexed code chunks will be deleted\n"
72
+ "• The vector database will be reset\n"
73
+ "• Configuration settings will be preserved\n"
74
+ f"• {'A backup will be created' if backup else 'No backup will be created'}\n\n"
75
+ "You will need to run 'mcp-vector-search index' afterward to rebuild.",
76
+ title="[red]Index Reset Confirmation[/red]",
77
+ border_style="red",
78
+ )
79
+ )
80
+
81
+ if not Confirm.ask("\nDo you want to proceed?", default=False):
82
+ console.print("[yellow]Reset cancelled[/yellow]")
83
+ raise typer.Exit(0)
84
+
85
+ # Get the database directory
86
+ project_manager.load_config()
87
+ db_path = root / ".mcp_vector_search" / "db"
88
+
89
+ if not db_path.exists():
90
+ print_warning("No index found. Nothing to reset.")
91
+ raise typer.Exit(0)
92
+
93
+ # Create backup if requested
94
+ if backup:
95
+ backup_dir = root / ".mcp_vector_search" / "backups"
96
+ backup_dir.mkdir(exist_ok=True)
97
+
98
+ import time
99
+
100
+ timestamp = int(time.time())
101
+ backup_path = backup_dir / f"db_backup_{timestamp}"
102
+
103
+ try:
104
+ shutil.copytree(db_path, backup_path)
105
+ print_success(f"Created backup at: {backup_path.relative_to(root)}")
106
+ except Exception as e:
107
+ print_warning(f"Could not create backup: {e}")
108
+ if not force:
109
+ if not Confirm.ask("Continue without backup?", default=False):
110
+ console.print("[yellow]Reset cancelled[/yellow]")
111
+ raise typer.Exit(0)
112
+
113
+ # Clear the index
114
+ console.print("[cyan]Clearing index...[/cyan]")
115
+ try:
116
+ shutil.rmtree(db_path)
117
+ db_path.mkdir(parents=True, exist_ok=True)
118
+ print_success("Index cleared successfully!")
119
+ except Exception as e:
120
+ print_error(f"Failed to clear index: {e}")
121
+ raise typer.Exit(1)
122
+
123
+ # Show next steps
124
+ console.print(
125
+ Panel(
126
+ "[green]✅ Index reset complete![/green]\n\n"
127
+ "Next steps:\n"
128
+ "1. Run [cyan]mcp-vector-search index[/cyan] to rebuild the search index\n"
129
+ "2. Or run [cyan]mcp-vector-search watch[/cyan] to start incremental indexing",
130
+ title="[green]Reset Complete[/green]",
131
+ border_style="green",
132
+ )
133
+ )
134
+
135
+ except (DatabaseError, IndexCorruptionError) as e:
136
+ print_error(f"Reset failed: {e}")
137
+ raise typer.Exit(1)
138
+ except Exception as e:
139
+ logger.error(f"Unexpected error during reset: {e}")
140
+ print_error(f"Unexpected error: {e}")
141
+ raise typer.Exit(1)
142
+
143
+
144
+ @reset_app.command("all")
145
+ def reset_all(
146
+ project_root: Path = typer.Option(
147
+ None,
148
+ "--project-root",
149
+ "-p",
150
+ help="Project root directory",
151
+ ),
152
+ force: bool = typer.Option(
153
+ False,
154
+ "--force",
155
+ "-f",
156
+ help="Skip confirmation prompt",
157
+ ),
158
+ ) -> None:
159
+ """Reset everything (index and configuration).
160
+
161
+ This will completely remove all MCP Vector Search data,
162
+ requiring re-initialization with 'mcp-vector-search init'.
163
+ """
164
+ root = project_root or Path.cwd()
165
+
166
+ # Get confirmation unless forced
167
+ if not force:
168
+ console.print(
169
+ Panel(
170
+ "[red]⚠️ DANGER: This will remove ALL MCP Vector Search data![/red]\n\n"
171
+ "The following will be deleted:\n"
172
+ "• All indexed code chunks\n"
173
+ "• The vector database\n"
174
+ "• All configuration settings\n"
175
+ "• All project metadata\n\n"
176
+ "You will need to run 'mcp-vector-search init' to start over.",
177
+ title="[red]Complete Reset Confirmation[/red]",
178
+ border_style="red",
179
+ )
180
+ )
181
+
182
+ if not Confirm.ask("\nAre you absolutely sure?", default=False):
183
+ console.print("[yellow]Reset cancelled[/yellow]")
184
+ raise typer.Exit(0)
185
+
186
+ # Double confirmation for destructive action
187
+ if not Confirm.ask("Type 'yes' to confirm complete reset", default=False):
188
+ console.print("[yellow]Reset cancelled[/yellow]")
189
+ raise typer.Exit(0)
190
+
191
+ # Remove entire .mcp_vector_search directory
192
+ mcp_dir = root / ".mcp_vector_search"
193
+
194
+ if not mcp_dir.exists():
195
+ print_warning("No MCP Vector Search data found. Nothing to reset.")
196
+ raise typer.Exit(0)
197
+
198
+ console.print("[cyan]Removing all MCP Vector Search data...[/cyan]")
199
+ try:
200
+ shutil.rmtree(mcp_dir)
201
+ print_success("All data removed successfully!")
202
+
203
+ console.print(
204
+ Panel(
205
+ "[green]✅ Complete reset done![/green]\n\n"
206
+ "To start using MCP Vector Search again:\n"
207
+ "1. Run [cyan]mcp-vector-search init[/cyan] to initialize the project\n"
208
+ "2. Run [cyan]mcp-vector-search index[/cyan] to index your codebase",
209
+ title="[green]Reset Complete[/green]",
210
+ border_style="green",
211
+ )
212
+ )
213
+ except Exception as e:
214
+ print_error(f"Failed to remove data: {e}")
215
+ raise typer.Exit(1)
216
+
217
+
218
+ @reset_app.command("health")
219
+ async def check_health(
220
+ project_root: Path = typer.Option(
221
+ None,
222
+ "--project-root",
223
+ "-p",
224
+ help="Project root directory",
225
+ ),
226
+ fix: bool = typer.Option(
227
+ False,
228
+ "--fix",
229
+ help="Attempt to fix issues if found",
230
+ ),
231
+ ) -> None:
232
+ """Check the health of the search index.
233
+
234
+ This command will:
235
+ - Verify database connectivity
236
+ - Check for index corruption
237
+ - Validate collection integrity
238
+ - Optionally attempt repairs with --fix
239
+ """
240
+ root = project_root or Path.cwd()
241
+
242
+ try:
243
+ # Check if project is initialized
244
+ project_manager = ProjectManager(root)
245
+ if not project_manager.is_initialized():
246
+ print_error("Project not initialized. Run 'mcp-vector-search init' first.")
247
+ raise typer.Exit(1)
248
+
249
+ console.print("[cyan]Performing health check...[/cyan]\n")
250
+
251
+ # Initialize database
252
+ from ...config.defaults import get_default_cache_path
253
+ from ...core.database import ChromaVectorDatabase
254
+ from ...core.embeddings import create_embedding_function
255
+
256
+ config = project_manager.load_config()
257
+ db_path = root / ".mcp_vector_search" / "db"
258
+
259
+ # Setup embedding function and cache
260
+ cache_dir = get_default_cache_path(root) if config.cache_embeddings else None
261
+ embedding_function, _ = create_embedding_function(
262
+ model_name=config.embedding_model,
263
+ cache_dir=cache_dir,
264
+ cache_size=config.max_cache_size,
265
+ )
266
+
267
+ # Create database instance
268
+ db = ChromaVectorDatabase(
269
+ persist_directory=db_path,
270
+ embedding_function=embedding_function,
271
+ )
272
+
273
+ # Initialize and check health
274
+ try:
275
+ await db.initialize()
276
+ is_healthy = await db.health_check()
277
+
278
+ if is_healthy:
279
+ # Get stats for additional info
280
+ stats = await db.get_stats()
281
+
282
+ console.print(
283
+ Panel(
284
+ f"[green]✅ Index is healthy![/green]\n\n"
285
+ f"Statistics:\n"
286
+ f"• Total chunks: {stats.total_chunks:,}\n"
287
+ f"• Total files: {stats.total_files:,}\n"
288
+ f"• Languages: {', '.join(stats.languages.keys()) if stats.languages else 'None'}\n"
289
+ f"• Index size: {stats.index_size_mb:.2f} MB",
290
+ title="[green]Health Check Passed[/green]",
291
+ border_style="green",
292
+ )
293
+ )
294
+ else:
295
+ console.print(
296
+ Panel(
297
+ "[red]❌ Index health check failed![/red]\n\n"
298
+ "Detected issues:\n"
299
+ "• Index may be corrupted\n"
300
+ "• Database operations failing\n\n"
301
+ f"{'Run with --fix to attempt automatic repair' if not fix else 'Attempting to fix...'}",
302
+ title="[red]Health Check Failed[/red]",
303
+ border_style="red",
304
+ )
305
+ )
306
+
307
+ if fix:
308
+ console.print("\n[cyan]Attempting to repair index...[/cyan]")
309
+ # The health check already attempts recovery
310
+ # Try to reinitialize
311
+ await db.close()
312
+ await db.initialize()
313
+
314
+ # Check again
315
+ is_healthy = await db.health_check()
316
+ if is_healthy:
317
+ print_success("Index repaired successfully!")
318
+ else:
319
+ print_error(
320
+ "Automatic repair failed. "
321
+ "Please run 'mcp-vector-search reset index' followed by 'mcp-vector-search index'"
322
+ )
323
+ raise typer.Exit(1)
324
+ else:
325
+ print_warning(
326
+ "Run 'mcp-vector-search reset health --fix' to attempt automatic repair,\n"
327
+ "or 'mcp-vector-search reset index' to clear and rebuild."
328
+ )
329
+ raise typer.Exit(1)
330
+
331
+ except IndexCorruptionError as e:
332
+ console.print(
333
+ Panel(
334
+ f"[red]❌ Index corruption detected![/red]\n\n"
335
+ f"Error: {e}\n\n"
336
+ "Recommended actions:\n"
337
+ "1. Run [cyan]mcp-vector-search reset index[/cyan] to clear the corrupted index\n"
338
+ "2. Run [cyan]mcp-vector-search index[/cyan] to rebuild",
339
+ title="[red]Corruption Detected[/red]",
340
+ border_style="red",
341
+ )
342
+ )
343
+ raise typer.Exit(1)
344
+
345
+ finally:
346
+ await db.close()
347
+
348
+ except Exception as e:
349
+ logger.error(f"Health check error: {e}")
350
+ print_error(f"Health check failed: {e}")
351
+ raise typer.Exit(1)
352
+
353
+
354
+ # Main reset command that shows subcommands
355
+ @reset_app.callback(invoke_without_command=True)
356
+ def reset_main(ctx: typer.Context) -> None:
357
+ """Reset and recovery operations for MCP Vector Search."""
358
+ if ctx.invoked_subcommand is None:
359
+ console.print(
360
+ Panel(
361
+ "Available reset commands:\n\n"
362
+ "[cyan]mcp-vector-search reset index[/cyan]\n"
363
+ " Reset the search index (preserves config)\n\n"
364
+ "[cyan]mcp-vector-search reset health[/cyan]\n"
365
+ " Check index health and optionally repair\n\n"
366
+ "[cyan]mcp-vector-search reset all[/cyan]\n"
367
+ " Complete reset (removes everything)\n",
368
+ title="Reset Commands",
369
+ border_style="cyan",
370
+ )
371
+ )
372
+
373
+
374
+ # Export for backwards compatibility
375
+ main = reset_main
376
+
377
+
378
+ # Make health check synchronous for CLI
379
+ def health_main(
380
+ project_root: Path = typer.Option(
381
+ None,
382
+ "--project-root",
383
+ "-p",
384
+ help="Project root directory",
385
+ ),
386
+ fix: bool = typer.Option(
387
+ False,
388
+ "--fix",
389
+ help="Attempt to fix issues if found",
390
+ ),
391
+ ) -> None:
392
+ """Check the health of the search index (sync wrapper)."""
393
+ asyncio.run(check_health(project_root, fix))