9.4 KiB
Hanzo MCP Search Guide
Overview
Hanzo MCP provides a powerful unified search system that intelligently combines multiple search modalities to help you find anything in your codebase. The system consists of two primary tools:
- Unified Search (
search) - THE primary search interface that finds everything - Find Tool (
find) - Fast file and directory discovery
Unified Search Tool
The unified search tool is your universal interface for finding:
- Code patterns and text matches (using ripgrep)
- AST nodes and code structure (using treesitter)
- Symbol definitions and references (using ctags/LSP)
- Files and directories (using find tool)
- Memory and knowledge base entries
- Semantic/conceptual matches (using vector search)
Key Features
- Intelligent Query Detection: Automatically determines the best search strategy based on your query
- Parallel Search: Runs multiple search types concurrently for speed
- Deduplication: Removes duplicate results across search types
- Relevance Ranking: Sorts results by relevance and match quality
- Context Awareness: Provides surrounding context for matches
- Pagination: Handles large result sets efficiently
Usage Examples
1. Find Code Patterns
# Find all error handling code
search("error handling")
# Find TODOs and FIXMEs (regex)
search("TODO|FIXME")
# Find async functions
search("async function")
2. Find Symbols/Definitions
# Find a class definition
search("class UserService")
# Find a function/method
search("handleRequest")
# Find a constant
search("MAX_RETRIES")
3. Find Files
# Find test files
search("test_*.py", search_files=True)
# Find config files
search("config", search_files=True)
4. Semantic Search
# Natural language queries
search("how authentication works")
search("database connection logic")
search("error handling patterns")
5. Memory Search
# Search previous discussions
search("previous discussion about API design")
search("that bug we fixed last week")
Advanced Usage
Filtering Results
# Search only in Python files
search("import requests", include="*.py")
# Exclude test files
search("DatabaseConnection", exclude="*test*")
# Search in specific directory
search("TODO", path="src/services")
Controlling Search Types
# Force specific search types
search("pattern",
enable_text=True, # Text search (always on)
enable_ast=True, # AST search
enable_vector=True, # Semantic search
enable_symbol=True, # Symbol search
search_files=True, # File name search
search_memory=True # Memory search
)
Pagination
# Get first page of results
result = search("async", page_size=20, page=1)
# Get next page
if result.data["pagination"]["has_next"]:
result = search("async", page_size=20, page=2)
How It Works
-
Query Analysis: The tool analyzes your query to determine intent
- Code syntax → Text/AST/Symbol search
- Natural language → Vector/semantic search
- Glob patterns → File search
-
Parallel Execution: Appropriate search types run concurrently
-
Result Processing:
- Deduplication across search types
- Relevance scoring based on:
- Match type (exact > fuzzy)
- Location (definitions > usage)
- File type (source > test > vendor)
- Context extraction
-
Presentation: Results are formatted with previews and context
Find Tool
The find tool is optimized for quickly finding files and directories by name, pattern, or attributes.
Key Features
- Lightning Fast: Uses
ffindwhen available for blazing performance - Smart Pattern Matching: Supports glob, regex, and fuzzy matching
- File Attribute Filtering: Filter by size, modification time, type
- Human-Readable: Sizes and times in readable format
- Gitignore Aware: Respects .gitignore by default
Usage Examples
Basic File Finding
# Find all Python files
find("*.py")
# Find files starting with test_
find("test_", type="file")
# Find directories named src
find("src", type="dir")
Advanced Filtering
# Find large files (>10MB)
find("*", min_size="10MB")
# Find recently modified files
find("*", modified_after="1 day ago")
# Find old log files
find("*.log", modified_before="1 week ago")
# Find files in size range
find("*", min_size="1MB", max_size="10MB")
Pattern Matching Options
# Regex pattern matching
find(r"test_\w+\.py", regex=True)
# Fuzzy matching (typo-tolerant)
find("confg", fuzzy=True) # Finds "config" files
# Case-sensitive search
find("README", case_sensitive=True)
Performance Options
# Limit search depth
find("*.js", max_depth=3)
# Don't follow symlinks
find("*", follow_symlinks=False)
# Include gitignored files
find("*", respect_gitignore=False)
# Sort results
find("*.py", sort_by="size", reverse=True)
Integration with Other Tools
AST-Aware Multi-Edit
The new AST-aware multi-edit tool can use the unified search to find all references before making changes:
# Find and rename a function across the codebase
ast_multi_edit("main.go", [
{
"old_string": "ProcessData",
"new_string": "ProcessDataWithContext",
"semantic_match": True, # Find all references
"node_types": ["call_expression"] # Only function calls
}
])
LSP Tool
The LSP tool provides language-specific intelligence:
# Check if Go LSP is available
lsp("status", file="main.go")
# Find definition (uses LSP when available)
lsp("definition", file="app.py", line=42, character=10)
# Find all references
lsp("references", file="service.ts", line=15, character=5)
# Rename symbol
lsp("rename", file="lib.rs", line=20, character=8, new_name="new_name")
Search Strategies
For Maximum Coverage
Use the unified search tool - it automatically runs all appropriate search types:
# This will search text, AST, symbols, vectors, and more
search("authentication flow")
For Speed
-
Known file names: Use the find tool
find("config.json") -
Specific text: Use grep directly
grep("TODO") -
Code structure: Use ast tool (symbols)
symbols("function.*process")
For Accuracy
-
Symbol definitions: Enable symbol search
search("MyClass", enable_symbol=True) -
Semantic meaning: Enable vector search
search("how to handle errors", enable_vector=True) -
Exact matches: Use regex anchors
search("^class MyClass$")
Performance Tips
-
Use specific paths when you know the general location:
search("pattern", path="src/services") -
Limit results for faster response:
search("common_term", max_results_per_type=10) -
Use appropriate page sizes:
# Smaller pages for interactive use search("pattern", page_size=20) # Larger pages for batch processing search("pattern", page_size=100) -
Exclude unnecessary files:
search("pattern", exclude="node_modules,*.min.js")
Configuration
Vector Search Setup
To enable semantic/vector search:
-
Install dependencies:
pip install chromadb sentence-transformers -
The tool will automatically initialize vector search when available
-
Build index for better performance:
# This happens automatically on first use # But can be triggered manually for large codebases
LSP Configuration
The LSP tool automatically installs language servers as needed. Supported languages:
- Go: gopls
- Python: python-lsp-server
- TypeScript/JavaScript: typescript-language-server
- Rust: rust-analyzer
- Java: jdtls
- C/C++: clangd
- Ruby: solargraph
- Lua: lua-language-server
Troubleshooting
Search Returns Too Many Results
- Be more specific in your query
- Use filters (include/exclude)
- Limit search types
- Reduce max_results_per_type
Search is Slow
- Use specific paths instead of searching entire codebase
- Disable vector search for simple text searches
- Use find tool for file discovery
- Install ripgrep for faster text search
Missing Expected Results
- Check if files are gitignored
- Verify file permissions
- Try different search types
- Use more general patterns
Vector Search Not Working
- Check if chromadb is installed
- Verify sentence-transformers is available
- Check for initialization errors in logs
- Try rebuilding the index
Best Practices
- Start with unified search - it's the most comprehensive
- Use natural language for conceptual searches
- Use code syntax for exact matches
- Combine search types for best results
- Review statistics to understand what was searched
- Use pagination for large result sets
- Cache results when doing multiple related searches
Summary
The Hanzo MCP search system provides a powerful, intelligent way to find anything in your codebase. The unified search tool should be your primary interface, automatically selecting the best search strategies for your queries. The find tool complements this with ultra-fast file discovery.
Together, these tools ensure you can quickly locate any code, file, symbol, or concept in your project, making development more efficient and enjoyable.