webdav_list_remote_directory
List files and directories from a remote WebDAV server path to view available content and navigate the 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:301-336 (handler)MCP tool handler implementation for 'webdav_list_remote_directory'. Registers the tool with Zod input schema (path optional, defaults to '/'), executes webdavService.list(path), formats results as JSON, and returns as text content or error.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)Core helper method implementing directory listing using WebDAVClient.getDirectoryContents, handling response formats, converting to FileStat[], with full path resolution and logging.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)Top-level server initialization calls setupToolHandlers(server, webdavService), which registers the 'webdav_list_remote_directory' tool among others.setupResourceHandlers(server, webdavService); setupToolHandlers(server, webdavService); setupPromptHandlers(server);
- Zod input schema for the tool: path as optional string defaulting to '/'.{ path: z.string().optional().default('/') },
- Supporting utility for basename extraction used in FileStat conversion.private getBasenameFromPath(path: string): string {