hanzo-mcp 0.5.1__py3-none-any.whl → 0.6.1__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 (118) hide show
  1. hanzo_mcp/__init__.py +1 -1
  2. hanzo_mcp/cli.py +32 -0
  3. hanzo_mcp/dev_server.py +246 -0
  4. hanzo_mcp/prompts/__init__.py +1 -1
  5. hanzo_mcp/prompts/project_system.py +43 -7
  6. hanzo_mcp/server.py +5 -1
  7. hanzo_mcp/tools/__init__.py +168 -6
  8. hanzo_mcp/tools/agent/__init__.py +1 -1
  9. hanzo_mcp/tools/agent/agent.py +401 -0
  10. hanzo_mcp/tools/agent/agent_tool.py +3 -4
  11. hanzo_mcp/tools/common/__init__.py +1 -1
  12. hanzo_mcp/tools/common/base.py +9 -4
  13. hanzo_mcp/tools/common/batch_tool.py +3 -5
  14. hanzo_mcp/tools/common/config_tool.py +1 -1
  15. hanzo_mcp/tools/common/context.py +1 -1
  16. hanzo_mcp/tools/common/palette.py +344 -0
  17. hanzo_mcp/tools/common/palette_loader.py +108 -0
  18. hanzo_mcp/tools/common/stats.py +261 -0
  19. hanzo_mcp/tools/common/thinking_tool.py +3 -5
  20. hanzo_mcp/tools/common/tool_disable.py +144 -0
  21. hanzo_mcp/tools/common/tool_enable.py +182 -0
  22. hanzo_mcp/tools/common/tool_list.py +260 -0
  23. hanzo_mcp/tools/config/__init__.py +10 -0
  24. hanzo_mcp/tools/config/config_tool.py +212 -0
  25. hanzo_mcp/tools/config/index_config.py +176 -0
  26. hanzo_mcp/tools/config/palette_tool.py +166 -0
  27. hanzo_mcp/tools/database/__init__.py +71 -0
  28. hanzo_mcp/tools/database/database_manager.py +246 -0
  29. hanzo_mcp/tools/database/graph.py +482 -0
  30. hanzo_mcp/tools/database/graph_add.py +257 -0
  31. hanzo_mcp/tools/database/graph_query.py +536 -0
  32. hanzo_mcp/tools/database/graph_remove.py +267 -0
  33. hanzo_mcp/tools/database/graph_search.py +348 -0
  34. hanzo_mcp/tools/database/graph_stats.py +345 -0
  35. hanzo_mcp/tools/database/sql.py +411 -0
  36. hanzo_mcp/tools/database/sql_query.py +229 -0
  37. hanzo_mcp/tools/database/sql_search.py +296 -0
  38. hanzo_mcp/tools/database/sql_stats.py +254 -0
  39. hanzo_mcp/tools/editor/__init__.py +11 -0
  40. hanzo_mcp/tools/editor/neovim_command.py +272 -0
  41. hanzo_mcp/tools/editor/neovim_edit.py +290 -0
  42. hanzo_mcp/tools/editor/neovim_session.py +356 -0
  43. hanzo_mcp/tools/filesystem/__init__.py +52 -13
  44. hanzo_mcp/tools/filesystem/base.py +1 -1
  45. hanzo_mcp/tools/filesystem/batch_search.py +812 -0
  46. hanzo_mcp/tools/filesystem/content_replace.py +3 -5
  47. hanzo_mcp/tools/filesystem/diff.py +193 -0
  48. hanzo_mcp/tools/filesystem/directory_tree.py +3 -5
  49. hanzo_mcp/tools/filesystem/edit.py +3 -5
  50. hanzo_mcp/tools/filesystem/find.py +443 -0
  51. hanzo_mcp/tools/filesystem/find_files.py +348 -0
  52. hanzo_mcp/tools/filesystem/git_search.py +505 -0
  53. hanzo_mcp/tools/filesystem/grep.py +2 -2
  54. hanzo_mcp/tools/filesystem/multi_edit.py +3 -5
  55. hanzo_mcp/tools/filesystem/read.py +17 -5
  56. hanzo_mcp/tools/filesystem/{grep_ast_tool.py → symbols.py} +17 -27
  57. hanzo_mcp/tools/filesystem/symbols_unified.py +376 -0
  58. hanzo_mcp/tools/filesystem/tree.py +268 -0
  59. hanzo_mcp/tools/filesystem/unified_search.py +465 -443
  60. hanzo_mcp/tools/filesystem/unix_aliases.py +99 -0
  61. hanzo_mcp/tools/filesystem/watch.py +174 -0
  62. hanzo_mcp/tools/filesystem/write.py +3 -5
  63. hanzo_mcp/tools/jupyter/__init__.py +9 -12
  64. hanzo_mcp/tools/jupyter/base.py +1 -1
  65. hanzo_mcp/tools/jupyter/jupyter.py +326 -0
  66. hanzo_mcp/tools/jupyter/notebook_edit.py +3 -4
  67. hanzo_mcp/tools/jupyter/notebook_read.py +3 -5
  68. hanzo_mcp/tools/llm/__init__.py +31 -0
  69. hanzo_mcp/tools/llm/consensus_tool.py +351 -0
  70. hanzo_mcp/tools/llm/llm_manage.py +413 -0
  71. hanzo_mcp/tools/llm/llm_tool.py +346 -0
  72. hanzo_mcp/tools/llm/llm_unified.py +851 -0
  73. hanzo_mcp/tools/llm/provider_tools.py +412 -0
  74. hanzo_mcp/tools/mcp/__init__.py +15 -0
  75. hanzo_mcp/tools/mcp/mcp_add.py +263 -0
  76. hanzo_mcp/tools/mcp/mcp_remove.py +127 -0
  77. hanzo_mcp/tools/mcp/mcp_stats.py +165 -0
  78. hanzo_mcp/tools/mcp/mcp_unified.py +503 -0
  79. hanzo_mcp/tools/shell/__init__.py +21 -23
  80. hanzo_mcp/tools/shell/base.py +1 -1
  81. hanzo_mcp/tools/shell/base_process.py +303 -0
  82. hanzo_mcp/tools/shell/bash_unified.py +134 -0
  83. hanzo_mcp/tools/shell/logs.py +265 -0
  84. hanzo_mcp/tools/shell/npx.py +194 -0
  85. hanzo_mcp/tools/shell/npx_background.py +254 -0
  86. hanzo_mcp/tools/shell/npx_unified.py +101 -0
  87. hanzo_mcp/tools/shell/open.py +107 -0
  88. hanzo_mcp/tools/shell/pkill.py +262 -0
  89. hanzo_mcp/tools/shell/process_unified.py +131 -0
  90. hanzo_mcp/tools/shell/processes.py +279 -0
  91. hanzo_mcp/tools/shell/run_background.py +326 -0
  92. hanzo_mcp/tools/shell/run_command.py +3 -4
  93. hanzo_mcp/tools/shell/run_command_windows.py +3 -4
  94. hanzo_mcp/tools/shell/uvx.py +187 -0
  95. hanzo_mcp/tools/shell/uvx_background.py +249 -0
  96. hanzo_mcp/tools/shell/uvx_unified.py +101 -0
  97. hanzo_mcp/tools/todo/__init__.py +1 -1
  98. hanzo_mcp/tools/todo/base.py +1 -1
  99. hanzo_mcp/tools/todo/todo.py +265 -0
  100. hanzo_mcp/tools/todo/todo_read.py +3 -5
  101. hanzo_mcp/tools/todo/todo_write.py +3 -5
  102. hanzo_mcp/tools/vector/__init__.py +6 -1
  103. hanzo_mcp/tools/vector/git_ingester.py +3 -0
  104. hanzo_mcp/tools/vector/index_tool.py +358 -0
  105. hanzo_mcp/tools/vector/infinity_store.py +98 -0
  106. hanzo_mcp/tools/vector/project_manager.py +27 -5
  107. hanzo_mcp/tools/vector/vector.py +311 -0
  108. hanzo_mcp/tools/vector/vector_index.py +1 -1
  109. hanzo_mcp/tools/vector/vector_search.py +12 -7
  110. hanzo_mcp-0.6.1.dist-info/METADATA +336 -0
  111. hanzo_mcp-0.6.1.dist-info/RECORD +134 -0
  112. hanzo_mcp-0.6.1.dist-info/entry_points.txt +3 -0
  113. hanzo_mcp-0.5.1.dist-info/METADATA +0 -276
  114. hanzo_mcp-0.5.1.dist-info/RECORD +0 -68
  115. hanzo_mcp-0.5.1.dist-info/entry_points.txt +0 -2
  116. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.6.1.dist-info}/WHEEL +0 -0
  117. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.6.1.dist-info}/licenses/LICENSE +0 -0
  118. {hanzo_mcp-0.5.1.dist-info → hanzo_mcp-0.6.1.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 mcp.server.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
@@ -12,8 +12,8 @@ import shutil
12
12
  from pathlib import Path
13
13
  from typing import Annotated, TypedDict, Unpack, final, override
14
14
 
15
- from fastmcp import Context as MCPContext
16
- from fastmcp import FastMCP
15
+ from mcp.server.fastmcp import Context as MCPContext
16
+ from mcp.server import FastMCP
17
17
  from pydantic import Field
18
18
 
19
19
  from hanzo_mcp.tools.common.context import ToolContext
@@ -7,9 +7,8 @@ from difflib import unified_diff
7
7
  from pathlib import Path
8
8
  from typing import Annotated, TypedDict, Unpack, final, override
9
9
 
10
- from fastmcp import Context as MCPContext
11
- from fastmcp import FastMCP
12
- from fastmcp.server.dependencies import get_context
10
+ from mcp.server.fastmcp import Context as MCPContext
11
+ from mcp.server import FastMCP
13
12
  from pydantic import Field
14
13
 
15
14
  from hanzo_mcp.tools.filesystem.base import FilesystemBaseTool
@@ -350,11 +349,10 @@ If you want to create a new file, use:
350
349
 
351
350
  @mcp_server.tool(name=self.name, description=self.description)
352
351
  async def multi_edit(
353
- ctx: MCPContext,
354
352
  file_path: FilePath,
355
353
  edits: Edits,
354
+ ctx: MCPContext
356
355
  ) -> str:
357
- ctx = get_context()
358
356
  return await tool_self.call(
359
357
  ctx,
360
358
  file_path=file_path,
@@ -6,9 +6,8 @@ This module provides the ReadTool for reading the contents of files.
6
6
  from pathlib import Path
7
7
  from typing import Annotated, TypedDict, Unpack, final, override
8
8
 
9
- from fastmcp import Context as MCPContext
10
- from fastmcp import FastMCP
11
- from fastmcp.server.dependencies import get_context
9
+ from mcp.server.fastmcp import Context as MCPContext
10
+ from mcp.server import FastMCP
12
11
  from pydantic import Field
13
12
 
14
13
  from hanzo_mcp.tools.filesystem.base import FilesystemBaseTool
@@ -230,6 +229,20 @@ Usage:
230
229
  await tool_ctx.error(f"Error reading file: {str(e)}")
231
230
  return f"Error: {str(e)}"
232
231
 
232
+ async def run(self, ctx: MCPContext, file_path: str, offset: int = 0, limit: int = 2000) -> str:
233
+ """Run method for backwards compatibility with test scripts.
234
+
235
+ Args:
236
+ ctx: MCP context
237
+ file_path: Path to file to read
238
+ offset: Line offset to start reading
239
+ limit: Maximum lines to read
240
+
241
+ Returns:
242
+ File contents
243
+ """
244
+ return await self.call(ctx, file_path=file_path, offset=offset, limit=limit)
245
+
233
246
  @override
234
247
  def register(self, mcp_server: FastMCP) -> None:
235
248
  """Register this tool with the MCP server.
@@ -244,12 +257,11 @@ Usage:
244
257
 
245
258
  @mcp_server.tool(name=self.name, description=self.description)
246
259
  async def read(
247
- ctx: MCPContext,
248
260
  file_path: FilePath,
249
261
  offset: Offset,
250
262
  limit: Limit,
263
+ ctx: MCPContext
251
264
  ) -> str:
252
- ctx = get_context()
253
265
  return await tool_self.call(
254
266
  ctx, file_path=file_path, offset=offset, limit=limit
255
267
  )
@@ -1,16 +1,16 @@
1
- """Grep AST tool implementation.
1
+ """Symbols tool implementation.
2
2
 
3
- This module provides the GrepAstTool for searching through source code files with AST context,
4
- seeing matching lines with useful context showing how they fit into the code structure.
3
+ This module provides the SymbolsTool for searching, indexing, and querying code symbols
4
+ using tree-sitter AST parsing. It can find function definitions, class declarations,
5
+ and other code structures with full context.
5
6
  """
6
7
 
7
8
  import os
8
9
  from pathlib import Path
9
10
  from typing import Annotated, TypedDict, Unpack, final, override
10
11
 
11
- from fastmcp import Context as MCPContext
12
- from fastmcp import FastMCP
13
- from fastmcp.server.dependencies import get_context
12
+ from mcp.server.fastmcp import Context as MCPContext
13
+ from mcp.server import FastMCP
14
14
  from grep_ast.grep_ast import TreeContext
15
15
  from pydantic import Field
16
16
 
@@ -66,8 +66,8 @@ class GrepAstToolParams(TypedDict):
66
66
 
67
67
 
68
68
  @final
69
- class GrepAstTool(FilesystemBaseTool):
70
- """Tool for searching through source code files with AST context."""
69
+ class SymbolsTool(FilesystemBaseTool):
70
+ """Tool for searching and querying code symbols using tree-sitter AST parsing."""
71
71
 
72
72
  @property
73
73
  @override
@@ -77,7 +77,7 @@ class GrepAstTool(FilesystemBaseTool):
77
77
  Returns:
78
78
  Tool name
79
79
  """
80
- return "grep_ast"
80
+ return "symbols"
81
81
 
82
82
  @property
83
83
  @override
@@ -87,23 +87,14 @@ class GrepAstTool(FilesystemBaseTool):
87
87
  Returns:
88
88
  Tool description
89
89
  """
90
- return """Search through source code files and see matching lines with useful AST (Abstract Syntax Tree) context. This tool helps you understand code structure by showing how matched lines fit into functions, classes, and other code blocks.
90
+ return """Code symbols search with tree-sitter AST. Actions: search (default), index, query.
91
91
 
92
- Unlike traditional search tools like `search_content` that only show matching lines, `grep_ast` leverages the AST to reveal the structural context around matches, making it easier to understand the code organization.
92
+ Usage:
93
+ symbols "function_name" ./src
94
+ symbols --action index --path ./src
95
+ symbols --action query --type function --path ./src
93
96
 
94
- When to use this tool:
95
- 1. When you need to understand where a pattern appears within larger code structures
96
- 2. When searching for function or class definitions that match a pattern
97
- 3. When you want to see not just the matching line but its surrounding context in the code
98
- 4. When exploring unfamiliar codebases and need structural context
99
- 5. When examining how a specific pattern is used across different parts of the codebase
100
-
101
- This tool is superior to regular grep/search_content when you need to understand code structure, not just find text matches.
102
-
103
- Example usage:
104
- ```
105
- grep_ast(pattern="function_name", path="/path/to/file.py", ignore_case=False, line_number=True)
106
- ```"""
97
+ Finds code structures (functions, classes, methods) with full context."""
107
98
 
108
99
  @override
109
100
  async def call(
@@ -233,14 +224,13 @@ grep_ast(pattern="function_name", path="/path/to/file.py", ignore_case=False, li
233
224
  tool_self = self # Create a reference to self for use in the closure
234
225
 
235
226
  @mcp_server.tool(name=self.name, description=self.description)
236
- async def grep_ast(
237
- ctx: MCPContext,
227
+ async def symbols(
238
228
  pattern: Pattern,
239
229
  path: SearchPath,
240
230
  ignore_case: IgnoreCase,
241
231
  line_number: LineNumber,
232
+ ctx: MCPContext
242
233
  ) -> str:
243
- ctx = get_context()
244
234
  return await tool_self.call(
245
235
  ctx,
246
236
  pattern=pattern,