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
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | File name pattern to search for (substring or regex) | |
| type | No | File type to filter by | any |
| useRegex | No | Treat pattern as a regular expression |
Implementation Reference
- src/tools/file-tools.ts:147-195 (handler)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" }, }); - src/tools/file-tools.ts:134-146 (schema)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"), }, - src/tools/file-tools.ts:130-146 (registration)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"), },