Skip to main content
Glama
lofcz

MCP Smart Filesystem Server

by lofcz

find_files

Search for files by name using pattern matching with wildcards, character matching, and multiple extensions to quickly locate specific files in your filesystem.

Instructions

Find files by name using fast pattern matching.

PATTERN EXAMPLES:

  • Exact name: "config.json"

  • Wildcard: "*.config" or "Handler"

  • Multiple extensions: "*.{ts,tsx,js}"

TIPS:

  • Use * for any characters

  • Use ? for single character

  • Use {a,b,c} for alternatives

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesFilename pattern. Examples: 'Component.tsx', '*.json', '*Handler*', '*.{ts,tsx}'
pathNoLimit search to specific directory

Implementation Reference

  • Core implementation of the find_files tool. Uses ripgrep --files to list all files in allowed directories, then filters by custom glob pattern matching using matchPattern.
    export async function ripgrepFindFiles(
      pattern: string,
      searchPath: string | undefined,
      allowedDirs: string[]
    ): Promise<string[]> {
      const args = ['--files', '--no-config'];
      
      let searchPaths: string[];
      if (searchPath) {
        try {
          const validated = await validatePath(path.join(allowedDirs[0], searchPath));
          searchPaths = [validated];
        } catch (error) {
          throw new Error(`Invalid search path: ${error instanceof Error ? error.message : String(error)}`);
        }
      } else {
        searchPaths = allowedDirs;
      }
      
      args.push(...searchPaths);
      
      return new Promise((resolve, reject) => {
        const rg = spawn('rg', args);
        let stdout = '';
        let stderr = '';
        
        rg.stdout.on('data', (data) => stdout += data);
        rg.stderr.on('data', (data) => stderr += data);
        
        rg.on('close', (code) => {
          if (code === 0 || code === 1) {
            const allFiles = stdout.trim().split('\n').filter(f => f);
            
            // Filter by pattern (simple glob matching)
            const matching = allFiles.filter(file => {
              const filename = path.basename(file);
              return matchPattern(filename, pattern);
            });
            
            resolve(matching);
          } else {
            reject(new Error(`ripgrep failed: ${stderr}`));
          }
        });
        
        rg.on('error', (error) => {
          reject(new Error(`Failed to spawn ripgrep: ${error.message}`));
        });
      });
    }
  • index.ts:207-234 (registration)
    Registration of the 'find_files' tool in the tools array, including name, description, and input schema.
      {
        name: 'find_files',
        description: `Find files by name using fast pattern matching.
    
    PATTERN EXAMPLES:
      - Exact name: "config.json"
      - Wildcard: "*.config" or "*Handler*"
      - Multiple extensions: "*.{ts,tsx,js}"
      
    TIPS:
      - Use * for any characters
      - Use ? for single character  
      - Use {a,b,c} for alternatives`,
        inputSchema: {
          type: 'object',
          properties: {
            pattern: {
              type: 'string',
              description: "Filename pattern. Examples: 'Component.tsx', '*.json', '*Handler*', '*.{ts,tsx}'"
            },
            path: {
              type: 'string',
              description: 'Limit search to specific directory'
            }
          },
          required: ['pattern']
        }
      },
  • Tool dispatch handler for 'find_files' in the main CallToolRequestSchema handler. Calls ripgrepFindFiles and adds metadata like size and line counts to results.
    case 'find_files': {
      const schema = z.object({
        pattern: z.string(),
        path: z.string().optional()
      });
      const { pattern, path } = schema.parse(args);
      
      const files = await ripgrepFindFiles(pattern, path, getAllowedDirectories());
      
      // Get metadata for each file
      const filesWithMetadata = await Promise.all(
        files.map(async (file) => {
          try {
            const stats = await getFileStats(file);
            let lines: number | undefined;
            
            if (stats.isFile && stats.size < 10 * 1024 * 1024) {
              const isBinary = await isBinaryFile(file);
              if (!isBinary) {
                try {
                  const content = await readFileContent(file);
                  lines = countLines(content);
                } catch {
                  // Ignore
                }
              }
            }
            
            return {
              path: file,
              size: `${stats.size} bytes`,
              lines,
              matchType: 'match',
              hint: `Matches pattern '${pattern}'`
            };
          } catch {
            return {
              path: file,
              matchType: 'match'
            };
          }
        })
      );
      
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            query: {
              pattern,
              searchedIn: path || getAllowedDirectories().join(', ')
            },
            files: filesWithMetadata,
            summary: {
              totalFiles: filesWithMetadata.length,
              searchTimeMs: 0
            }
          }, null, 2)
        }]
      };
  • Helper function used by ripgrepFindFiles to match filenames against glob patterns, converting globs to regex.
    function matchPattern(filename: string, pattern: string): boolean {
      // If pattern doesn't contain wildcards, add implicit wildcards for partial matching
      const hasWildcards = pattern.includes('*') || pattern.includes('?') || pattern.includes('{');
      
      if (!hasWildcards) {
        // For patterns without wildcards, match if the pattern appears anywhere in the filename
        return filename.toLowerCase().includes(pattern.toLowerCase());
      }
      
      // Convert glob pattern to regex
      const regex = new RegExp(
        '^' + pattern
          .replace(/\./g, '\\.')
          .replace(/\*/g, '.*')
          .replace(/\?/g, '.')
          .replace(/\{([^}]+)\}/g, (_, alternatives) => `(${alternatives.replace(/,/g, '|')})`)
        + '$',
        'i'
      );
      return regex.test(filename);
    }
  • Zod schema for input validation in the find_files handler.
    const schema = z.object({
      pattern: z.string(),
      path: z.string().optional()
    });
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'fast pattern matching' which hints at performance, but doesn't cover critical aspects like permissions needed, whether it's read-only or has side effects, rate limits, error conditions, or what the output looks like. The pattern examples are helpful but insufficient for full transparency.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, examples, tips) and efficiently communicates key information. The pattern examples and tips are valuable additions. However, the 'TIPS' section could be more concise, and some information (like wildcard syntax) is somewhat redundant with the schema description.

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

Completeness3/5

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

For a 2-parameter tool with no annotations and no output schema, the description provides adequate basic information about what the tool does and how to use patterns. However, it lacks important context about behavioral aspects (permissions, side effects), output format, and differentiation from sibling tools. The pattern examples help but don't fully compensate for missing behavioral transparency.

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 description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds pattern examples and wildcard syntax that complement the schema's 'pattern' parameter description, but doesn't provide additional semantic meaning beyond what's in the structured fields. This meets the baseline for high schema coverage.

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: 'Find files by name using fast pattern matching.' It specifies the verb ('find'), resource ('files'), and method ('pattern matching'), but doesn't explicitly differentiate from sibling tools like 'search_code' or 'search_in_file' that might have overlapping functionality.

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 'search_code' or 'search_in_file'. It includes pattern examples and tips, but these are syntax instructions rather than usage context. There's no mention of prerequisites, limitations, or comparative scenarios.

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/lofcz/mcp-filesystem-smart'

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