Skip to main content
Glama

find

Search for files and directories using pattern matching, filtering by depth, and excluding ignored files to locate specific items in a directory.

Instructions

Find files and directories with pattern matching and filtering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesDirectory path to search (required)
patternNoFile pattern to match (*.js,**/*.test.ts,!**/node_modules/**). Use ! to exclude, comma-separated
depthNoMaximum depth to recurse (default: 0 = unlimited)
includeIgnoredNoInclude files ignored by .gitignore (default: false)

Implementation Reference

  • The execute method of the FindTool class that handles tool invocation: validates input with Zod schema, uses DirectoryUtils.findFiles for the core logic, formats results as newline-separated relative paths, and handles errors.
    async execute(args: any): Promise<any> {
      try {
        // Validate and parse input using Zod schema
        const validatedArgs = FindToolInputSchema.parse(args);
        const { path: targetPath, depth, includeIgnored, pattern: filterPath } = validatedArgs;
    
        const basePath = targetPath || ".";
    
        // Use DirectoryUtils for file finding with all the same features
        const options: any = {
          includeIgnored,
          includeFiles: true,
          includeDirectories: true,
        };
        if (depth > 0) {
          options.maxDepth = depth;
        }
        const results = await DirectoryUtils.findFiles(basePath, filterPath, options);
    
        // Format results as relative paths (maintaining original behavior)
        const relativePaths = results.map((result) => {
          const path = result.relativePath;
          return result.isDirectory ? `${path}/` : path;
        });
    
        return ResultFormatter.createResponse(relativePaths.join("\n"));
      } catch (error) {
        // Handle Zod validation errors
        if (error instanceof Error && error.name === "ZodError") {
          throw ToolError.createValidationError("input", args, `Invalid input: ${error.message}`);
        }
        throw ToolError.wrapError("Find operation", error);
      }
    }
  • Zod input schema (FindToolInputSchema) defining parameters for the find tool: path (required), optional pattern, depth, and includeIgnored flag.
    // Find tool input schema
    export const FindToolInputSchema = z.object({
      path: FilePathSchema,
      pattern: z.string().optional(),
      depth: z.number().int().min(0).default(0),
      includeIgnored: BooleanFlagSchema,
    });
  • Tool registration in getTools() method: includes FindTool.getDefinition() in the list of available tools returned by the MCP server.
    protected getTools(): Tool[] {
      return [
        this.readTool.getDefinition(),
        this.findTool.getDefinition(),
        this.grepTool.getDefinition(),
        this.writeTool.getDefinition(),
        this.editTool.getDefinition(),
        this.moveTool.getDefinition(),
        this.copyTool.getDefinition(),
      ];
  • Tool dispatch registration in handleToolCall switch statement: routes 'find' calls to this.findTool.execute().
    case "find":
      return await this.findTool.execute(args);
  • Supporting utility DirectoryUtils.findFiles: parses patterns, traverses directory with filtering, gitignore respect, and depth limits, returns matching file/directory results used by the find handler.
    static async findFiles(
      basePath: string,
      filterPatterns?: string,
      options: Omit<TraversalOptions, "includePatterns" | "excludePatterns"> = {}
    ): Promise<TraversalResult[]> {
      const { include, exclude } = DirectoryUtils.parseFilterPatterns(filterPatterns);
    
      const results: TraversalResult[] = [];
    
      for await (const entry of DirectoryUtils.traverseDirectory(basePath, {
        ...options,
        includePatterns: include,
        excludePatterns: exclude,
        includeFiles: true,
        includeDirectories: options.includeDirectories !== false,
      })) {
        results.push(entry);
      }
    
      return results;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pattern matching and filtering but doesn't cover important aspects like whether this is a read-only operation (implied but not stated), performance characteristics, error handling, or output format. For a tool with 4 parameters and no annotation coverage, this is insufficient behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that efficiently communicates the core functionality. Every word earns its place with no redundancy or unnecessary elaboration. The structure is front-loaded with the essential purpose statement.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (list of paths? file objects?), error conditions, performance implications of depth settings, or how pattern syntax works beyond what's in the schema. The agent would need to guess about important behavioral aspects.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions pattern matching and filtering, which aligns with the 'pattern' and 'includeIgnored' parameters, but doesn't add significant meaning beyond what's already in the schema descriptions (which have 100% coverage). It doesn't explain the relationship between parameters or provide usage examples. With complete schema coverage, the baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as finding files and directories with pattern matching and filtering, which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'grep' (which might search file contents) or 'read' (which reads file contents), leaving some ambiguity about when to choose this tool over alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'grep' or 'read'. It mentions pattern matching and filtering but doesn't specify use cases, prerequisites, or exclusions. This leaves the agent without clear context for tool selection among the available siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/d-issy/mcp'

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