webdav_get_remote_file
Retrieve content from files stored on remote WebDAV servers by specifying the file path to access and download data.
Instructions
Retrieve content from a file stored on a remote WebDAV server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/handlers/tool-handlers.ts:56-75 (handler)The MCP tool handler function that executes the webdav_get_remote_file logic by calling WebDAVService.readFile(path) and returning the content or error.async ({ path }) => { try { const content = await webdavService.readFile(path); return { content: [{ type: 'text', text: content }] }; } catch (error) { return { content: [{ type: 'text', text: `Error reading file: ${(error as Error).message}` }], isError: true }; } }
- src/handlers/tool-handlers.ts:53-55 (schema)Zod input schema validation for the tool parameters.{ path: z.string().min(1, 'Path must not be empty') },
- src/handlers/tool-handlers.ts:50-76 (registration)Registration of the webdav_get_remote_file tool with MCP server.tool, including name, description, schema, and handler reference.server.tool( 'webdav_get_remote_file', 'Retrieve content from a file stored on a remote WebDAV server', { path: z.string().min(1, 'Path must not be empty') }, async ({ path }) => { try { const content = await webdavService.readFile(path); return { content: [{ type: 'text', text: content }] }; } catch (error) { return { content: [{ type: 'text', text: `Error reading file: ${(error as Error).message}` }], isError: true }; } } );
- Core implementation of file reading in WebDAVService using WebDAVClient.getFileContents with text format, handling various response types.async readFile(path: string): Promise<string> { const fullPath = this.getFullPath(path); logger.debug(`Reading file: ${fullPath}`); try { // v5.x returns buffer by default, need to use format: 'text' const content = await this.client.getFileContents(fullPath, { format: 'text' }); // Handle both direct string response and detailed response let result: string; if (typeof content === 'string') { result = content; } else if (this.isResponseData(content)) { result = String(content.data); } else { throw new Error("Unexpected response format from server"); } const contentLength = result.length; logger.debug(`Read file: ${fullPath}`, { contentLength }); return result; } catch (error) { logger.error(`Error reading file ${fullPath}:`, error); throw new Error(`Failed to read file: ${(error as Error).message}`); } }