hanzo-mcp 0.5.1__py3-none-any.whl → 0.5.2__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 hanzo-mcp might be problematic. Click here for more details.

Files changed (54) hide show
  1. hanzo_mcp/__init__.py +1 -1
  2. hanzo_mcp/tools/__init__.py +135 -4
  3. hanzo_mcp/tools/common/base.py +7 -2
  4. hanzo_mcp/tools/common/stats.py +261 -0
  5. hanzo_mcp/tools/common/tool_disable.py +144 -0
  6. hanzo_mcp/tools/common/tool_enable.py +182 -0
  7. hanzo_mcp/tools/common/tool_list.py +263 -0
  8. hanzo_mcp/tools/database/__init__.py +71 -0
  9. hanzo_mcp/tools/database/database_manager.py +246 -0
  10. hanzo_mcp/tools/database/graph_add.py +257 -0
  11. hanzo_mcp/tools/database/graph_query.py +536 -0
  12. hanzo_mcp/tools/database/graph_remove.py +267 -0
  13. hanzo_mcp/tools/database/graph_search.py +348 -0
  14. hanzo_mcp/tools/database/graph_stats.py +345 -0
  15. hanzo_mcp/tools/database/sql_query.py +229 -0
  16. hanzo_mcp/tools/database/sql_search.py +296 -0
  17. hanzo_mcp/tools/database/sql_stats.py +254 -0
  18. hanzo_mcp/tools/editor/__init__.py +11 -0
  19. hanzo_mcp/tools/editor/neovim_command.py +272 -0
  20. hanzo_mcp/tools/editor/neovim_edit.py +290 -0
  21. hanzo_mcp/tools/editor/neovim_session.py +356 -0
  22. hanzo_mcp/tools/filesystem/__init__.py +15 -5
  23. hanzo_mcp/tools/filesystem/{unified_search.py → batch_search.py} +254 -131
  24. hanzo_mcp/tools/filesystem/find_files.py +348 -0
  25. hanzo_mcp/tools/filesystem/git_search.py +505 -0
  26. hanzo_mcp/tools/llm/__init__.py +27 -0
  27. hanzo_mcp/tools/llm/consensus_tool.py +351 -0
  28. hanzo_mcp/tools/llm/llm_manage.py +413 -0
  29. hanzo_mcp/tools/llm/llm_tool.py +346 -0
  30. hanzo_mcp/tools/llm/provider_tools.py +412 -0
  31. hanzo_mcp/tools/mcp/__init__.py +11 -0
  32. hanzo_mcp/tools/mcp/mcp_add.py +263 -0
  33. hanzo_mcp/tools/mcp/mcp_remove.py +127 -0
  34. hanzo_mcp/tools/mcp/mcp_stats.py +165 -0
  35. hanzo_mcp/tools/shell/__init__.py +27 -7
  36. hanzo_mcp/tools/shell/logs.py +265 -0
  37. hanzo_mcp/tools/shell/npx.py +194 -0
  38. hanzo_mcp/tools/shell/npx_background.py +254 -0
  39. hanzo_mcp/tools/shell/pkill.py +262 -0
  40. hanzo_mcp/tools/shell/processes.py +279 -0
  41. hanzo_mcp/tools/shell/run_background.py +326 -0
  42. hanzo_mcp/tools/shell/uvx.py +187 -0
  43. hanzo_mcp/tools/shell/uvx_background.py +249 -0
  44. hanzo_mcp/tools/vector/__init__.py +5 -0
  45. hanzo_mcp/tools/vector/git_ingester.py +3 -0
  46. hanzo_mcp/tools/vector/index_tool.py +358 -0
  47. hanzo_mcp/tools/vector/infinity_store.py +98 -0
  48. hanzo_mcp/tools/vector/vector_search.py +11 -6
  49. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/METADATA +1 -1
  50. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/RECORD +54 -16
  51. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/WHEEL +0 -0
  52. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/entry_points.txt +0 -0
  53. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/licenses/LICENSE +0 -0
  54. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.5.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,505 @@
