Skip to main content
Glama
wonderwhy-er

Claude Desktop Commander MCP

read_multiple_files

Read and retrieve contents from multiple files in one operation, including text files and images (PNG, JPEG, GIF, WebP). Uses absolute paths for reliability and continues execution even if individual file reads fail.

Instructions

                    Read the contents of multiple files simultaneously.
                    
                    Each file's content is returned with its path as a reference.
                    Handles text files normally and renders images as viewable content.
                    Recognized image types: PNG, JPEG, GIF, WebP.
                    
                    Failed reads for individual files won't stop the entire operation.
                    Only works within allowed directories.
                    
                    IMPORTANT: Always use absolute paths for reliability. Paths are automatically normalized regardless of slash direction. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.
                    This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathsYes

Implementation Reference

  • Main handler function that executes the read_multiple_files tool. Parses args with schema, calls readMultipleFiles helper, handles PDF/image/text responses, builds summary and content array.
    /**
     * Handle read_multiple_files command
     */
    export async function handleReadMultipleFiles(args: unknown): Promise<ServerResult> {
        const parsed = ReadMultipleFilesArgsSchema.parse(args);
        const fileResults = await readMultipleFiles(parsed.paths);
    
        // Create a text summary of all files
        const textSummary = fileResults.map(result => {
            if (result.error) {
                return `${result.path}: Error - ${result.error}`;
            } else if (result.isPdf) {
                return `${result.path}: PDF file with ${result.payload?.pages?.length} pages`;
            } else if (result.mimeType) {
                return `${result.path}: ${result.mimeType} ${result.isImage ? '(image)' : '(text)'}`;
            } else {
                return `${result.path}: Unknown type`;
            }
        }).join("\n");
    
        // Create content items for each file
        const contentItems: Array<{ type: string, text?: string, data?: string, mimeType?: string }> = [];
    
        // Add the text summary
        contentItems.push({ type: "text", text: textSummary });
    
        // Add each file content
        for (const result of fileResults) {
            if (!result.error && result.content !== undefined) {
                if (result.isPdf) {
                    result.payload?.pages.forEach((page, i) => {
                        page.images.forEach((image, i) => {
                            contentItems.push({
                                type: "image",
                                data: image.data,
                                mimeType: image.mimeType
                            });
                        });
                        contentItems.push({
                            type: "text",
                            text: page.text,
                        });
                    });
                } else if (result.isImage && result.mimeType) {
                    // For image files, add an image content item
                    contentItems.push({
                        type: "image",
                        data: result.content,
                        mimeType: result.mimeType
                    });
                } else {
                    // For text files, add a text summary
                    contentItems.push({
                        type: "text",
                        text: `\n--- ${result.path} contents: ---\n${result.content}`
                    });
                }
            }
        }
    
        return { content: contentItems };
    }
  • Registration/dispatch in the main CallToolRequestHandler switch statement, mapping tool name 'read_multiple_files' to the handleReadMultipleFiles handler.
    case "read_multiple_files":
        result = await handlers.handleReadMultipleFiles(args);
        break;
  • Zod schema defining input arguments for read_multiple_files tool: array of file paths.
    export const ReadMultipleFilesArgsSchema = z.object({
      paths: z.array(z.string()),
    });
  • src/server.ts:287-305 (registration)
    Tool definition in ListToolsRequestHandler, including name, description, inputSchema from ReadMultipleFilesArgsSchema, and annotations.
        name: "read_multiple_files",
        description: `
                Read the contents of multiple files simultaneously.
                
                Each file's content is returned with its path as a reference.
                Handles text files normally and renders images as viewable content.
                Recognized image types: PNG, JPEG, GIF, WebP.
                
                Failed reads for individual files won't stop the entire operation.
                Only works within allowed directories.
                
                ${PATH_GUIDANCE}
                ${CMD_PREFIX_DESCRIPTION}`,
        inputSchema: zodToJsonSchema(ReadMultipleFilesArgsSchema),
        annotations: {
            title: "Read Multiple Files",
            readOnlyHint: true,
        },
    },
  • Core helper function that reads multiple files in parallel using Promise.all, validates paths, calls readFile for each, handles errors per file, returns array of results with metadata.
    export async function readMultipleFiles(paths: string[]): Promise<MultiFileResult[]> {
        return Promise.all(
            paths.map(async (filePath: string) => {
                try {
                    const validPath = await validatePath(filePath);
                    const fileResult = await readFile(validPath);
                    const isPdf = isPdfFile(fileResult.mimeType);
                    return {
                        path: filePath,
                        content: typeof fileResult === 'string' ? fileResult : fileResult.content,
                        mimeType: typeof fileResult === 'string' ? "text/plain" : fileResult.mimeType,
                        isImage: typeof fileResult === 'string' ? false : fileResult.isImage,
                        isPdf: typeof fileResult === 'string' ? false : fileResult.isPdf,
                        payload: typeof fileResult === 'string' ? undefined : fileResult.payload
                    };
                } catch (error) {
                    const errorMessage = error instanceof Error ? error.message : String(error);
                    return {
                        path: filePath,
                        error: errorMessage
                    };
                }
            }),
        );
    }
Behavior4/5

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

With no annotations provided, the description carries full burden and discloses key behaviors: handles text and image files (PNG, JPEG, GIF, WebP), continues on individual file failures, works within allowed directories, and requires absolute paths for reliability. It doesn't cover rate limits or auth needs but provides substantial operational context.

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

Conciseness4/5

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

Well-structured with clear sections: purpose, return format, file handling, error behavior, directory constraints, and path instructions. Some redundancy in path advice slightly reduces efficiency, but overall front-loaded and informative.

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 provides good coverage: explains what the tool does, how to use it, behavioral traits, and parameter semantics. It could detail output format more explicitly but is largely complete for a read operation tool.

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?

Schema description coverage is 0% with 1 parameter ('paths'), and the description compensates by explaining that 'paths' should be absolute for reliability, automatically normalized, and that relative/tilde paths may fail. It adds meaning beyond the bare schema type definition.

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 verb ('read') and resource ('multiple files simultaneously'), distinguishing it from sibling 'read_file' which handles single files. It specifies the scope of reading multiple files at once with content returned by path.

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

Usage Guidelines5/5

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

Explicitly states when to use this tool ('read multiple files simultaneously') and provides alternatives: it distinguishes from 'read_file' for single files, mentions 'only works within allowed directories' as a constraint, and references 'Desktop Commander' context for usage.

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/wonderwhy-er/DesktopCommanderMCP'

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