webdav_list_remote_directory
Retrieve and list files and directories from a specified path on a remote WebDAV server to manage and organize your remote file system.
Instructions
List files and directories at the specified path on a remote WebDAV server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | / |
Implementation Reference
- src/handlers/tool-handlers.ts:307-335 (handler)The core handler function that executes the tool: fetches directory listing from WebDAV service, formats files with name/path/type/size/lastmod, returns JSON text or error.async ({ path }) => { try { const files = await webdavService.list(path); // Format response const formattedFiles = files.map(file => ({ name: file.basename, path: file.filename, type: file.type, size: file.size, lastModified: file.lastmod })); return { content: [{ type: 'text', text: JSON.stringify(formattedFiles, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error listing directory: ${(error as Error).message}` }], isError: true }; } }
- Input validation schema using Zod: path as optional string defaulting to root directory '/'.{ path: z.string().optional().default('/') },
- src/handlers/tool-handlers.ts:301-336 (registration)MCP server.tool registration of the webdav_list_remote_directory tool with description, schema, and handler function.server.tool( 'webdav_list_remote_directory', 'List files and directories at the specified path on a remote WebDAV server', { path: z.string().optional().default('/') }, async ({ path }) => { try { const files = await webdavService.list(path); // Format response const formattedFiles = files.map(file => ({ name: file.basename, path: file.filename, type: file.type, size: file.size, lastModified: file.lastmod })); return { content: [{ type: 'text', text: JSON.stringify(formattedFiles, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Error listing directory: ${(error as Error).message}` }], isError: true }; } } );
- src/services/webdav-service.ts:65-86 (helper)WebDAVService.list method: core implementation using WebDAVClient.getDirectoryContents, path normalization, response conversion to FileStat array, error handling.async list(path: string = '/'): Promise<FileStat[]> { const fullPath = this.getFullPath(path); logger.debug(`Listing directory: ${fullPath}`); try { // In v5.x we need to handle the response differently const result = await this.client.getDirectoryContents(fullPath); // Convert the result to our FileStat interface const fileStats = Array.isArray(result) ? result.map(item => this.convertToFileStat(item)) : this.isResponseData(result) && Array.isArray(result.data) ? result.data.map(item => this.convertToFileStat(item)) : []; logger.debug(`Listed ${fileStats.length} items in directory: ${fullPath}`); return fileStats; } catch (error) { logger.error(`Error listing directory ${fullPath}:`, error); throw new Error(`Failed to list directory: ${(error as Error).message}`); } }
- src/lib.ts:77-79 (registration)Calls to setup functions in lib.ts startWebDAVServer that invoke the handler setups including tool registration for webdav_list_remote_directory.setupResourceHandlers(server, webdavService); setupToolHandlers(server, webdavService); setupPromptHandlers(server);