Skip to main content
Glama

searchGlob

Find files matching a specific pattern within directories to locate code, documents, or resources using glob matching syntax.

Instructions

Search for files matching a pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesThe glob pattern to match files against
pathNoThe directory to search in. Defaults to the current working directory.

Implementation Reference

  • Core implementation of the searchGlob tool. Uses the 'find' shell command to locate files matching the given pattern in the specified path.
    export async function searchGlob(
      pattern: string,
      searchPath: string = process.cwd()
    ): Promise<string[]> {
      try {
        const { stdout } = await execPromise(`find ${searchPath} -type f -name "${pattern}" | sort`);
        return stdout.trim().split('\n').filter(Boolean);
      } catch (error) {
        throw error;
      }
    }
  • Zod input schema defining parameters for the searchGlob tool: pattern (required string) and path (optional string).
    {
      pattern: z.string().describe("The glob pattern to match files against"),
      path: z.string().optional().describe("The directory to search in. Defaults to the current working directory.")
    },
  • Registration of the searchGlob tool on the MCP server using server.tool(), including description, input schema, and thin wrapper handler that calls the core searchGlob function.
      "searchGlob",
      "Search for files matching a pattern",
      {
        pattern: z.string().describe("The glob pattern to match files against"),
        path: z.string().optional().describe("The directory to search in. Defaults to the current working directory.")
      },
      async ({ pattern, path }) => {
        try {
          const results = await searchGlob(pattern, path);
          return {
            content: [{ type: "text", text: results.join('\n') }]
          };
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: error instanceof Error ? error.message : String(error)
            }],
            isError: true
          };
        }
      }
    );

Tool Definition Quality

Score is being calculated. Check back soon.

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/auchenberg/claude-code-mcp'

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