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,348 @@
1
+ """Find files using ffind library."""
2
+
3
+ import os
4
+ from typing import Annotated, Optional, TypedDict, Unpack, final, override
5
+ from pathlib import Path
6
+
7
+ from fastmcp import Context as MCPContext
8
+ from pydantic import Field
9
+
10
+ from hanzo_mcp.tools.common.base import BaseTool
11
+ from hanzo_mcp.tools.common.context import create_tool_context
12
+ from hanzo_mcp.tools.common.permissions import PermissionManager
13
+
14
+ try:
15
+ import ffind
16
+ FFIND_AVAILABLE = True
17
+ except ImportError:
18
+ FFIND_AVAILABLE = False
19
+
20
+
21
+ Pattern = Annotated[
22
+ str,
23
+ Field(
24
+ description="File name pattern to search for (supports wildcards)",
25
+ min_length=1,
26
+ ),
27
+ ]
28
+
29
+ Path_ = Annotated[
30
+ Optional[str],
31
+ Field(
32
+ description="Directory to search in (defaults to current directory)",
33
+ default=None,
34
+ ),
35
+ ]
36
+
37
+ Recursive = Annotated[
38
+ bool,
39
+ Field(
40
+ description="Search recursively in subdirectories",
41
+ default=True,
42
+ ),
43
+ ]
44
+
45
+ IgnoreCase = Annotated[
46
+ bool,
47
+ Field(
48
+ description="Case-insensitive search",
49
+ default=True,
50
+ ),
51
+ ]
52
+
53
+ Hidden = Annotated[
54
+ bool,
55
+ Field(
56
+ description="Include hidden files in search",
57
+ default=False,
58
+ ),
59
+ ]
60
+
61
+ DirsOnly = Annotated[
62
+ bool,
63
+ Field(
64
+ description="Only find directories",
65
+ default=False,
66
+ ),
67
+ ]
68
+
69
+ FilesOnly = Annotated[
70
+ bool,
71
+ Field(
72
+ description="Only find files (not directories)",
73
+ default=True,
74
+ ),
75
+ ]
76
+
77
+ MaxResults = Annotated[
78
+ int,
79
+ Field(
80
+ description="Maximum number of results",
81
+ default=100,
82
+ ),
83
+ ]
84
+
85
+
86
+ class FindFilesParams(TypedDict, total=False):
87
+ """Parameters for find files tool."""
88
+
89
+ pattern: str
90
+ path: Optional[str]
91
+ recursive: bool
92
+ ignore_case: bool
93
+ hidden: bool
94
+ dirs_only: bool
95
+ files_only: bool
96
+ max_results: int
97
+
98
+
99
+ @final
100
+ class FindFilesTool(BaseTool):
101
+ """Tool for finding files using ffind."""
102
+
103
+ def __init__(self, permission_manager: PermissionManager):
104
+ """Initialize the find files tool.
105
+
106
+ Args:
107
+ permission_manager: Permission manager for access control
108
+ """
109
+ self.permission_manager = permission_manager
110
+
111
+ @property
112
+ @override
113
+ def name(self) -> str:
114
+ """Get the tool name."""
115
+ return "find_files"
116
+
117
+ @property
118
+ @override
119
+ def description(self) -> str:
120
+ """Get the tool description."""
121
+ return """Find files by name pattern using efficient search.
122
+
123
+ Uses the ffind library for fast file searching with support for:
124
+ - Wildcards (* and ?)
125
+ - Case-insensitive search
126
+ - Hidden files
127
+ - Directory vs file filtering
128
+
129
+ Examples:
130
+ - find_files --pattern "*.py" # Find all Python files
131
+ - find_files --pattern "test_*" # Find files starting with test_
132
+ - find_files --pattern "README.*" # Find README files
133
+ - find_files --pattern "*config*" --hidden # Include hidden config files
134
+ - find_files --pattern "src" --dirs-only # Find directories named src
135
+
136
+ For content search, use 'grep' instead.
137
+ For database search, use 'sql_search' or 'vector_search'.
138
+ """
139
+
140
+ @override
141
+ async def call(
142
+ self,
143
+ ctx: MCPContext,
144
+ **params: Unpack[FindFilesParams],
145
+ ) -> str:
146
+ """Find files matching pattern.
147
+
148
+ Args:
149
+ ctx: MCP context
150
+ **params: Tool parameters
151
+
152
+ Returns:
153
+ List of matching files
154
+ """
155
+ tool_ctx = create_tool_context(ctx)
156
+ await tool_ctx.set_tool_info(self.name)
157
+
158
+ # Extract parameters
159
+ pattern = params.get("pattern")
160
+ if not pattern:
161
+ return "Error: pattern is required"
162
+
163
+ search_path = params.get("path") or os.getcwd()
164
+ recursive = params.get("recursive", True)
165
+ ignore_case = params.get("ignore_case", True)
166
+ hidden = params.get("hidden", False)
167
+ dirs_only = params.get("dirs_only", False)
168
+ files_only = params.get("files_only", True)
169
+ max_results = params.get("max_results", 100)
170
+
171
+ # Validate path
172
+ search_path = os.path.abspath(search_path)
173
+ if not self.permission_manager.has_permission(search_path):
174
+ return f"Error: No permission to access {search_path}"
175
+
176
+ if not os.path.exists(search_path):
177
+ return f"Error: Path does not exist: {search_path}"
178
+
179
+ await tool_ctx.info(f"Searching for '{pattern}' in {search_path}")
180
+
181
+ # If ffind is not available, fall back to basic implementation
182
+ if not FFIND_AVAILABLE:
183
+ return await self._find_files_fallback(
184
+ pattern, search_path, recursive, ignore_case,
185
+ hidden, dirs_only, files_only, max_results
186
+ )
187
+
188
+ try:
189
+ # Use ffind for efficient searching
190
+ results = []
191
+ count = 0
192
+
193
+ # Configure ffind options
194
+ options = {
195
+ 'pattern': pattern,
196
+ 'path': search_path,
197
+ 'recursive': recursive,
198
+ 'ignore_case': ignore_case,
199
+ 'hidden': hidden,
200
+ }
201
+
202
+ # Search with ffind
203
+ for filepath in ffind.find(**options):
204
+ # Check if it matches our criteria
205
+ is_dir = os.path.isdir(filepath)
206
+
207
+ if dirs_only and not is_dir:
208
+ continue
209
+ if files_only and is_dir:
210
+ continue
211
+
212
+ # Make path relative for cleaner output
213
+ try:
214
+ rel_path = os.path.relpath(filepath, search_path)
215
+ except ValueError:
216
+ rel_path = filepath
217
+
218
+ results.append(rel_path)
219
+ count += 1
220
+
221
+ if count >= max_results:
222
+ break
223
+
224
+ if not results:
225
+ return f"No files found matching '{pattern}'"
226
+
227
+ # Format output
228
+ output = [f"Found {len(results)} file(s) matching '{pattern}':"]
229
+ output.append("")
230
+
231
+ for filepath in sorted(results):
232
+ output.append(filepath)
233
+
234
+ if count >= max_results:
235
+ output.append(f"\n... (showing first {max_results} results)")
236
+
237
+ return "\n".join(output)
238
+
239
+ except Exception as e:
240
+ await tool_ctx.error(f"Error during search: {str(e)}")
241
+ # Fall back to basic implementation
242
+ return await self._find_files_fallback(
243
+ pattern, search_path, recursive, ignore_case,
244
+ hidden, dirs_only, files_only, max_results
245
+ )
246
+
247
+ async def _find_files_fallback(
248
+ self, pattern: str, search_path: str, recursive: bool,
249
+ ignore_case: bool, hidden: bool, dirs_only: bool,
250
+ files_only: bool, max_results: int
251
+ ) -> str:
252
+ """Fallback implementation when ffind is not available."""
253
+ import fnmatch
254
+
255
+ results = []
256
+ count = 0
257
+
258
+ # Convert pattern for case-insensitive matching
259
+ if ignore_case:
260
+ pattern = pattern.lower()
261
+
262
+ try:
263
+ if recursive:
264
+ # Walk directory tree
265
+ for root, dirs, files in os.walk(search_path):
266
+ # Skip hidden directories if not requested
267
+ if not hidden:
268
+ dirs[:] = [d for d in dirs if not d.startswith('.')]
269
+
270
+ # Check directories
271
+ if not files_only:
272
+ for dirname in dirs:
273
+ if self._match_pattern(dirname, pattern, ignore_case):
274
+ filepath = os.path.join(root, dirname)
275
+ rel_path = os.path.relpath(filepath, search_path)
276
+ results.append(rel_path + '/')
277
+ count += 1
278
+ if count >= max_results:
279
+ break
280
+
281
+ # Check files
282
+ if not dirs_only:
283
+ for filename in files:
284
+ if not hidden and filename.startswith('.'):
285
+ continue
286
+
287
+ if self._match_pattern(filename, pattern, ignore_case):
288
+ filepath = os.path.join(root, filename)
289
+ rel_path = os.path.relpath(filepath, search_path)
290
+ results.append(rel_path)
291
+ count += 1
292
+ if count >= max_results:
293
+ break
294
+
295
+ if count >= max_results:
296
+ break
297
+ else:
298
+ # Only search in the specified directory
299
+ for entry in os.listdir(search_path):
300
+ if not hidden and entry.startswith('.'):
301
+ continue
302
+
303
+ filepath = os.path.join(search_path, entry)
304
+ is_dir = os.path.isdir(filepath)
305
+
306
+ if dirs_only and not is_dir:
307
+ continue
308
+ if files_only and is_dir:
309
+ continue
310
+
311
+ if self._match_pattern(entry, pattern, ignore_case):
312
+ results.append(entry + '/' if is_dir else entry)
313
+ count += 1
314
+ if count >= max_results:
315
+ break
316
+
317
+ if not results:
318
+ return f"No files found matching '{pattern}' (using fallback search)"
319
+
320
+ # Format output
321
+ output = [f"Found {len(results)} file(s) matching '{pattern}' (using fallback search):"]
322
+ output.append("")
323
+
324
+ for filepath in sorted(results):
325
+ output.append(filepath)
326
+
327
+ if count >= max_results:
328
+ output.append(f"\n... (showing first {max_results} results)")
329
+
330
+ output.append("\nNote: Install 'ffind' for faster searching: pip install ffind")
331
+
332
+ return "\n".join(output)
333
+
334
+ except Exception as e:
335
+ return f"Error searching for files: {str(e)}"
336
+
337
+ def _match_pattern(self, filename: str, pattern: str, ignore_case: bool) -> bool:
338
+ """Check if filename matches pattern."""
339
+ import fnmatch
340
+
341
+ if ignore_case:
342
+ return fnmatch.fnmatch(filename.lower(), pattern)
343
+ else:
344
+ return fnmatch.fnmatch(filename, pattern)
345
+
346
+ def register(self, mcp_server) -> None:
347
+ """Register this tool with the MCP server."""
348
+ pass