read_multiple_files
Read multiple files at once to access their contents efficiently. Returns each file's content with its path, continues reading even if some files fail, and operates within specified directories.
Instructions
Read the contents of multiple files simultaneously. Each file's content is returned with its path as a reference. Failed reads for individual files won't stop the entire operation. Only works within allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes |
Implementation Reference
- src/server.ts:273-279 (handler)MCP server handler for the 'read_multiple_files' tool: parses input arguments, calls the readMultipleFiles implementation, and formats the response.case "read_multiple_files": { const parsed = ReadMultipleFilesArgsSchema.parse(args); const results = await readMultipleFiles(parsed.paths); return { content: [{ type: "text", text: results.join("\n---\n") }], }; }
- src/tools/filesystem.ts:75-88 (helper)Core implementation function that reads multiple files concurrently, validates paths, reads contents or returns errors for each file individually.export async function readMultipleFiles(paths: string[]): Promise<string[]> { return Promise.all( paths.map(async (filePath: string) => { try { const validPath = await validatePath(filePath); const content = await fs.readFile(validPath, "utf-8"); return `${filePath}:\n${content}\n`; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return `${filePath}: Error - ${errorMessage}`; } }), ); }
- src/tools/schemas.ts:36-38 (schema)Zod schema defining the input arguments for the read_multiple_files tool: an array of file paths.export const ReadMultipleFilesArgsSchema = z.object({ paths: z.array(z.string()), });
- src/server.ts:134-141 (registration)Tool registration in the MCP server's tools array, specifying name, description, and input schema.name: "read_multiple_files", description: "Read the contents of multiple files simultaneously. " + "Each file's content is returned with its path as a reference. " + "Failed reads for individual files won't stop the entire operation. " + "Only works within allowed directories.", inputSchema: zodToJsonSchema(ReadMultipleFilesArgsSchema), },