Skip to main content
Glama
LaubPlusCo

WebDAV MCP Server

by LaubPlusCo

webdav_update_remote_file

Update content of an existing file on a remote WebDAV server by specifying the file path and new content using this tool for streamlined file management.

Instructions

Update an existing file on a remote WebDAV server with new content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
pathYes

Implementation Reference

  • Full tool handler implementation for 'webdav_update_remote_file', including inline schema validation, existence check before update, error handling, and call to WebDAVService.writeFile.
    server.tool( 'webdav_update_remote_file', 'Update an existing file on a remote WebDAV server with new content', { path: z.string().min(1, 'Path must not be empty'), content: z.string() }, async ({ path, content }) => { try { // Check if file exists const exists = await webdavService.exists(path); if (!exists) { return { content: [{ type: 'text', text: `Error: File does not exist at ${path}` }], isError: true }; } await webdavService.writeFile(path, content); return { content: [{ type: 'text', text: `File updated successfully at ${path}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Error updating file: ${(error as Error).message}` }], isError: true }; } }
  • Input schema for the tool using Zod: path (string, required) and content (string, required).
    { path: z.string().min(1, 'Path must not be empty'), content: z.string() },
  • Core helper method writeFile in WebDAVService that performs the actual file update using WebDAVClient.putFileContents, with path normalization, logging, and error handling.
    async writeFile(path: string, content: string | Buffer): Promise<void> { const fullPath = this.getFullPath(path); const contentLength = typeof content === 'string' ? content.length : content.length; logger.debug(`Writing file: ${fullPath}`, { contentLength }); try { // putFileContents in v5.x returns a boolean indicating success const result = await this.client.putFileContents(fullPath, content); // Check result based on type if (typeof result === 'boolean' && !result) { throw new Error("Failed to write file: server returned failure status"); } else if (this.isResponseData(result) && result.status !== undefined && result.status !== 201 && result.status !== 204) { throw new Error(`Failed to write file: server returned status ${result.status}`); } logger.debug(`Successfully wrote file: ${fullPath}`); } catch (error) { logger.error(`Error writing to file ${fullPath}:`, error); throw new Error(`Failed to write file: ${(error as Error).message}`); } }
  • Helper method exists used by the tool handler to verify the file exists before updating.
    async exists(path: string): Promise<boolean> { const fullPath = this.getFullPath(path); logger.debug(`Checking if exists: ${fullPath}`); try { const result = await this.client.exists(fullPath); // Handle both boolean and object responses let exists = false; if (typeof result === 'boolean') { exists = result; } else if (result && typeof result === 'object') { // Use type guard for better type safety const responseData = result as ResponseData; if (responseData.status !== undefined) { exists = responseData.status < 400; // If status is less than 400, the resource exists } } logger.debug(`Exists check for ${fullPath}: ${exists}`); return exists; } catch (error) { logger.error(`Error checking existence of ${fullPath}:`, error); return false; }

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