The search_pattern tool provides powerful regex-based code search with intelligent file filtering and context options. It's the ideal choice when you need to find exact text patterns, specific syntax, or code that follows a particular structure.
Stellarion uses a high-performance regex engine (ripgrep) optimized for code search. It automatically respects .gitignore patterns and excludes common noise like node_modules, build artifacts, and compiled files.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pattern | string | Yes | - | Regex pattern to search for |
path | string | No | Project root | Directory or file to search in |
fileTypes | array | No | All code files | File extensions to include (e.g., ["ts", "js"]) |
contextLines | number | No | 0 | Lines of context before and after each match |
excludeTests | boolean | No | false | Exclude test and spec files |
limit | number | No | 100 | Maximum number of matches to return |
multiline | boolean | No | false | Enable patterns that span multiple lines |
mcp__stellarion__search_pattern pattern:"regex" path:src/ fileTypes:["ts","js"] contextLines:2
Natural Language:
Find all TODO, FIXME, and HACK comments in the codebase
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"TODO|FIXME|HACK" contextLines:1
Returns: All developer annotations with one line of context
Natural Language:
Show me all console.log, console.warn, and console.error calls
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"console\\.(log|warn|error)" excludeTests:true
Returns: All console statements in production code (excluding tests)
Natural Language:
Find all async function declarations
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"async function|async \\w+\\(" fileTypes:["ts","js"]
Returns: All async function declarations in TypeScript and JavaScript files
Natural Language:
Find all imports from React
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"import.*from ['\"]react['\"]" fileTypes:["tsx","jsx"]
Returns: All React imports in JSX/TSX files
Natural Language:
Show me all named exports in the project
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"export (class|interface|type|function|const)" path:src/
Returns: All named export declarations in the src directory
Natural Language:
Find usage of the old authentication API
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"oldAuthService\\.|legacyLogin\\(" contextLines:3
Returns: All usage of deprecated auth methods with surrounding context
Natural Language:
Find all try-catch blocks
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"try\\s*\\{" contextLines:5 multiline:true
Returns: All try blocks with context showing the catch handling
Natural Language:
Find all @Injectable decorators
Direct MCP Call:
mcp__stellarion__search_pattern pattern:"@Injectable\\(.*\\)" fileTypes:["ts"]
Returns: All classes with the Injectable decorator
Each result includes:
| Field | Description |
|---|---|
| File path | Location of the match |
| Line number | Line where the match was found |
| Matching line | The content of the matching line |
| Context lines | Surrounding lines if contextLines was specified |
| Match count | Total matches per file |
Use \\ to escape regex special characters:
| Character | Escape | Example |
|---|---|---|
. | \\. | console\\.log |
( ) | \\( \\) | function\\( |
[ ] | \\[ \\] | array\\[0\\] |
{ } | \\{ \\} | interface\\{\\} |
| Goal | Pattern |
|---|---|
| Word boundary | \\bword\\b |
| Any whitespace | \\s+ |
| Word characters | \\w+ |
| Start of line | ^pattern |
| End of line | pattern$ |
| Optional | patterns? |
| One or more | pattern+ |
| Zero or more | pattern* |
Pattern search works well with other Stellarion tools:
search_pattern to find code, then get_code_element to extract full implementationssearch_pattern to locate files, then batch_analyze for complexity metricssearch_pattern for exact matches, search_semantic for conceptual matchesfileTypes:["ts","tsx"]excludeTests:true when searching production codecontextLines:2 to understand matches in contextlimit:50 for faster results on large codebases