Skip to main content
Glama
modelcontextprotocol

Filesystem MCP Server

Official

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
NameRequiredDescriptionDefault
pathsYesArray of file paths to read. Each path must be a string pointing to a valid file within allowed directories.

Implementation Reference

  • 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 } }; }
  • 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 } },
  • 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."), });

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/modelcontextprotocol/filesystem'

If you have feedback or need assistance with the MCP directory API, please join our Discord server