find_by_content
Search for files containing specific text within directories using file patterns and result limits to locate content efficiently.
Instructions
Find files containing specific text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to search for (literal, not regex) | |
| path | No | Directory to search | |
| file_pattern | No | File pattern (e.g., *.ts) | |
| max_results | No | Maximum results |
Implementation Reference
- src/tools/search.ts:243-260 (handler)Implementation of the find_by_content logic.
async function findByContentImpl(input: { text: string; path?: string; file_pattern?: string; max_results?: number; }): Promise<ToolResult> { // Escape special regex characters for literal search const escapedText = input.text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); return await grepSearchImpl({ pattern: escapedText, path: input.path, glob: input.file_pattern, case_sensitive: true, max_results: input.max_results ?? 100, context_lines: 0, }); } - src/tools/search.ts:300-313 (registration)Registration of the find_by_content MCP tool.
// find_by_content tool (simpler interface) server.tool( 'find_by_content', 'Find files containing specific text', { text: z.string().describe('Text to search for (literal, not regex)'), path: z.string().optional().describe('Directory to search'), file_pattern: z.string().optional().describe('File pattern (e.g., *.ts)'), max_results: z.number().optional().describe('Maximum results'), }, async (args) => { return await findByContentImpl(args); } );