Tools

search_pattern

Regex-based code search with intelligent filtering

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.

How It Works

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.

When to Use

  • Finding exact text matches: Specific strings, identifiers, or keywords
  • Searching for code markers: TODOs, FIXMEs, HACKs, or custom annotations
  • Locating specific function calls: API usage, deprecated methods, library calls
  • Finding deprecated API usage: Identify code that needs migration
  • Syntax-based searches: Import statements, export patterns, decorators

Parameters

ParameterTypeRequiredDefaultDescription
patternstringYes-Regex pattern to search for
pathstringNoProject rootDirectory or file to search in
fileTypesarrayNoAll code filesFile extensions to include (e.g., ["ts", "js"])
contextLinesnumberNo0Lines of context before and after each match
excludeTestsbooleanNofalseExclude test and spec files
limitnumberNo100Maximum number of matches to return
multilinebooleanNofalseEnable patterns that span multiple lines

MCP Command Syntax

mcp__stellarion__search_pattern pattern:"regex" path:src/ fileTypes:["ts","js"] contextLines:2

Examples

Find TODO Comments

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


Find Console Statements

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)


Find Async Functions

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


Find Import Statements

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


Find Export Declarations

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


Find Deprecated API Usage

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


Find Error Handling Patterns

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


Find Specific Decorators

Natural Language:

Find all @Injectable decorators

Direct MCP Call:

mcp__stellarion__search_pattern pattern:"@Injectable\\(.*\\)" fileTypes:["ts"]

Returns: All classes with the Injectable decorator

Output Format

Each result includes:

FieldDescription
File pathLocation of the match
Line numberLine where the match was found
Matching lineThe content of the matching line
Context linesSurrounding lines if contextLines was specified
Match countTotal matches per file

Regex Tips

Escaping Special Characters

Use \\ to escape regex special characters:

CharacterEscapeExample
.\\.console\\.log
( )\\( \\)function\\(
[ ]\\[ \\]array\\[0\\]
{ }\\{ \\}interface\\{\\}

Common Patterns

GoalPattern
Word boundary\\bword\\b
Any whitespace\\s+
Word characters\\w+
Start of line^pattern
End of linepattern$
Optionalpatterns?
One or morepattern+
Zero or morepattern*

Combining with Other Tools

Pattern search works well with other Stellarion tools:

  1. Find, then analyze: Use search_pattern to find code, then get_code_element to extract full implementations
  2. Find, then measure: Use search_pattern to locate files, then batch_analyze for complexity metrics
  3. Pattern + semantic: Use search_pattern for exact matches, search_semantic for conceptual matches

Tips for Effective Searches

  1. Start simple: Begin with a basic pattern and refine if needed
  2. Use file type filters: Narrow results with fileTypes:["ts","tsx"]
  3. Exclude tests: Add excludeTests:true when searching production code
  4. Add context: Use contextLines:2 to understand matches in context
  5. Limit results: Use limit:50 for faster results on large codebases