Skip to main content
Glama
safurrier

MCP Filesystem Server

read_multiple_files

Read multiple files simultaneously to retrieve their contents efficiently. Specify file paths and optional encoding to get a dictionary mapping each path to its content or error message.

Instructions

Read multiple files at once.

Args:
    paths: List of file paths to read
    encoding: File encoding (default: utf-8)
    ctx: MCP context

Returns:
    Dictionary mapping file paths to contents or error messages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathsYes
encodingNoutf-8

Implementation Reference

  • MCP tool registration and handler for 'read_multiple_files'. This is the entry point decorated with @mcp.tool(), which receives parameters, calls the core operations method, formats exceptions for JSON compatibility, and returns the results.
    @mcp.tool()
    async def read_multiple_files(
        paths: List[str], ctx: Context, encoding: str = "utf-8"
    ) -> Dict[str, str]:
        """Read multiple files at once.
    
        Args:
            paths: List of file paths to read
            encoding: File encoding (default: utf-8)
            ctx: MCP context
    
        Returns:
            Dictionary mapping file paths to contents or error messages
        """
        try:
            components = get_components()
            results = await components["operations"].read_multiple_files(paths, encoding)
    
            # Convert exceptions to strings for JSON serialization
            formatted_results = {}
            for path, result in results.items():
                if isinstance(result, Exception):
                    formatted_results[path] = f"Error: {str(result)}"
                else:
                    formatted_results[path] = result
    
            return formatted_results
        except Exception as e:
            return {"error": str(e)}
  • Core implementation of read_multiple_files in FileOperations class. Validates paths, reads file contents asynchronously, catches exceptions per file, and returns a dictionary of path to content or exception.
    async def read_multiple_files(
        self, paths: List[Union[str, Path]], encoding: str = "utf-8"
    ) -> Dict[str, Union[str, Exception]]:
        """Read multiple files at once.
    
        Args:
            paths: List of file paths
            encoding: Text encoding (default: utf-8)
    
        Returns:
            Dictionary mapping file paths to contents or exceptions
        """
        # Explicitly type-annotate the results to help mypy
        results: Dict[str, Union[str, Exception]] = {}
    
        for path in paths:
            try:
                abs_path, allowed = await self.validator.validate_path(path)
                if not allowed:
                    # Create an error and store it
                    error_msg = f"Path outside allowed directories: {path}"
                    results[str(path)] = ValueError(error_msg)
                    continue
    
                content = await anyio.to_thread.run_sync(
                    partial(abs_path.read_text, encoding=encoding)
                )
                results[str(path)] = content
            except Exception as e:
                results[str(path)] = e
    
        return results
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the return format (dictionary mapping paths to contents/errors) which is helpful, but doesn't address important behavioral aspects like error handling strategy (does it fail fast or continue?), performance implications of reading many files, memory considerations, or whether it respects file permissions. The description provides basic output information but lacks comprehensive behavioral context.

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 efficiently structured with a clear purpose statement followed by organized sections for Args and Returns. Each sentence earns its place by providing essential information without redundancy. The formatting with clear section headers makes it easy to parse while maintaining brevity.

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

Completeness3/5

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

Given 2 parameters with 0% schema coverage and no output schema, the description does an adequate job explaining parameters and return format. However, for a file reading tool with many sibling alternatives and no annotations, it should ideally address more behavioral aspects like error handling strategy, performance considerations, and clearer differentiation from similar tools. The description meets minimum viability but has clear gaps.

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

Parameters4/5

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

The description adds significant value beyond the input schema, which has 0% description coverage. It explains that 'paths' is a 'List of file paths to read' and 'encoding' is 'File encoding (default: utf-8)', providing clear semantic meaning. For the 'ctx' parameter, it simply states 'MCP context' without elaboration, but this is likely a standard parameter. The description compensates well for the schema's lack of documentation.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Read multiple files at once.' This specifies the verb ('read') and resource ('multiple files'), distinguishing it from the sibling 'read_file' which handles single files. However, it doesn't explicitly differentiate from other reading-related siblings like 'read_file_lines' or 'head_file/tail_file'.

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

Usage Guidelines3/5

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

The description implies usage context through its name and purpose statement - it's for reading multiple files simultaneously rather than one at a time. However, it doesn't provide explicit guidance on when to use this versus alternatives like 'read_file' for single files or 'grep_files' for searching content. No exclusions or prerequisites are mentioned.

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

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