Skip to main content
Glama
gabrielmaialva33

MCP Filesystem Server

read_multiple_files

Enables simultaneous reading of multiple files in allowed directories, returning content with file paths. Ideal for efficient analysis or comparison. Handles failed reads without interrupting 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
encodingNoFile encodingutf-8
pathsYesList of file paths to read

Implementation Reference

  • Core handler function that implements the read_multiple_files tool logic: validates paths and sizes for each file, reads contents concurrently using Promise.all, handles individual errors without failing the entire operation, returns a record mapping paths to content or Error.
    export async function readMultipleFiles(
      args: z.infer<typeof ReadMultipleFilesArgsSchema>,
      config: Config
    ): Promise<Record<string, string | Error>> {
      const endMetric = metrics.startOperation('read_multiple_files')
      const results: Record<string, string | Error> = {}
    
      await Promise.all(
        args.paths.map(async (filePath: string) => {
          try {
            const validPath = await validatePath(filePath, config)
    
            // Validate file size
            if (config.security.maxFileSize > 0) {
              await validateFileSize(validPath, config.security.maxFileSize)
            }
    
            const content = await fs.readFile(validPath, args.encoding)
            results[filePath] = content
          } catch (error) {
            if (error instanceof Error) {
              results[filePath] = error
            } else {
              results[filePath] = new Error(String(error))
            }
          }
        })
      )
    
      endMetric()
      return results
    }
  • Zod schema defining input arguments for the read_multiple_files tool: array of paths and optional encoding.
    /**
     * Schema for read_multiple_files arguments
     */
    export const ReadMultipleFilesArgsSchema = z.object({
      paths: z.array(z.string()).describe('List of file paths to read'),
      encoding: z
        .enum(['utf-8', 'utf8', 'base64'])
        .optional()
        .default('utf-8')
        .describe('File encoding'),
    })
  • src/index.ts:244-253 (registration)
    Tool registration in the ListTools response: defines the tool name, description, and converts the Zod schema to JSON schema for MCP protocol.
    {
      name: '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: zodToJsonSchema(ReadMultipleFilesArgsSchema) as ToolInput,
    },
  • MCP server dispatcher case for read_multiple_files: parses input arguments using the schema, calls the core handler, formats results (including errors per file), and returns MCP-formatted response.
    case 'read_multiple_files': {
      const parsed = ReadMultipleFilesArgsSchema.safeParse(a)
      if (!parsed.success) {
        throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, {
          errors: parsed.error.format(),
        })
      }
    
      const results = await readMultipleFiles(parsed.data, config)
      const formattedResults = Object.entries(results)
        .map(([filePath, content]) => {
          if (content instanceof Error) {
            return `${filePath}: Error - ${content.message}`
          }
          return `${filePath}:\n${content}\n`
        })
        .join('\n---\n')
    
      endMetric()
      return {
        content: [{ type: 'text', text: formattedResults }],
      }
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: partial failure tolerance ('Failed reads for individual files won't stop the entire operation'), directory restrictions ('Only works within allowed directories'), and output structure ('Each file's content is returned with its path as a reference'). It lacks details on error handling or performance characteristics, but covers essential operational behavior.

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 front-loaded with the core purpose, followed by efficiency rationale, output format, failure behavior, and constraints—all in four concise sentences. Each sentence adds distinct value without redundancy, making it highly efficient and well-structured.

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

Completeness4/5

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

Given no annotations and no output schema, the description does a good job covering purpose, usage, behavior, and constraints. It could be more complete by detailing error responses or performance limits, but it provides sufficient context for a read operation with partial failures and directory restrictions.

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?

Schema description coverage is 100%, so the schema fully documents both parameters. The description does not add any parameter-specific semantics beyond what the schema provides (e.g., it doesn't explain path formatting or encoding implications). This meets the baseline for high schema coverage without extra value.

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'), identifies the resource ('files'), and distinguishes it from the sibling tool 'read_file' by emphasizing batch efficiency and partial failure tolerance. It explicitly contrasts with reading files one by one, making the purpose distinct and well-defined.

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 on when to use this tool ('when you need to analyze or compare multiple files') and mentions efficiency benefits over the sibling 'read_file'. However, it does not explicitly state when not to use it or name specific alternatives beyond the implied contrast, leaving some guidance gaps.

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

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/gabrielmaialva33/mcp-filesystem'

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