Skip to main content
Glama

find_file

Search for files in Godot projects using name patterns or extensions, supporting substring or regex matching to locate scenes, scripts, or resources.

Instructions

Find files by name pattern or extension in the project. Supports substring or regex matching.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesFile name pattern to search for (substring or regex)
typeNoFile type to filter byany
useRegexNoTreat pattern as a regular expression

Implementation Reference

  • Handler logic for find_file which filters file paths based on pattern (regex/substring) and type (scene/script/resource/any) by querying the system index.
    handler: async (ctx) => {
      const { pattern, type = "any", useRegex = false } = ctx.args;
    
      let matcher: (path: string) => boolean;
      if (useRegex) {
        // Reject patterns with nested quantifiers that cause catastrophic backtracking
        if (/(\+|\*|\{)\s*\??\s*[^+*?{}]*(\+|\*|\{)/.test(pattern) || pattern.length > 200) {
          return makeTextResponse({
            error:
              "Regex pattern rejected: nested quantifiers or excessive length may cause slow matching",
            data: null,
          });
        }
        try {
          const re = new RegExp(pattern);
          matcher = (p) => re.test(p);
        } catch {
          return makeTextResponse({
            error: `Invalid regex pattern: ${pattern}`,
            data: null,
          });
        }
      } else {
        matcher = (p) => p.includes(pattern);
      }
    
      const results: string[] = [];
    
      if (type === "any" || type === "scene") {
        for (const p of index.sceneIndex.allPaths()) {
          if (matcher(p)) results.push(p);
        }
      }
      if (type === "any" || type === "script") {
        for (const p of index.scriptIndex.allPaths()) {
          if (matcher(p)) results.push(p);
        }
      }
      if (type === "any" || type === "resource") {
        for (const p of index.resourceIndex.allPaths()) {
          if (matcher(p)) results.push(p);
        }
      }
    
      return makeTextResponse({
        data: results,
        totalCount: results.length,
        metadata: { source: "index" },
      });
  • Input validation schema for find_file using zod.
    schema: {
      pattern: z.string().describe("File name pattern to search for (substring or regex)"),
      type: z
        .enum(["scene", "script", "resource", "any"])
        .optional()
        .default("any")
        .describe("File type to filter by"),
      useRegex: z
        .boolean()
        .optional()
        .default(false)
        .describe("Treat pattern as a regular expression"),
    },
  • Registration of the find_file tool within the tools array.
    {
      name: "find_file",
      description:
        "Find files by name pattern or extension in the project. Supports substring or regex matching.",
      schema: {
        pattern: z.string().describe("File name pattern to search for (substring or regex)"),
        type: z
          .enum(["scene", "script", "resource", "any"])
          .optional()
          .default("any")
          .describe("File type to filter by"),
        useRegex: z
          .boolean()
          .optional()
          .default(false)
          .describe("Treat pattern as a regular expression"),
      },

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/woohq/godette-mcp'

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