Release Notes v0.4.1
Major Features
Regex Support in Search
Fixes #11: OR search (regex pipe operator) not working in search_code_advanced
Added comprehensive regex support to the search_code_advanced tool with the new regex parameter:
# OR searches now work!
search_code_advanced("ERROR|WARN", regex=True) # Returns OR matches
# Other regex patterns
search_code_advanced("function|class", regex=True) # OR search
search_code_advanced("^import", regex=True) # Start of line
search_code_advanced("Error$", regex=True) # End of line
search_code_advanced("[A-Z]+", regex=True) # Character classesKey Benefits:
- OR searches: Use
|to search for multiple patterns simultaneously - Pattern matching: Full regex support with anchors, character classes, etc.
- Safety: Built-in ReDoS attack protection
- Backward compatible: Default behavior unchanged (literal search)
Bug Fixes
Fixed ag (Silver Searcher) File Pattern Handling
Resolved issue where glob patterns like *.py were incorrectly passed to ag's -G parameter, causing incorrect file matching behavior.
Improvements:
*.pynow correctly converts to\.py$for ag's regex enginetest_*.jsnow correctly converts to^test_.*\.js$src/*.cssnow correctly converts to^src/.*\.css$- All search tools (ugrep, ripgrep, ag, grep) now handle file patterns consistently
Technical Changes
New Features
regexparameter: Explicit control over regex vs literal search modes- Pattern safety validation:
is_safe_regex_pattern()function with ReDoS protection - Automatic glob-to-regex conversion: Smart pattern conversion for ag search strategy
- Enhanced file pattern support: Consistent behavior across all search backends
Security Enhancements
- Protection against ReDoS (Regular Expression Denial of Service) attacks
- Validates regex patterns before execution
- Rejects potentially dangerous patterns like
(.+)+,(.*)* - Only allows safe regex metacharacters:
|,(,),[,],^,$
Code Improvements
- Renamed
create_safe_fuzzy_pattern()tocreate_word_boundary_pattern()for clarity - Improved parameter documentation across all search strategies
- Enhanced error handling and validation
Usage Examples
Basic Regex Search
# Default behavior (literal search) - unchanged
search_code_advanced("ERROR|WARN") # Searches for literal "ERROR|WARN"
# New regex support
search_code_advanced("ERROR|WARN", regex=True) # OR searchFile Pattern Examples
# All these now work consistently across all search tools
search_code_advanced("def main", file_pattern="*.py") # Python files
search_code_advanced("function", file_pattern="test_*.js") # Test JS files
search_code_advanced("import", file_pattern="src/*.ts") # TypeScript in src/Advanced Regex Patterns
search_code_advanced("class [A-Z][a-zA-Z0-9]*", regex=True) # Class names
search_code_advanced("(TODO|FIXME|HACK)", regex=True) # Code comments
search_code_advanced("^\\s*def\\s+", regex=True) # Function definitionsSecurity Notes
- All regex patterns are validated for safety before execution
- Dangerous patterns that could cause ReDoS attacks are automatically rejected
- Pattern validation ensures server stability and performance
- Safe regex features are clearly documented
Backward Compatibility
This release maintains 100% backward compatibility:
- Default search behavior remains unchanged (literal string search)
- Existing code will continue to work without any modifications
- New
regexparameter is optional withFalseas default - File pattern handling improved transparently without API changes
Migration Guide
To use regex features:
# Old way (still works)
search_code_advanced("simple text")
# New regex capabilities
search_code_advanced("pattern1|pattern2", regex=True) # OR search
search_code_advanced("^start", regex=True) # Line start
search_code_advanced("end$", regex=True) # Line endNo migration needed for file patterns:
File pattern handling is automatically improved - existing code works better without changes.
Testing
This release has been thoroughly tested with:
- Basic search functionality validation
- OR pattern matching verification across all search backends
- File pattern conversion for ag, ripgrep, ugrep, and grep
- Safety checks for dangerous regex patterns
- Backward compatibility confirmation with existing codebases
- Performance testing with various pattern complexities
Related Issues
Version Updates
- Bumped version to 0.4.1 reflecting the major regex feature addition
- Updated version strings in
pyproject.tomlandsrc/code_index_mcp/__init__.py
Full Changelog: v0.3.1...v0.4.1