Skip to main content
Glama
StrawHatAI

Claude Desktop Commander MCP

by StrawHatAI

search_files

Find files and directories matching patterns across subdirectories from a specified path within allowed locations.

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

  • The core handler function that recursively searches files matching the given pattern within the allowed directories starting from rootPath.
    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 the 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)
    Tool registration in the list of available tools, specifying name, description, and input schema.
    {
      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),
  • Dispatch handler in the main tool call switch statement that parses arguments and invokes the searchFiles function.
    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/StrawHatAI/claude-dev-tools'

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