list_project_files
Recursively list all files within configured sync directories, enabling efficient access and analysis of local project structures for AI applications.
Instructions
递归列出所有已配置同步目录中的文件
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- src/index.ts:253-267 (registration)Registration of the 'list_project_files' tool using server.tool(). Includes tool name, Chinese description, empty input schema ({}), and inline async handler that iterates over pathRegistry, calls getFilesRecursive for each path, formats file lists with prefixes, and returns as text content.server.tool( "list_project_files", "递归列出所有已配置同步目录中的文件", {}, async () => { let allFilesText = "项目文件列表:\n---\n"; for (const [prefix, absolutePath] of pathRegistry.entries()) { const files = await getFilesRecursive(absolutePath); if (files.length > 0) { allFilesText += files.map(file => `${prefix}/${file}`).join('\n') + '\n'; } } return { content: [{ type: "text", text: allFilesText }] }; } );
- src/index.ts:257-266 (handler)The inline handler function for list_project_files. Loops through registered project paths (pathRegistry), recursively gets files using getFilesRecursive, prefixes them, and returns a formatted text list of all project files.async () => { let allFilesText = "项目文件列表:\n---\n"; for (const [prefix, absolutePath] of pathRegistry.entries()) { const files = await getFilesRecursive(absolutePath); if (files.length > 0) { allFilesText += files.map(file => `${prefix}/${file}`).join('\n') + '\n'; } } return { content: [{ type: "text", text: allFilesText }] }; }
- src/index.ts:27-46 (helper)Helper function getFilesRecursive: Recursively traverses directory, skips ignored files/directories (IGNORED_PATTERNS), collects relative paths of all files (normalized to forward slashes), used by the tool handler and other tools.async function getFilesRecursive(directory: string): Promise<string[]> { let files: string[] = []; try { const dirents = await fs.readdir(directory, { withFileTypes: true }); for (const dirent of dirents) { if (IGNORED_PATTERNS.has(dirent.name)) continue; const fullPath = path.join(directory, dirent.name); const relativePath = path.relative(directory, fullPath); if (dirent.isDirectory()) { const subFiles = await getFilesRecursive(fullPath); files.push(...subFiles.map(sf => path.join(relativePath, sf).replace(/\\/g, '/'))); } else { files.push(relativePath.replace(/\\/g, '/')); } } } catch (error) { console.error(`Error reading directory ${directory}:`, error); } return files; }