read_multiple_files
Read and retrieve contents of multiple UTF-8 text files simultaneously, mapping paths to their contents. Ensures all files are within allowed directories and returns an error if any file fails.
Instructions
Read multiple UTF-8 text files at once and return a mapping of paths to contents.
Args: paths (List[str]): List of file paths to read (absolute or relative to allowed directories)
Returns: Dict[str, str] | str: Dictionary mapping absolute file paths to their contents, or error message if any file fails
Note: - All paths must be within allowed directory roots - All files must be UTF-8 text files - If any file fails to read, entire operation returns error string - Returns dictionary for successful reads, string for errors
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes |
Implementation Reference
- main.py:433-459 (handler)Handler function for the 'read_multiple_files' MCP tool. Decorated with @mcp.tool, it reads contents from multiple specified text files within allowed directories, returning a dictionary of absolute paths to contents or an error string if any issue occurs.@mcp.tool def read_multiple_files(paths: List[str]) -> Dict[str, str] | str: """Read multiple UTF-8 text files at once and return a mapping of paths to contents. Args: paths (List[str]): List of file paths to read (absolute or relative to allowed directories) Returns: Dict[str, str] | str: Dictionary mapping absolute file paths to their contents, or error message if any file fails Note: - All paths must be within allowed directory roots - All files must be UTF-8 text files - If any file fails to read, entire operation returns error string - Returns dictionary for successful reads, string for errors """ result: Dict[str, str] = {} try: for p in paths: rp = _resolve(p) if not _is_text(rp): return f"Error reading multiple files: '{rp}' is not a UTF-8 text file or is binary" result[str(rp)] = rp.read_text(encoding="utf-8") return result except Exception as e: return _human_error(e, "reading multiple files")