Skip to main content
Glama
koopatroopa787

MCP PC Control Server

search_files

Find files by name or extension using wildcard patterns in specified directories. Recursively searches and returns matching file paths for file management tasks.

Instructions

Recursively search for files matching a pattern in a directory. Supports wildcards (* and **) and returns matching file paths. Useful for finding files by name or extension.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe directory to search in
patternYesThe pattern to match (e.g., '*.ts', '**/*.json')

Implementation Reference

  • Handler case within the CallToolRequestSchema request handler that parses input arguments, invokes the searchFiles helper function, and returns the search results in JSON format.
    case "search_files": {
      const searchPath = args.path as string;
      const pattern = args.pattern as string;
    
      const results = await searchFiles(searchPath, pattern);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                matches: results,
                count: results.length,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Input schema defining the parameters for the search_files tool: path (directory to search) and pattern (glob-like pattern to match). Used for validation.
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "The directory to search in",
        },
        pattern: {
          type: "string",
          description: "The pattern to match (e.g., '*.ts', '**/*.json')",
        },
      },
      required: ["path", "pattern"],
    },
  • src/index.ts:190-207 (registration)
    Registration of the search_files tool in the TOOLS array, which is returned by the ListToolsRequestSchema handler. Includes name, description, and schema.
    {
      name: "search_files",
      description: "Recursively search for files matching a pattern in a directory. Supports wildcards (* and **) and returns matching file paths. Useful for finding files by name or extension.",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "The directory to search in",
          },
          pattern: {
            type: "string",
            description: "The pattern to match (e.g., '*.ts', '**/*.json')",
          },
        },
        required: ["path", "pattern"],
      },
    },
  • Helper function implementing the core recursive file search logic: converts glob pattern to regex, traverses directory tree, and collects absolute paths of matching files.
    async function searchFiles(
      dirPath: string,
      pattern: string
    ): Promise<string[]> {
      const results: string[] = [];
    
      // Convert glob pattern to regex
      const regexPattern = pattern
        .replace(/\./g, "\\.")
        .replace(/\*\*/g, ".*")
        .replace(/\*/g, "[^/]*");
      const regex = new RegExp(regexPattern);
    
      async function search(currentPath: string) {
        try {
          const entries = await fs.readdir(currentPath, { withFileTypes: true });
    
          for (const entry of entries) {
            const fullPath = path.join(currentPath, entry.name);
            const relativePath = path.relative(dirPath, fullPath);
    
            if (entry.isDirectory()) {
              await search(fullPath);
            } else if (regex.test(relativePath)) {
              results.push(fullPath);
            }
          }
        } catch (error) {
          // Skip directories we can't access
        }
      }
    
      await search(dirPath);
      return results;
    }
Behavior3/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 effectively describes the recursive nature and wildcard support, but lacks details on permissions needed, error handling, or output format (e.g., pagination, sorting).

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 appropriately sized and front-loaded, with two efficient sentences that directly convey the tool's functionality and use case without any wasted words or redundancy.

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?

Given the tool's moderate complexity (search with recursion and pattern matching), no annotations, and no output schema, the description is adequate but incomplete—it covers the core behavior but omits details like return format, error conditions, or performance considerations.

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 schema description coverage is 100%, so the schema already documents both parameters fully. The description adds minimal value by mentioning wildcard examples ('*.ts', '**/*.json'), but does not provide additional syntax or format details beyond what the schema implies.

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 specific action ('recursively search for files matching a pattern'), resource ('files'), and scope ('in a directory'), distinguishing it from siblings like list_directory (which lists without pattern matching) or get_file_info (which retrieves metadata for a specific file).

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('useful for finding files by name or extension'), but does not explicitly state when not to use it or name alternatives among the siblings (e.g., list_directory for unfiltered listing).

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/koopatroopa787/first_mcp'

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