Skip to main content
Glama
LaubPlusCo

WebDAV MCP Server

by LaubPlusCo

webdav_delete_remote_item

Delete files or directories from a remote WebDAV server by specifying their path to manage storage and organize content.

Instructions

Delete a file or directory from a remote WebDAV server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • MCP tool handler function that checks if the path exists, deletes the item using WebDAVService, and returns success or error messages.
    async ({ path }) => {
      try {
        // Check if path exists
        const exists = await webdavService.exists(path);
        if (!exists) {
          return {
            content: [{
              type: 'text',
              text: `Error: Path does not exist at ${path}`
            }],
            isError: true
          };
        }
    
        await webdavService.delete(path);
        
        return {
          content: [{
            type: 'text',
            text: `Successfully deleted ${path}`
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `Error deleting: ${(error as Error).message}`
          }],
          isError: true
        };
      }
  • Zod input schema defining the 'path' parameter for the tool.
    {
      path: z.string().min(1, 'Path must not be empty')
    },
  • Registration of the 'webdav_delete_remote_item' tool with the MCP server, including name, description, schema, and handler.
      'webdav_delete_remote_item',
      'Delete a file or directory from a remote WebDAV server',
      {
        path: z.string().min(1, 'Path must not be empty')
      },
      async ({ path }) => {
        try {
          // Check if path exists
          const exists = await webdavService.exists(path);
          if (!exists) {
            return {
              content: [{
                type: 'text',
                text: `Error: Path does not exist at ${path}`
              }],
              isError: true
            };
          }
    
          await webdavService.delete(path);
          
          return {
            content: [{
              type: 'text',
              text: `Successfully deleted ${path}`
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `Error deleting: ${(error as Error).message}`
            }],
            isError: true
          };
        }
      }
    );
  • Supporting WebDAVService.delete method called by the tool handler to perform the actual deletion via WebDAV client.
    async delete(path: string): Promise<void> {
      const fullPath = this.getFullPath(path);
      logger.debug(`Deleting: ${fullPath}`);
      
      try {
        // Get type before deleting for better logging
        const stat = await this.stat(fullPath).catch(() => null);
        const itemType = stat?.type || 'item';
        
        // deleteFile in v5.x returns a boolean indicating success
        const result = await this.client.deleteFile(fullPath);
        
        // Check result based on type
        if (typeof result === 'boolean' && !result) {
          throw new Error("Failed to delete: server returned failure status");
        } else if (this.isResponseData(result) && 
                   result.status !== undefined && 
                   result.status !== 204) {
          throw new Error(`Failed to delete: server returned status ${result.status}`);
        }
        
        logger.debug(`Successfully deleted ${itemType}: ${fullPath}`);
      } catch (error) {
        logger.error(`Error deleting ${fullPath}:`, error);
        throw new Error(`Failed to delete: ${(error as Error).message}`);
      }
    }
  • Registration of prompt handler for 'webdav_delete_remote_item' with MCP server.
        'webdav_delete_remote_item',
        // The issue is with boolean not being compatible with the prompt schema
        // Using string as a workaround
        {
          path: z.string().min(1, 'Path must not be empty'),
          confirm: z.string().optional()
        },
        (args) => {
          const confirmationEnabled = args.confirm !== 'false';
          const pathValue = args.path;
          const isDirectory = pathValue.endsWith('/');
          
          return {
            messages: [
              {
                role: 'user',
                content: {
                  type: 'text',
                  text: `Delete the ${isDirectory ? 'directory' : 'file'} at "${pathValue}" from the remote WebDAV server.
    ${confirmationEnabled ? 'Please confirm this action to proceed with deletion.' : 'Execute this remote deletion operation.'}
    
    Please confirm when the remote WebDAV deletion is complete.`
                }
              }
            ]
          };
        }
      );

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/LaubPlusCo/mcp-webdav-server'

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