list-files
Preview files that ripgrep would search before running actual searches. Filter by file type, glob patterns, or include hidden files to scope your search targets.
Instructions
List files that would be searched by ripgrep without actually searching them
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Directory or file(s) to search. | |
| filePattern | No | Filter by file type or glob | |
| fileType | No | Filter by file type (e.g., js, py) | |
| includeHidden | No | Include hidden files and directories |
Implementation Reference
- src/index.ts:441-488 (handler)The main handler function for the 'list-files' tool, which executes 'rg --files' with optional filters like filePattern, fileType, and includeHidden, processes the output, and returns the list of files.case "list-files": { const path = String(args.path); const filePattern = args.filePattern ? String(args.filePattern) : undefined; const fileType = args.fileType ? String(args.fileType) : undefined; const includeHidden = typeof args.includeHidden === 'boolean' ? args.includeHidden : undefined; // Build the rg command with flags let command = "rg --files"; // Add file pattern if specified if (filePattern) { command += ` -g ${escapeShellArg(filePattern)}`; } // Add file type if specified if (fileType) { command += ` -t ${fileType}`; } // Add hidden files flag if specified if (includeHidden === true) { command += " -." } // No colors for file listing command += " --color never"; // Add path command += ` ${escapeShellArg(path)}`; console.error(`Executing: ${command}`); const { stdout, stderr } = await exec(command); // If there's anything in stderr, log it for debugging if (stderr) { console.error(`ripgrep stderr: ${stderr}`); } return { content: [ { type: "text", text: stripAnsiEscapeCodes(stdout) || "No files found" } ] }; }
- src/index.ts:155-168 (schema)The input schema definition and registration of the 'list-files' tool in the ListToolsRequestHandler.{ name: "list-files", description: "List files that would be searched by ripgrep without actually searching them", inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory or file(s) to search." }, filePattern: { type: "string", description: "Filter by file type or glob" }, fileType: { type: "string", description: "Filter by file type (e.g., js, py)" }, includeHidden: { type: "boolean", description: "Include hidden files and directories" } }, required: ["path"] } },
- src/index.ts:185-185 (registration)Tool name validation check in the CallToolRequestHandler switch dispatch.if (!["search", "advanced-search", "count-matches", "list-files", "list-file-types"].includes(toolName)) {