searchGlob
Locate files in a directory by matching a specific glob pattern. Specify the pattern and path to streamline file searches efficiently.
Instructions
Search for files matching a pattern
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | The directory to search in. Defaults to the current working directory. | |
| pattern | Yes | The glob pattern to match files against |
Implementation Reference
- src/utils/file.ts:70-80 (handler)The core implementation of searchGlob, which uses the Unix 'find' command to locate files matching the given pattern.export async function searchGlob( pattern: string, searchPath: string = process.cwd() ): Promise<string[]> { try { const { stdout } = await execPromise(`find ${searchPath} -type f -name "${pattern}" | sort`); return stdout.trim().split('\n').filter(Boolean); } catch (error) { throw error; } }
- src/server/tools.ts:107-130 (registration)Registers the MCP tool 'searchGlob' with input schema validation using Zod and a handler that delegates to the core searchGlob function.server.tool( "searchGlob", "Search for files matching a pattern", { pattern: z.string().describe("The glob pattern to match files against"), path: z.string().optional().describe("The directory to search in. Defaults to the current working directory.") }, async ({ pattern, path }) => { try { const results = await searchGlob(pattern, path); return { content: [{ type: "text", text: results.join('\n') }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }], isError: true }; } } );
- src/server/tools.ts:111-113 (schema)Input schema for the searchGlob tool using Zod for validation.pattern: z.string().describe("The glob pattern to match files against"), path: z.string().optional().describe("The directory to search in. Defaults to the current working directory.") },