webdav_list_remote_directory
Browse and view files and directories stored on a remote WebDAV server to manage your cloud storage content and navigate folder structures.
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:402-437 (handler)MCP tool handler implementation for 'webdav_list_remote_directory'. Defines the tool schema, description, and execution logic which lists directory contents using WebDAVService.list() and returns formatted JSON.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:70-93 (helper)WebDAVService.list() method, the core helper function called by the tool handler to retrieve directory contents from the remote WebDAV server using the webdav library's getDirectoryContents.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/handlers/prompt-handlers.ts:123-152 (registration)MCP prompt registration for 'webdav_list_remote_directory', providing a user prompt template for listing directories.server.prompt( "webdav_list_remote_directory", { path: z.string().optional(), }, (args) => { const pathToUse = args.path || "/"; return { messages: [ { role: "user", content: { type: "text", text: `List all files and directories in the remote WebDAV directory "${pathToUse}". Please provide a well-formatted list showing: - File/directory names - Types (file or directory) - Sizes (for files) - Last modified dates (if available) This is for a remote WebDAV server, not a local filesystem.`, }, }, ], }; }, );
- src/handlers/resource-handlers.ts:12-63 (registration)MCP resource registration for 'webdav_list_remote_directory', providing a resource template for directory listing via URI.server.resource( "webdav_list_remote_directory", new ResourceTemplate("webdav://{path}/list", { // The list property expects a proper response format list: async () => { return { resources: [ { uri: "webdav://", name: "WebDAV Root", description: "Access to WebDAV resources", }, ], }; }, }), async (uri, { path }) => { try { const normalizedPath = path ? String(path) : "/"; const files = await webdavService.list(normalizedPath); // Format the file listing for display const content = files.map((file) => { const type = file.type === "directory" ? "Directory" : "File"; const size = file.type === "file" ? `Size: ${formatSize(file.size)}` : ""; const lastMod = file.lastmod ? `Last Modified: ${file.lastmod}` : ""; return `${type}: ${file.basename} ${size} ${lastMod} Path: ${file.filename} ${"-".repeat(40)}`; }).join("\n"); return { contents: [{ uri: uri.href, text: content ? content : "Empty directory", }], }; } catch (error) { return { contents: [{ uri: uri.href, text: `Error listing directory: ${(error as Error).message}`, }], }; } }, );