Skip to main content
Glama

glob_search

Search for files and directories using glob patterns within specified base paths, with configurable result limits and directory inclusion options.

Instructions

Find files matching a glob pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesGlob pattern (e.g., **/*.ts)
base_pathNoBase directory for search
max_resultsNoMaximum results (default: 1000)
include_dirsNoInclude directories in results

Implementation Reference

  • The implementation of the glob_search tool.
    async function globSearchImpl(input: GlobSearchInput): Promise<ToolResult> {
      try {
        const basePath = input.base_path ? path.resolve(input.base_path) : process.cwd();
    
        // Use glob to find matching files
        const matches = await glob(input.pattern, {
          cwd: basePath,
          nodir: !input.include_dirs,
          absolute: true,
          maxDepth: 20, // Prevent excessive recursion
        });
    
        // Limit results
        const limitedMatches = matches.slice(0, input.max_results);
    
        // Get basic info for each match
        const results = await Promise.all(
          limitedMatches.map(async (filePath) => {
            try {
              const stats = await fs.stat(filePath);
              return {
                path: filePath,
                name: path.basename(filePath),
                isFile: stats.isFile(),
                isDirectory: stats.isDirectory(),
                size: stats.size,
              };
            } catch {
              return {
                path: filePath,
                name: path.basename(filePath),
                error: 'Could not stat file',
              };
            }
          })
        );
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  count: results.length,
                  total_matches: matches.length,
                  truncated: matches.length > input.max_results,
                  results,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        const err = error as Error;
    
        return {
          isError: true,
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                code: 'UNKNOWN_ERROR',
                message: `Error in glob search: ${err.message}`,
              }),
            },
          ],
        };
      }
    }
  • Registration of the glob_search tool with the MCP server.
    // glob_search tool
    server.tool(
      'glob_search',
      'Find files matching a glob pattern',
      {
        pattern: z.string().describe('Glob pattern (e.g., **/*.ts)'),
        base_path: z.string().optional().describe('Base directory for search'),
        max_results: z.number().optional().describe('Maximum results (default: 1000)'),
        include_dirs: z.boolean().optional().describe('Include directories in results'),
      },
      async (args) => {
        const input = GlobSearchInputSchema.parse(args);
        return await globSearchImpl(input);
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden but reveals little beyond the basic operation. It doesn't disclose behavioral traits like whether the search is recursive by default, how errors are handled (e.g., invalid patterns), performance implications for large directories, or what the output format looks like (e.g., list of paths).

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 waste. It's front-loaded with the core purpose and appropriately sized for a tool with well-documented parameters in the schema.

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 inadequate. It doesn't explain what the tool returns (e.g., array of file paths, error formats), how results are ordered, or constraints like pattern syntax limitations. The schema covers parameter mechanics, but the description fails to provide necessary context for effective 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 description coverage is 100%, so the schema fully documents all parameters. The description adds no additional meaning beyond implying a search operation, which the schema already covers with parameter descriptions like 'Glob pattern' and 'Base directory for search'. Baseline 3 is appropriate when the schema does the heavy lifting.

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 verb 'Find' and the resource 'files matching a glob pattern', making the purpose immediately understandable. However, it doesn't explicitly differentiate this from sibling tools like 'find_by_content' or 'grep_search', which also search for files but using different criteria.

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 'find_by_content' (content-based search) or 'grep_search' (regex-based search). It also doesn't mention prerequisites, such as whether the base_path must exist or be accessible.

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/mcp-tool-shop-org/mcp-file-forge'

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