search_file_contents
Search for regex patterns in file contents, returning matches with line numbers and context lines for efficient code analysis.
Instructions
Search for patterns in file contents across a directory or file.
This tool uses ripgrep to efficiently search for regex patterns in files. It returns matches with line numbers and surrounding context lines.
Args: pattern: Regular expression pattern to search for path: File or directory path to search in case_sensitive: Whether search should be case-sensitive (default: True) file_types: File type filters (e.g., ['py', 'js']). None = all files exclude_patterns: Glob patterns to exclude (e.g., ['node_modules']) max_results: Maximum number of results to return (1-10000) context_lines: Lines of context before/after match (0-10) ctx: MCP context for logging (optional)
Returns: SearchFileContentsOutput with matches and metadata
Raises: ValueError: If input validation fails SanitizedError: If search execution fails
Examples: >>> result = search_file_contents("TODO", "./src", case_sensitive=False) >>> print(f"Found {len(result.matches)} TODO comments")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| pattern | Yes | ||
| file_types | No | ||
| max_results | No | ||
| context_lines | No | ||
| case_sensitive | No | ||
| exclude_patterns | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| matches | Yes | List of search matches found | |
| truncated | Yes | Whether results were truncated due to max_results limit | |
| total_matches | Yes | Total number of matches found (may exceed returned matches if limited) | |
| files_searched | Yes | Number of files searched | |
| search_time_ms | Yes | Time taken to complete search in milliseconds |