webdav_read_multiple_files
Read contents from multiple WebDAV files simultaneously to efficiently access and process multiple documents at once, saving time on individual file operations.
Instructions
Read the contents of multiple files simultaneously
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| paths | Yes | Array of file paths to read |
Implementation Reference
- src/handlers/tool-handlers.ts:614-651 (handler)The primary MCP tool handler implementation for 'webdav_read_multiple_files'. Includes tool registration with server.tool, input schema validation using Zod (paths: array of strings), execution logic that calls the service method, formats results with separators and error handling, and returns structured MCP response.server.tool( "webdav_read_multiple_files", "Read the contents of multiple files simultaneously", { paths: z.array(z.string()).min( 1, "At least one file path must be provided", ).describe("Array of file paths to read"), }, async ({ paths }) => { try { const results = await webdavService.readMultipleFiles(paths); const formattedResults = results.map((result) => { if (result.error) { return `${result.path}: Error - ${result.error}`; } else { return `${result.path}:\n${result.content}\n`; } }); return { content: [{ type: "text", text: formattedResults.join("\n---\n"), }], }; } catch (error) { return { content: [{ type: "text", text: `Error reading multiple files: ${(error as Error).message}`, }], isError: true, }; } }, );
- Supporting utility method in WebDAVService class that implements the core logic for reading multiple files concurrently using Promise.allSettled, individual readFile calls, and returns array of results with path, content or error.async readMultipleFiles( paths: string[], ): Promise<{ path: string; content?: string; error?: string }[]> { logger.debug(`Reading multiple files`, { count: paths.length }); const results = await Promise.allSettled( paths.map(async (path) => { try { const content = await this.readFile(path); return { path, content }; } catch (error) { return { path, error: (error as Error).message, }; } }), ); const formattedResults = results.map((result) => result.status === "fulfilled" ? result.value : { path: "", error: "Unknown error" } ); logger.debug(`Multiple files read completed`, { success: formattedResults.filter((r) => !r.error).length, failed: formattedResults.filter((r) => r.error).length, }); return formattedResults; }