Skip to main content
Glama

Filesystem MCP Server

Official

read_multiple_files

Read and retrieve contents of multiple files at once for efficient analysis or comparison. Includes file paths for reference, handles individual read failures gracefully, and operates within permitted directories.

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

NameRequiredDescriptionDefault
pathsYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "paths": { "items": { "type": "string" }, "type": "array" } }, "required": [ "paths" ], "type": "object" }

Implementation Reference

  • The main handler function that implements the logic for the 'read_multiple_files' tool. It processes multiple file paths in parallel, validates each path, reads the content (handling individual errors gracefully), formats the output with file paths 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 } }; }
  • Zod schema defining the input parameters for the 'read_multiple_files' tool: an array of at least one string file path.
    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."), });
  • Registration of the 'read_multiple_files' tool with the MCP server, specifying title, description, input schema (referencing the args schema structure), output schema, and annotations.
    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 } },

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

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