Skip to content

Commit 6abb5d0

Browse files
authored
Correct search tool path handling and ugrep recursion (#38)
Fix ugrep recursion and path handling - Add -r flag for recursive search in subdirectories - Fix relative path handling in parse_search_output to work correctly with all search tools - Change ugrep file pattern from -g to --include for proper glob filtering This PR resolves critical ugrep integration issues where: 1. ugrep wasn't searching subdirectories due to missing -r flag 2. Relative paths from ugrep were incorrectly converted by os.path.relpath() Both changes are necessary and complementary for proper ugrep functionality.
1 parent 7de0293 commit 6abb5d0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/code_index_mcp/search/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ def parse_search_output(
7070

7171
line_number = int(line_number_str)
7272

73-
# Make the file path relative to the base_path
74-
relative_path = os.path.relpath(file_path_abs, normalized_base_path)
73+
# If the path is already relative (doesn't start with /), keep it as is
74+
# Otherwise, make it relative to the base_path
75+
if os.path.isabs(file_path_abs):
76+
relative_path = os.path.relpath(file_path_abs, normalized_base_path)
77+
else:
78+
# Path is already relative, use it as is
79+
relative_path = file_path_abs
7580

7681
# Normalize path separators for consistency
7782
relative_path = normalize_file_path(relative_path)

src/code_index_mcp/search/ugrep.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def search(
4646
if not self.is_available():
4747
return {"error": "ugrep (ug) command not found."}
4848

49-
cmd = ['ug', '--line-number', '--no-heading']
49+
cmd = ['ug', '-r', '--line-number', '--no-heading']
5050

5151
if fuzzy:
5252
# ugrep has native fuzzy search support
@@ -67,7 +67,7 @@ def search(
6767
cmd.extend(['-A', str(context_lines), '-B', str(context_lines)])
6868

6969
if file_pattern:
70-
cmd.extend(['-g', file_pattern]) # Correct parameter for file patterns
70+
cmd.extend(['--include', file_pattern])
7171

7272
# Add '--' to treat pattern as a literal argument, preventing injection
7373
cmd.append('--')

0 commit comments

Comments
 (0)