Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ This server integrates with the [Model Context Protocol](https://modelcontextpro
## Key Features

- **Project Indexing**: Recursively scans directories to build a searchable index of code files
- **Advanced Search**: Intelligent search with automatic detection of ripgrep, ag, or grep for enhanced performance
- **Fuzzy Search**: Safe fuzzy matching with word boundaries for flexible code discovery
- **Advanced Search**: Intelligent search with automatic detection of ugrep, ripgrep, ag, or grep for enhanced performance
- **Fuzzy Search**: Native fuzzy matching with ugrep, or safe fuzzy patterns for other tools
- **File Analysis**: Get detailed insights about file structure, imports, and complexity
- **Smart Filtering**: Automatically ignores build directories, dependencies, and non-code files
- **Persistent Storage**: Caches indexes for improved performance across sessions
Expand Down Expand Up @@ -113,7 +113,7 @@ After adding the configuration, restart Claude Desktop and the Code Index MCP to

- **set_project_path**: Sets the base project path for indexing.
- **search_code**: Basic search for code matches within the indexed files.
- **search_code_advanced**: Enhanced search using external tools (ripgrep/ag/grep) with fuzzy matching support.
- **search_code_advanced**: Enhanced search using external tools (ugrep/ripgrep/ag/grep) with fuzzy matching support.
- **find_files**: Finds files in the project matching a given pattern.
- **get_file_summary**: Gets a summary of a specific file, including line count, functions, imports, etc.
- **refresh_index**: Refreshes the project index.
Expand Down Expand Up @@ -200,4 +200,4 @@ Contributions are welcome! Please feel free to submit a Pull Request.

## Languages

- [繁體中文](README_zh.md)
- [繁體中文](README_zh.md)
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
## 主要特性

- **專案索引**:遞迴掃描目錄以建構可搜尋的程式碼檔案索引
- **進階搜尋**:智慧搜尋,自動偵測 ripgrep、ag 或 grep 以提升效能
- **模糊搜尋**:使用詞邊界的安全模糊匹配,提供靈活的程式碼發現
- **進階搜尋**:智慧搜尋,自動偵測 ugrep、ripgrep、ag 或 grep 以提升效能
- **模糊搜尋**:ugrep 的原生模糊匹配功能提供卓越的搜尋結果,或其他工具的安全模糊模式
- **檔案分析**:取得有關檔案結構、匯入和複雜性的詳細資訊
- **智慧篩選**:自動忽略建構目錄、相依套件和非程式碼檔案
- **持久儲存**:快取索引以提高跨工作階段的效能
Expand Down Expand Up @@ -109,7 +109,7 @@ python -m code_index_mcp

- **set_project_path**:設定索引的基本專案路徑。
- **search_code**:在已索引檔案中進行基本程式碼搜尋。
- **search_code_advanced**:使用外部工具 (ripgrep/ag/grep) 的增強搜尋,支援模糊匹配。
- **search_code_advanced**:使用外部工具 (ugrep/ripgrep/ag/grep) 的增強搜尋,支援模糊匹配。
- **find_files**:尋找專案中符合給定模式的檔案。
- **get_file_summary**:取得特定檔案的摘要,包括行數、函式、匯入等。
- **refresh_index**:重新整理專案索引。
Expand Down
3 changes: 2 additions & 1 deletion src/code_index_mcp/project_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ def _detect_search_tools(self):
'preferred_tool': 'basic'
}

# Check tools in priority order: ripgrep > ag > grep
# Check tools in priority order: ugrep > ripgrep > ag > grep
search_tools = [
('ugrep', 'ug'),
('ripgrep', 'rg'),
('ag', 'ag'),
('grep', 'grep')
Expand Down
20 changes: 16 additions & 4 deletions src/code_index_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def refresh_search_tools(ctx: Context) -> str:
if preferred != 'basic':
message += f"\nAdvanced search capabilities enabled with {preferred}."
else:
message += "\nOnly basic search available. Consider installing ripgrep for better performance."
message += "\nOnly basic search available. Consider installing ugrep (recommended for fuzzy search), ripgrep, or ag for better performance."

return message

Expand Down Expand Up @@ -924,11 +924,23 @@ def _execute_advanced_search(
"""
# Prepare search pattern
search_pattern = pattern
if fuzzy:
if fuzzy and tool != 'ugrep': # ugrep has native fuzzy search
search_pattern = _create_safe_fuzzy_pattern(pattern)

# Build command based on tool
if tool == 'ripgrep':
if tool == 'ugrep':
if fuzzy:
cmd = ['ug', '--line-number', '--no-heading', '--fuzzy', '--ignore-files'] # Use native fuzzy search with gitignore
else:
cmd = ['ug', '--line-number', '--no-heading', '--fixed-strings', '--ignore-files']
if not case_sensitive:
cmd.append('--ignore-case')
if context_lines > 0:
cmd.extend(['-A', str(context_lines), '-B', str(context_lines)])
if file_pattern:
cmd.extend(['--include', file_pattern])

elif tool == 'ripgrep':
if fuzzy:
cmd = ['rg', '--line-number', '--no-heading'] # Use regex mode for fuzzy
else:
Expand All @@ -939,7 +951,7 @@ def _execute_advanced_search(
cmd.extend(['-A', str(context_lines), '-B', str(context_lines)])
if file_pattern:
cmd.extend(['--glob', file_pattern])

elif tool == 'ag':
if fuzzy:
cmd = ['ag', '--line-numbers', '--noheading'] # Use regex mode for fuzzy
Expand Down