Skip to main content
Glama
ai-yliu

Filesystem MCP Server

by ai-yliu

search_files

Recursively search for files and directories by pattern from a starting directory to locate specific items in the filesystem.

Instructions

Recursively search for files/directories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesStarting directory for search
patternYesSearch pattern (case-insensitive)

Implementation Reference

  • Handler for 'search_files' tool: extracts arguments, validates path, performs recursive directory traversal using fs.readdir and fs.stat, matches entry names against case-insensitive RegExp pattern, collects full paths of matches, returns as newline-separated text content.
    case 'search_files': {
      const { path: dirPath, pattern } = request.params.arguments as { 
        path: string; 
        pattern: string 
      };
      validatePath(dirPath);
      
      const results: string[] = [];
      const patternRegex = new RegExp(pattern, 'i');
      
      async function searchDirectory(currentPath: string) {
        const entries = await fs.readdir(currentPath);
        
        for (const entry of entries) {
          const entryPath = path.join(currentPath, entry);
          const stats = await fs.stat(entryPath);
          
          if (patternRegex.test(entry)) {
            results.push(entryPath);
          }
          
          if (stats.isDirectory()) {
            await searchDirectory(entryPath);
          }
        }
      }
      
      await searchDirectory(dirPath);
      
      return {
        content: [
          {
            type: 'text',
            text: results.join('\n'),
          },
        ],
      };
    }
  • Schema definition in ListTools response for 'search_files' tool, defining input schema with required 'path' (starting directory) and 'pattern' (case-insensitive search pattern).
    {
      name: 'search_files',
      description: 'Recursively search for files/directories',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Starting directory for search',
          },
          pattern: {
            type: 'string',
            description: 'Search pattern (case-insensitive)',
          },
        },
        required: ['path', 'pattern'],
      },
    },
  • src/index.ts:93-232 (registration)
    The tool is registered by including its details in the tools array returned by the ListToolsRequest handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'read_file',
          description: 'Read complete contents of a file',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Path to the file to read',
              },
            },
            required: ['path'],
          },
        },
        {
          name: 'read_multiple_files',
          description: 'Read multiple files simultaneously',
          inputSchema: {
            type: 'object',
            properties: {
              paths: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'Array of file paths to read',
              },
            },
            required: ['paths'],
          },
        },
        {
          name: 'write_file',
          description: 'Create new file or overwrite existing',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Path to the file to write',
              },
              content: {
                type: 'string',
                description: 'Content to write to the file',
              },
            },
            required: ['path', 'content'],
          },
        },
        {
          name: 'create_directory',
          description: 'Create new directory or ensure it exists',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Path to the directory to create',
              },
            },
            required: ['path'],
          },
        },
        {
          name: 'list_directory',
          description: 'List directory contents with [FILE] or [DIR] prefixes',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Path to the directory to list',
              },
            },
            required: ['path'],
          },
        },
        {
          name: 'move_file',
          description: 'Move or rename files and directories',
          inputSchema: {
            type: 'object',
            properties: {
              source: {
                type: 'string',
                description: 'Source path',
              },
              destination: {
                type: 'string',
                description: 'Destination path',
              },
            },
            required: ['source', 'destination'],
          },
        },
        {
          name: 'search_files',
          description: 'Recursively search for files/directories',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Starting directory for search',
              },
              pattern: {
                type: 'string',
                description: 'Search pattern (case-insensitive)',
              },
            },
            required: ['path', 'pattern'],
          },
        },
        {
          name: 'get_file_info',
          description: 'Get detailed file/directory metadata',
          inputSchema: {
            type: 'object',
            properties: {
              path: {
                type: 'string',
                description: 'Path to the file or directory',
              },
            },
            required: ['path'],
          },
        },
        {
          name: 'list_allowed_directories',
          description: 'List all directories the server is allowed to access',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
      ],
    }));
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'recursively' (a useful behavioral trait) but omits critical details like whether the search is read-only, what permissions are needed, how results are returned (e.g., format, pagination), or error handling. For a search tool with zero annotation coverage, this is insufficient.

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 a single, efficient sentence with zero wasted words. It is front-loaded with the core action ('search') and includes the key modifier ('recursively'), making it highly concise and well-structured for quick understanding.

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?

Given the tool's complexity (a search operation with two parameters), lack of annotations, and no output schema, the description is incomplete. It fails to address behavioral aspects like result format, error cases, or performance implications, leaving significant gaps for an agent to use it effectively.

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%, with both parameters ('path' and 'pattern') clearly documented in the schema. The description adds no additional parameter semantics beyond what the schema provides, such as examples of patterns or path constraints. 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 action ('search for files/directories') and resource ('files/directories'), with the adverb 'recursively' adding specificity about the search scope. However, it doesn't explicitly differentiate this tool from sibling tools like 'list_directory' or 'get_file_info', which prevents a perfect score.

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. With siblings like 'list_directory' (likely for listing without searching) and 'get_file_info' (likely for single-file details), the agent receives no help in choosing between them, leaving usage context implied at best.

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/ai-yliu/filesystem-mcp-server'

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