read_multiple_files
Read and retrieve contents of multiple files simultaneously with file paths as references. Continues operation even if individual file reads fail. Works only within permitted directories for secure file access.
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/tools/filesystem.ts:75-88 (handler)Core handler function that asynchronously reads multiple files. Validates each path using validatePath, reads file contents with fs.readFile, prefixes output with file path, and handles errors gracefully by returning error messages instead of failing the entire operation.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 for input validation: requires an array of string paths.export const ReadMultipleFilesArgsSchema = z.object({ paths: z.array(z.string()), });
- src/server.ts:133-141 (registration)Tool registration in the listTools response: defines name, description, and converts Zod schema to JSON schema for MCP protocol.{ 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), },
- src/server.ts:273-279 (registration)Dispatch handler in CallToolRequest: parses args with schema, calls the readMultipleFiles function, joins results with separators, and formats MCP 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") }], }; }