Skip to main content
Glama

search_files

Recursively search files and directories by pattern from a specified path using the Desktop Commander MCP server. Quickly locate data within allowed subdirectories for efficient file management.

Instructions

Recursively search for files and directories matching a pattern. Searches through all subdirectories from the starting path. Only searches within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
patternYes

Implementation Reference

  • Core implementation of the search_files tool: recursively searches for files/directories matching the pattern starting from rootPath, respecting allowed directories.
    export async function searchFiles(rootPath: string, pattern: string): Promise<string[]> { const results: string[] = []; async function search(currentPath: string) { const entries = await fs.readdir(currentPath, { withFileTypes: true }); for (const entry of entries) { const fullPath = path.join(currentPath, entry.name); try { await validatePath(fullPath); if (entry.name.toLowerCase().includes(pattern.toLowerCase())) { results.push(fullPath); } if (entry.isDirectory()) { await search(fullPath); } } catch (error) { continue; } } } const validPath = await validatePath(rootPath); await search(validPath); return results; }
  • Zod schema defining input arguments for the search_files tool: path (starting directory) and pattern (search string).
    export const SearchFilesArgsSchema = z.object({ path: z.string(), pattern: z.string(), });
  • src/server.ts:172-178 (registration)
    Registration of the search_files tool in the ListTools response, including name, description, and input schema reference.
    { name: "search_files", description: "Recursively search for files and directories matching a pattern. " + "Searches through all subdirectories from the starting path. " + "Only searches within allowed directories.", inputSchema: zodToJsonSchema(SearchFilesArgsSchema),
  • Execution handler for search_files tool call: parses input, invokes searchFiles helper, formats and returns results.
    case "search_files": { const parsed = SearchFilesArgsSchema.parse(args); const results = await searchFiles(parsed.path, parsed.pattern); return { content: [{ type: "text", text: results.length > 0 ? results.join('\n') : "No matches found" }], };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MrGNSS/ClaudeDesktopCommander'

If you have feedback or need assistance with the MCP directory API, please join our Discord server