Skip to main content
Glama

find_files

Search for files in directories using glob patterns like '.ts' or 'index.' to quickly locate matching filenames.

Instructions

Find files by name glob pattern (e.g. '.ts', 'index.').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesDirectory to search in
patternYesGlob pattern for filename (e.g. '*.ts')
max_resultsNoMax results to return (default 200)
workspace_rootNoWorkspace root directory (optional)

Implementation Reference

  • Core handler function that recursively walks directories, filters out hidden dirs/node_modules/dist, and matches filenames against a glob pattern.
    async function findFiles(
      dir: string,
      pattern: string,
      maxResults = 200
    ): Promise<string[]> {
      const results: string[] = [];
      async function walk(current: string) {
        if (results.length >= maxResults) return;
        let entries;
        try {
          entries = await readdir(current, { withFileTypes: true });
        } catch {
          return;
        }
        for (const entry of entries) {
          if (results.length >= maxResults) return;
          if (entry.name.startsWith(".") || entry.name === "node_modules" || entry.name === "dist") continue;
          const full = join(current, entry.name);
          if (entry.isDirectory()) {
            await walk(full);
          } else if (matchGlob(entry.name, pattern)) {
            results.push(full);
          }
        }
      }
      await walk(dir);
      return results;
    }
  • Tool definition/input schema for find_files, declaring directory, pattern, max_results, workspace_root parameters.
    {
      name: "find_files",
      description: "Find files by name glob pattern (e.g. '*.ts', 'index.*').",
      inputSchema: {
        type: "object",
        properties: {
          directory: { type: "string", description: "Directory to search in" },
          pattern: { type: "string", description: "Glob pattern for filename (e.g. '*.ts')" },
          max_results: { type: "number", description: "Max results to return (default 200)" },
          workspace_root: { type: "string", description: "Workspace root directory (optional)" },
        },
        required: ["directory", "pattern"],
      },
    },
  • src/index.ts:521-528 (registration)
    Registration/dispatch logic inside the CallToolRequestSchema handler that invokes findFiles and formats the response.
    case "find_files": {
      const dir = resolveWorkspacePath(a.directory as string, a.workspace_root as string | undefined);
      const files = await findFiles(dir, a.pattern as string, (a.max_results as number | undefined) ?? 200);
      if (files.length === 0) {
        return { content: [{ type: "text", text: "No files found." }] };
      }
      return { content: [{ type: "text", text: files.join("\n") }] };
    }
  • Helper function that converts a glob pattern to a regex for filename matching.
    function matchGlob(name: string, pattern: string): boolean {
      const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
      return new RegExp(`^${escaped}$`).test(name);
    }
Behavior2/5

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

No annotations exist, and the description does not disclose behavioral traits such as recursion, case sensitivity, or performance characteristics. It only states the basic operation without deeper 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?

A single, front-loaded sentence with no unnecessary words. Every part serves to convey the core function efficiently.

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?

Despite having 4 parameters and no output schema, the description omits crucial details like recursion behavior, return format, default max_results, and error handling, making it incomplete for effective agent use.

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?

Schema coverage is 100% with descriptions for all parameters. The description adds a useful example for the pattern parameter but no additional meaning for other parameters.

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

Purpose5/5

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

The description clearly states the tool finds files by name glob pattern with concrete examples, distinguishing it from siblings like search_files (content search) and list_directory (no pattern).

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

Usage Guidelines3/5

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

The description implies usage through the glob pattern example but provides no explicit guidance on when to use this tool versus alternatives like search_files or list_directory.

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/KloutDevs/vscode-mcp'

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