Skip to main content
Glama
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

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "maxFiles": { "default": 20, "description": "最大文件数量限制", "type": "number" }, "patterns": { "description": "文件模式数组,如 ['modules/*/services/*.ts', 'config/*.ts']", "items": { "type": "string" }, "type": "array" } }, "required": [ "patterns" ], "type": "object" }

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

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