Skip to main content
Glama
LaubPlusCo

WebDAV MCP Server

by LaubPlusCo

webdav_update_remote_file

Modify existing files on a remote WebDAV server by replacing their content with new data. Specify the file path and updated content to apply changes.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
contentYes

Implementation Reference

  • Main tool handler function: checks if the remote file exists, then writes new content using WebDAVService
    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 validation using Zod for path and content parameters
    path: z.string().min(1, 'Path must not be empty'), content: z.string() },
  • Registers the webdav_update_remote_file tool with the MCP server
    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 }; } } );
  • Core helper method implementing WebDAV file update via putFileContents
    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 to check if the remote path exists before attempting update
    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