Skip to main content
Glama
Cytrogen

Local Project Sync

by Cytrogen

read_multiple_files

Process multiple files simultaneously using glob patterns in local code repositories. Extract and analyze file contents for AI-driven project insights without manual uploads.

Instructions

批量读取多个文件内容,支持glob模式

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxFilesNo最大文件数量限制
patternsYes文件模式数组,如 ['modules/*/services/*.ts', 'config/*.ts']

Implementation Reference

  • Handler function that implements the logic for reading multiple files using glob patterns across synced directories, concatenating their contents with headers.
    async ({ patterns, maxFiles = 20 }) => {
      let allContent = "批量文件内容:\n" + "=".repeat(50) + "\n";
      let fileCount = 0;
    
      for (const [prefix, absolutePath] of pathRegistry.entries()) {
        for (const pattern of patterns) {
          try {
            const fullPattern = path.join(absolutePath, pattern);
            const matchedFiles = await glob(fullPattern, {
              ignore: ['**/node_modules/**', '**/.git/**']
            });
    
            for (const file of matchedFiles) {
              if (fileCount >= maxFiles) break;
    
              try {
                const relativePath = path.relative(absolutePath, file);
                const content = await fs.readFile(file, 'utf-8');
                allContent += `\n📄 ${prefix}/${relativePath}\n`;
                allContent += "-".repeat(30) + "\n";
                allContent += content + "\n";
                fileCount++;
              } catch (error) {
                allContent += `\n无法读取: ${file}\n`;
              }
            }
          } catch (error) {
            console.error(`处理模式 ${pattern} 时出错:`, error);
          }
    
          if (fileCount >= maxFiles) break;
        }
        if (fileCount >= maxFiles) break;
      }
    
      return { content: [{ type: "text", text: allContent }] };
    }
  • Zod schema defining the input parameters: patterns (array of glob patterns) and optional maxFiles.
    {
      patterns: z.array(z.string()).describe("文件模式数组,如 ['modules/*/services/*.ts', 'config/*.ts']"),
      maxFiles: z.number().optional().default(20).describe("最大文件数量限制"),
    },
  • src/index.ts:391-435 (registration)
    Registration of the 'read_multiple_files' tool on the MCP server, including name, description, schema, and handler function.
    server.tool(
      "read_multiple_files",
      "批量读取多个文件内容,支持glob模式",
      {
        patterns: z.array(z.string()).describe("文件模式数组,如 ['modules/*/services/*.ts', 'config/*.ts']"),
        maxFiles: z.number().optional().default(20).describe("最大文件数量限制"),
      },
      async ({ patterns, maxFiles = 20 }) => {
        let allContent = "批量文件内容:\n" + "=".repeat(50) + "\n";
        let fileCount = 0;
    
        for (const [prefix, absolutePath] of pathRegistry.entries()) {
          for (const pattern of patterns) {
            try {
              const fullPattern = path.join(absolutePath, pattern);
              const matchedFiles = await glob(fullPattern, {
                ignore: ['**/node_modules/**', '**/.git/**']
              });
    
              for (const file of matchedFiles) {
                if (fileCount >= maxFiles) break;
    
                try {
                  const relativePath = path.relative(absolutePath, file);
                  const content = await fs.readFile(file, 'utf-8');
                  allContent += `\n📄 ${prefix}/${relativePath}\n`;
                  allContent += "-".repeat(30) + "\n";
                  allContent += content + "\n";
                  fileCount++;
                } catch (error) {
                  allContent += `\n无法读取: ${file}\n`;
                }
              }
            } catch (error) {
              console.error(`处理模式 ${pattern} 时出错:`, error);
            }
    
            if (fileCount >= maxFiles) break;
          }
          if (fileCount >= maxFiles) break;
        }
    
        return { content: [{ type: "text", text: allContent }] };
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions batch reading and glob pattern support but lacks critical details: it doesn't specify file encoding, error handling (e.g., if some files are missing), performance implications (e.g., large files), or output format (e.g., array of file contents). For a tool with no annotations, this leaves significant gaps in understanding its behavior beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just two phrases: '批量读取多个文件内容,支持glob模式' (batch read multiple file contents, supports glob patterns). Every word earns its place by stating the core action and key feature without any fluff or redundancy. It's front-loaded with the main purpose, making it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (batch file reading with glob patterns), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., file contents, paths, errors), how results are structured, or any limitations (e.g., file size, permissions). For a tool that likely returns multiple data points, this omission makes it inadequate for full contextual understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for both parameters: 'patterns' as an array of file patterns and 'maxFiles' as a limit with a default of 20. The description adds minimal value beyond the schema by mentioning glob patterns, which is already implied in the schema's example. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '批量读取多个文件内容' (batch read multiple file contents) with the specific capability '支持glob模式' (supports glob patterns). It distinguishes from sibling tools like 'read_file_content' (single file) and 'list_project_files' (listing without reading content). However, it doesn't explicitly mention what distinguishes it from 'search_code_content' (which might also read files but with search functionality).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through '批量读取多个文件内容' (batch reading multiple files) and '支持glob模式' (glob patterns), suggesting this tool is for reading multiple files matching patterns rather than single files or other operations. However, it doesn't explicitly state when to use this vs. alternatives like 'read_file_content' (for single files) or 'search_code_content' (for searching within files), nor does it mention any exclusions or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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