search_files
Recursively locate files or directories by specifying a starting path and a case-insensitive search pattern, enabling precise navigation and discovery within allowed filesystem paths.
Instructions
Recursively search for files/directories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Starting directory for search | |
| pattern | Yes | Search pattern (case-insensitive) |
Implementation Reference
- src/index.ts:372-409 (handler)Handler for the 'search_files' tool. Recursively searches the directory starting from the given path for entries matching the pattern (case-insensitive RegExp on name), collects full paths of matches, and returns them as newline-separated text content.case 'search_files': { const { path: dirPath, pattern } = request.params.arguments as { path: string; pattern: string }; validatePath(dirPath); const results: string[] = []; const patternRegex = new RegExp(pattern, 'i'); async function searchDirectory(currentPath: string) { const entries = await fs.readdir(currentPath); for (const entry of entries) { const entryPath = path.join(currentPath, entry); const stats = await fs.stat(entryPath); if (patternRegex.test(entry)) { results.push(entryPath); } if (stats.isDirectory()) { await searchDirectory(entryPath); } } } await searchDirectory(dirPath); return { content: [ { type: 'text', text: results.join('\n'), }, ], }; }
- src/index.ts:190-207 (registration)Registration of the 'search_files' tool in the ListTools response, including name, description, and input schema requiring 'path' and 'pattern'.{ name: 'search_files', description: 'Recursively search for files/directories', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Starting directory for search', }, pattern: { type: 'string', description: 'Search pattern (case-insensitive)', }, }, required: ['path', 'pattern'], }, },