Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathNo/

Implementation Reference

  • 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, }; } }, );
  • 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}`); } }
  • 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.`, }, }, ], }; }, );
  • 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}`, }], }; } }, );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/masx200/mcp-webdav-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server