1
+ """Git search tool for searching through git history."""
2
+
3
+ import os
4
+ import subprocess
5
+ import re
6
+ from typing import Annotated, TypedDict, Unpack, final, override
7
+
8
+ from fastmcp import Context as MCPContext
9
+ from pydantic import Field
10
+
11
+ from hanzo_mcp.tools.common.base import BaseTool
12
+ from hanzo_mcp.tools.common.context import create_tool_context
13
+ from hanzo_mcp.tools.common.permissions import PermissionManager
14
+
15
+
16
+ Pattern = Annotated[
17
+ str,
18
+ Field(
19
+ description="Search pattern (regex supported)",
20
+ min_length=1,
21
+ ),
22
+ ]
23
+
24
+ SearchPath = Annotated[
25
+ str | None,
26
+ Field(
27
+ description="Path to search in (defaults to current directory)",
28
+ default=None,
29
+ ),
30
+ ]
31
+
32
+ SearchType = Annotated[
33
+ str,
34
+ Field(
35
+ description="Type of git search: 'commits', 'content', 'diff', 'log', 'blame'",
36
+ default="content",
37
+ ),
38
+ ]
39
+
40
+ CaseSensitive = Annotated[
41
+ bool,
42
+ Field(
43
+ description="Case sensitive search",
44
+ default=False,
45
+ ),
46
+ ]
47
+
48
+ MaxCount = Annotated[
49
+ int,
50
+ Field(
51
+ description="Maximum number of results",
52
+ default=100,
53
+ ),
54
+ ]
55
+
56
+ Branch = Annotated[
57
+ str | None,
58
+ Field(
59
+ description="Branch to search (defaults to current branch)",
60
+ default=None,
61
+ ),
62
+ ]
63
+
64
+ Author = Annotated[
65
+ str | None,
66
+ Field(
67
+ description="Filter by author (for commits/log)",
68
+ default=None,
69
+ ),
70
+ ]
71
+
72
+ Since = Annotated[
73
+ str | None,
74
+ Field(
75
+ description="Search commits since date (e.g., '2 weeks ago', '2024-01-01')",
76
+ default=None,
77
+ ),
78
+ ]
79
+
80
+ Until = Annotated[
81
+ str | None,
82
+ Field(
83
+ description="Search commits until date",
84
+ default=None,
85
+ ),
86
+ ]
87
+
88
+ FilePattern = Annotated[
89
+ str | None,
90
+ Field(
91
+ description="Limit search to files matching pattern",
92
+ default=None,
93
+ ),
94
+ ]
95
+
96
+
97
+ class GitSearchParams(TypedDict, total=False):
98
+ """Parameters for git search tool."""
99
+
100
+ pattern: str
101
+ path: str | None
102
+ search_type: str
103
+ case_sensitive: bool
104
+ max_count: int
105
+ branch: str | None
106
+ author: str | None
107
+ since: str | None
108
+ until: str | None
109
+ file_pattern: str | None
110
+
111
+
112
+ @final
113
+ class GitSearchTool(BaseTool):
114
+ """Tool for searching through git history efficiently."""
115
+
116
+ def __init__(self, permission_manager: PermissionManager):
117
+ """Initialize the git search tool.
118
+
119
+ Args:
120
+ permission_manager: Permission manager for access control
121
+ """
122
+ self.permission_manager = permission_manager
123
+
124
+ @property
125
+ @override
126
+ def name(self) -> str:
127
+ """Get the tool name."""
128
+ return "git_search"
129
+
130
+ @property
131
+ @override
132
+ def description(self) -> str:
133
+ """Get the tool description."""
134
+ return """Search through git history using native git commands.
135
+
136
+ Supports multiple search types:
137
+ - 'content': Search file contents in history (git grep)
138
+ - 'commits': Search commit messages (git log --grep)
139
+ - 'diff': Search changes/patches (git log -G)
140
+ - 'log': Search commit logs with filters
141
+ - 'blame': Find who changed lines matching pattern
142
+
143
+ Features:
144
+ - Regex pattern support
145
+ - Case sensitive/insensitive search
146
+ - Filter by author, date range, branch
147
+ - Limit to specific file patterns
148
+ - Efficient native git performance
149
+
150
+ Examples:
151
+ - Search for "TODO" in all history: pattern="TODO", search_type="content"
152
+ - Find commits mentioning "fix": pattern="fix", search_type="commits"
153
+ - Find when function was added: pattern="def my_func", search_type="diff"
154
+ """
155
+
156
+ @override
157
+ async def call(
158
+ self,
159
+ ctx: MCPContext,
160
+ **params: Unpack[GitSearchParams],
161
+ ) -> str:
162
+ """Execute git search.
163
+
164
+ Args:
165
+ ctx: MCP context
166
+ **params: Tool parameters
167
+
168
+ Returns:
169
+ Search results
170
+ """
171
+ tool_ctx = create_tool_context(ctx)
172
+ await tool_ctx.set_tool_info(self.name)
173
+
174
+ # Extract parameters
175
+ pattern = params.get("pattern")
176
+ if not pattern:
177
+ return "Error: pattern is required"
178
+
179
+ path = params.get("path", os.getcwd())
180
+ search_type = params.get("search_type", "content")
181
+ case_sensitive = params.get("case_sensitive", False)
182
+ max_count = params.get("max_count", 100)
183
+ branch = params.get("branch")
184
+ author = params.get("author")
185
+ since = params.get("since")
186
+ until = params.get("until")
187
+ file_pattern = params.get("file_pattern")
188
+
189
+ # Resolve absolute path
190
+ abs_path = os.path.abspath(path)
191
+
192
+ # Check permissions
193
+ if not self.permission_manager.has_permission(abs_path):
194
+ return f"Permission denied: {abs_path}"
195
+
196
+ # Check if it's a git repository
197
+ if not os.path.exists(os.path.join(abs_path, ".git")):
198
+ # Try to find parent git directory
199
+ parent = abs_path
200
+ while parent != os.path.dirname(parent):
201
+ parent = os.path.dirname(parent)
202
+ if os.path.exists(os.path.join(parent, ".git")):
203
+ abs_path = parent
204
+ break
205
+ else:
206
+ return f"Not a git repository: {path}"
207
+
208
+ await tool_ctx.info(f"Searching git history in {abs_path}")
209
+
210
+ try:
211
+ if search_type == "content":
212
+ return await self._search_content(
213
+ abs_path, pattern, case_sensitive, max_count,
214
+ branch, file_pattern, tool_ctx
215
+ )
216
+ elif search_type == "commits":
217
+ return await self._search_commits(
218
+ abs_path, pattern, case_sensitive, max_count,
219
+ branch, author, since, until, file_pattern, tool_ctx
220
+ )
221
+ elif search_type == "diff":
222
+ return await self._search_diff(
223
+ abs_path, pattern, case_sensitive, max_count,
224
+ branch, author, since, until, file_pattern, tool_ctx
225
+ )
226
+ elif search_type == "log":
227
+ return await self._search_log(
228
+ abs_path, pattern, max_count, branch,
229
+ author, since, until, file_pattern, tool_ctx
230
+ )
231
+ elif search_type == "blame":
232
+ return await self._search_blame(
233
+ abs_path, pattern, case_sensitive, file_pattern, tool_ctx
234
+ )
235
+ else:
236
+ return f"Unknown search type: {search_type}"
237
+
238
+ except subprocess.CalledProcessError as e:
239
+ await tool_ctx.error(f"Git command failed: {e}")
240
+ return f"Git search failed: {e.stderr if e.stderr else str(e)}"
241
+ except Exception as e:
242
+ await tool_ctx.error(f"Search failed: {e}")
243
+ return f"Error: {str(e)}"
244
+
245
+ async def _search_content(
246
+ self, repo_path: str, pattern: str, case_sensitive: bool,
247
+ max_count: int, branch: str | None, file_pattern: str | None,
248
+ tool_ctx
249
+ ) -> str:
250
+ """Search file contents in git history."""
251
+ cmd = ["git", "grep", "-n", f"--max-count={max_count}"]
252
+
253
+ if not case_sensitive:
254
+ cmd.append("-i")
255
+
256
+ if branch:
257
+ cmd.append(branch)
258
+ else:
259
+ cmd.append("--all") # Search all branches
260
+
261
+ cmd.append(pattern)
262
+
263
+ if file_pattern:
264
+ cmd.extend(["--", file_pattern])
265
+
266
+ result = subprocess.run(
267
+ cmd, cwd=repo_path, capture_output=True, text=True
268
+ )
269
+
270
+ if result.returncode == 0:
271
+ lines = result.stdout.strip().split('\n')
272
+ if lines and lines[0]:
273
+ await tool_ctx.info(f"Found {len(lines)} matches")
274
+ return self._format_grep_results(lines, pattern)
275
+ else:
276
+ return f"No matches found for pattern: {pattern}"
277
+ elif result.returncode == 1:
278
+ return f"No matches found for pattern: {pattern}"
279
+ else:
280
+ raise subprocess.CalledProcessError(
281
+ result.returncode, cmd, result.stdout, result.stderr
282
+ )
283
+
284
+ async def _search_commits(
285
+ self, repo_path: str, pattern: str, case_sensitive: bool,
286
+ max_count: int, branch: str | None, author: str | None,
287
+ since: str | None, until: str | None, file_pattern: str | None,
288
+ tool_ctx
289
+ ) -> str:
290
+ """Search commit messages."""
291
+ cmd = ["git", "log", f"--max-count={max_count}", "--oneline"]
292
+
293
+ grep_flag = "--grep" if case_sensitive else "--grep-ignore-case"
294
+ cmd.extend([grep_flag, pattern])
295
+
296
+ if branch:
297
+ cmd.append(branch)
298
+ else:
299
+ cmd.append("--all")
300
+
301
+ if author:
302
+ cmd.extend(["--author", author])
303
+
304
+ if since:
305
+ cmd.extend(["--since", since])
306
+
307
+ if until:
308
+ cmd.extend(["--until", until])
309
+
310
+ if file_pattern:
311
+ cmd.extend(["--", file_pattern])
312
+
313
+ result = subprocess.run(
314
+ cmd, cwd=repo_path, capture_output=True, text=True
315
+ )
316
+
317
+ if result.returncode == 0:
318
+ lines = result.stdout.strip().split('\n')
319
+ if lines and lines[0]:
320
+ await tool_ctx.info(f"Found {len(lines)} commits")
321
+ return f"Found {len(lines)} commits matching '{pattern}':\n\n" + result.stdout
322
+ else:
323
+ return f"No commits found matching: {pattern}"
324
+ else:
325
+ raise subprocess.CalledProcessError(
326
+ result.returncode, cmd, result.stdout, result.stderr
327
+ )
328
+
329
+ async def _search_diff(
330
+ self, repo_path: str, pattern: str, case_sensitive: bool,
331
+ max_count: int, branch: str | None, author: str | None,
332
+ since: str | None, until: str | None, file_pattern: str | None,
333
+ tool_ctx
334
+ ) -> str:
335
+ """Search for pattern in diffs (when code was added/removed)."""
336
+ cmd = ["git", "log", f"--max-count={max_count}", "-p"]
337
+
338
+ # Use -G for diff search (shows commits that added/removed pattern)
339
+ search_flag = f"-G{pattern}"
340
+ if not case_sensitive:
341
+ # For case-insensitive, we need to use -G with regex
342
+ import re
343
+ case_insensitive_pattern = "".join(
344
+ f"[{c.upper()}{c.lower()}]" if c.isalpha() else re.escape(c)
345
+ for c in pattern
346
+ )
347
+ search_flag = f"-G{case_insensitive_pattern}"
348
+
349
+ cmd.append(search_flag)
350
+
351
+ if branch:
352
+ cmd.append(branch)
353
+ else:
354
+ cmd.append("--all")
355
+
356
+ if author:
357
+ cmd.extend(["--author", author])
358
+
359
+ if since:
360
+ cmd.extend(["--since", since])
361
+
362
+ if until:
363
+ cmd.extend(["--until", until])
364
+
365
+ if file_pattern:
366
+ cmd.extend(["--", file_pattern])
367
+
368
+ result = subprocess.run(
369
+ cmd, cwd=repo_path, capture_output=True, text=True
370
+ )
371
+
372
+ if result.returncode == 0 and result.stdout.strip():
373
+ # Parse and highlight matching lines
374
+ output = self._highlight_diff_matches(result.stdout, pattern, case_sensitive)
375
+ matches = output.count("commit ")
376
+ await tool_ctx.info(f"Found {matches} commits with changes")
377
+ return f"Found {matches} commits with changes matching '{pattern}':\n\n{output}"
378
+ else:
379
+ return f"No changes found matching: {pattern}"
380
+
381
+ async def _search_log(
382
+ self, repo_path: str, pattern: str | None, max_count: int,
383
+ branch: str | None, author: str | None, since: str | None,
384
+ until: str | None, file_pattern: str | None, tool_ctx
385
+ ) -> str:
386
+ """Search git log with filters."""
387
+ cmd = ["git", "log", f"--max-count={max_count}", "--oneline"]
388
+
389
+ if pattern:
390
+ # Search in commit message and changes
391
+ cmd.extend(["--grep", pattern, f"-G{pattern}"])
392
+
393
+ if branch:
394
+ cmd.append(branch)
395
+ else:
396
+ cmd.append("--all")
397
+
398
+ if author:
399
+ cmd.extend(["--author", author])
400
+
401
+ if since:
402
+ cmd.extend(["--since", since])
403
+
404
+ if until:
405
+ cmd.extend(["--until", until])
406
+
407
+ if file_pattern:
408
+ cmd.extend(["--", file_pattern])
409
+
410
+ result = subprocess.run(
411
+ cmd, cwd=repo_path, capture_output=True, text=True
412
+ )
413
+
414
+ if result.returncode == 0 and result.stdout.strip():
415
+ lines = result.stdout.strip().split('\n')
416
+ await tool_ctx.info(f"Found {len(lines)} commits")
417
+ return f"Found {len(lines)} commits:\n\n" + result.stdout
418
+ else:
419
+ return "No commits found matching criteria"
420
+
421
+ async def _search_blame(
422
+ self, repo_path: str, pattern: str, case_sensitive: bool,
423
+ file_pattern: str | None, tool_ctx
424
+ ) -> str:
425
+ """Search using git blame to find who changed lines."""
426
+ if not file_pattern:
427
+ return "Error: file_pattern is required for blame search"
428
+
429
+ # First, find files matching the pattern
430
+ cmd = ["git", "ls-files", file_pattern]
431
+ result = subprocess.run(
432
+ cmd, cwd=repo_path, capture_output=True, text=True
433
+ )
434
+
435
+ if result.returncode != 0 or not result.stdout.strip():
436
+ return f"No files found matching: {file_pattern}"
437
+
438
+ files = result.stdout.strip().split('\n')
439
+ all_matches = []
440
+
441
+ for file_path in files[:10]: # Limit to 10 files
442
+ # Get blame for the file
443
+ cmd = ["git", "blame", "-l", file_path]
444
+ result = subprocess.run(
445
+ cmd, cwd=repo_path, capture_output=True, text=True
446
+ )
447
+
448
+ if result.returncode == 0:
449
+ # Search for pattern in blame output
450
+ flags = 0 if case_sensitive else re.IGNORECASE
451
+ for line in result.stdout.split('\n'):
452
+ if re.search(pattern, line, flags):
453
+ all_matches.append(f"{file_path}: {line}")
454
+
455
+ if all_matches:
456
+ await tool_ctx.info(f"Found {len(all_matches)} matching lines")
457
+ return f"Found {len(all_matches)} lines matching '{pattern}':\n\n" + \
458
+ "\n".join(all_matches[:50]) # Limit output
459
+ else:
460
+ return f"No lines found matching: {pattern}"
461
+
462
+ def _format_grep_results(self, lines: list[str], pattern: str) -> str:
463
+ """Format git grep results nicely."""
464
+ output = []
465
+ current_ref = None
466
+
467
+ for line in lines:
468
+ if ':' in line:
469
+ parts = line.split(':', 3)
470
+ if len(parts) >= 3:
471
+ ref = parts[0]
472
+ file_path = parts[1]
473
+ line_num = parts[2]
474
+ content = parts[3] if len(parts) > 3 else ""
475
+
476
+ if ref != current_ref:
477
+ current_ref = ref
478
+ output.append(f"\n=== {ref} ===")
479
+
480
+ output.append(f"{file_path}:{line_num}: {content}")
481
+
482
+ return f"Found matches for '{pattern}':\n" + "\n".join(output)
483
+
484
+ def _highlight_diff_matches(
485
+ self, diff_output: str, pattern: str, case_sensitive: bool
486
+ ) -> str:
487
+ """Highlight matching lines in diff output."""
488
+ lines = diff_output.split('\n')
489
+ output = []
490
+ flags = 0 if case_sensitive else re.IGNORECASE
491
+
492
+ for line in lines:
493
+ if line.startswith(('+', '-')) and not line.startswith(('+++', '---')):
494
+ if re.search(pattern, line[1:], flags):
495
+ output.append(f">>> {line}") # Highlight matching lines
496
+ else:
497
+ output.append(line)
498
+ else:
499
+ output.append(line)
500
+
501
+ return "\n".join(output)
502
+
503
+ def register(self, mcp_server) -> None:
504
+ """Register this tool with the MCP server."""
505
+ pass
@@ -0,0 +1,27 @@
1
+ """LLM tools for Hanzo MCP."""
2
+
3
+ from hanzo_mcp.tools.llm.llm_tool import LLMTool
4
+ from hanzo_mcp.tools.llm.consensus_tool import ConsensusTool
5
+ from hanzo_mcp.tools.llm.llm_manage import LLMManageTool
6
+ from hanzo_mcp.tools.llm.provider_tools import (
7
+ create_provider_tools,
8
+ OpenAITool,
9
+ AnthropicTool,
10
+ GeminiTool,
11
+ GroqTool,
12
+ MistralTool,
13
+ PerplexityTool,
14
+ )
15
+
16
+ __all__ = [
17
+ "LLMTool",
18
+ "ConsensusTool",
19
+ "LLMManageTool",
20
+ "create_provider_tools",
21
+ "OpenAITool",
22
+ "AnthropicTool",
23
+ "GeminiTool",
24
+ "GroqTool",
25
+ "MistralTool",
26
+ "PerplexityTool",
27
+ ]