Skip to main content
Glama
by Cytrogen

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

NameRequiredDescriptionDefault

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 }] }; } );
  • 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 }] }; }
  • 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; }

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/Cytrogen/local-project-sync'

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