read_multiple_files
Read multiple files at once to analyze or compare their contents efficiently. Each file's content is returned with its path, and individual read failures don't stop the entire operation.
Instructions
Read the contents of multiple files simultaneously. This is more efficient than reading files one by one when you need to analyze or compare multiple files. 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 | Array of file paths to read. Each path must be a string pointing to a valid file within allowed directories. |
Implementation Reference
- src/filesystem/index.ts:299-317 (handler)The asynchronous handler function for the 'read_multiple_files' tool. It processes multiple file paths in parallel, reads each file's content (handling errors individually), formats the results with path prefixes and separators, and returns structured text content.async (args: z.infer<typeof ReadMultipleFilesArgsSchema>) => { const results = await Promise.all( args.paths.map(async (filePath: string) => { try { const validPath = await validatePath(filePath); const content = await readFileContent(validPath); return `${filePath}:\n${content}\n`; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return `${filePath}: Error - ${errorMessage}`; } }), ); const text = results.join("\n---\n"); return { content: [{ type: "text" as const, text }], structuredContent: { content: text } }; }
- src/filesystem/index.ts:281-298 (registration)The server.registerTool call that registers the 'read_multiple_files' tool, providing its metadata (title, description, input/output schemas, annotations) and references the inline handler function.server.registerTool( "read_multiple_files", { title: "Read Multiple Files", description: "Read the contents of multiple files simultaneously. This is more " + "efficient than reading files one by one when you need to analyze " + "or compare multiple files. 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: { paths: z.array(z.string()) .min(1) .describe("Array of file paths to read. Each path must be a string pointing to a valid file within allowed directories.") }, outputSchema: { content: z.string() }, annotations: { readOnlyHint: true } },
- src/filesystem/index.ts:87-92 (schema)Zod schema definition for the input arguments of the 'read_multiple_files' tool, used for type inference in the handler function.const ReadMultipleFilesArgsSchema = z.object({ paths: z .array(z.string()) .min(1, "At least one file path must be provided") .describe("Array of file paths to read. Each path must be a string pointing to a valid file within allowed directories."), });