Skip to main content
Glama
modelcontextprotocol

Filesystem MCP Server

Official

Read Multiple Files

read_multiple_files
Read-only

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.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes

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."),
    });
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds valuable behavioral context beyond the readOnlyHint annotation: it explains that failed reads for individual files won't stop the entire operation, and that it only works within allowed directories. This provides important operational details about partial failures and access constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly front-loaded with the core purpose, followed by efficiency rationale, output format, error behavior, and access constraints in just four concise sentences. Every sentence adds distinct value with zero redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity, the presence of readOnlyHint annotation, 100% schema coverage, and an output schema, the description provides complete contextual information. It covers purpose, efficiency rationale, output format, error handling, and access constraints without needing to explain return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already fully documents the single 'paths' parameter. The description doesn't add any parameter-specific details beyond what's in the schema, maintaining the baseline score for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Read the contents of multiple files simultaneously') and resource ('files'), distinguishing it from sibling tools like read_file, read_text_file, and read_media_file by emphasizing batch processing efficiency.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('more efficient than reading files one by one when you need to analyze or compare multiple files'), but doesn't explicitly state when NOT to use it or name specific alternatives among siblings like read_file for single-file operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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