webdav_move_remote_item
Move or rename files or directories on a remote WebDAV server by specifying source and destination paths. Supports optional overwrite functionality.
Instructions
Move or rename a file or directory on a remote WebDAV server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fromPath | Yes | ||
| overwrite | No | ||
| toPath | Yes |
Implementation Reference
- src/handlers/tool-handlers.ts:191-243 (handler)Defines the webdav_move_remote_item tool handler using server.tool(). Includes Zod input schema (fromPath, toPath, overwrite), pre-flight existence checks, overwrite logic, calls webdavService.move(), and returns structured success/error responses.server.tool( 'webdav_move_remote_item', 'Move or rename a file or directory on a remote WebDAV server', { fromPath: z.string().min(1, 'Source path must not be empty'), toPath: z.string().min(1, 'Destination path must not be empty'), overwrite: z.boolean().optional().default(false) }, async ({ fromPath, toPath, overwrite }) => { try { // Check if source exists const sourceExists = await webdavService.exists(fromPath); if (!sourceExists) { return { content: [{ type: 'text', text: `Error: Source path does not exist at ${fromPath}` }], isError: true }; } // Check if destination exists and respect overwrite flag const destExists = await webdavService.exists(toPath); if (destExists && !overwrite) { return { content: [{ type: 'text', text: `Error: Destination already exists at ${toPath}. Use overwrite=true to replace it.` }], isError: true }; } await webdavService.move(fromPath, toPath); return { content: [{ type: 'text', text: `Successfully moved ${fromPath} to ${toPath}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Error moving: ${(error as Error).message}` }], isError: true }; } } );
- src/lib.ts:76-80 (registration)Registers all MCP tools including webdav_move_remote_item by calling setupToolHandlers(server, webdavService). This is the top-level registration during server initialization.setupResourceHandlers(server, webdavService); setupToolHandlers(server, webdavService); setupPromptHandlers(server);
- WebDAVService.move() method implements the core move/rename logic: normalizes paths with getFullPath(), logs item type, calls underlying WebDAV client's moveFile(), validates response status, and propagates errors.async move(fromPath: string, toPath: string): Promise<void> { const fullFromPath = this.getFullPath(fromPath); const fullToPath = this.getFullPath(toPath); logger.debug(`Moving from ${fullFromPath} to ${fullToPath}`); try { // Get type before moving for better logging const stat = await this.stat(fromPath).catch(() => null); const itemType = stat?.type || 'item'; // moveFile in v5.x returns a boolean indicating success const result = await this.client.moveFile(fullFromPath, fullToPath); // Check result based on type if (typeof result === 'boolean' && !result) { throw new Error("Failed to move: server returned failure status"); } else if (this.isResponseData(result) && result.status !== undefined && result.status !== 201 && result.status !== 204) { throw new Error(`Failed to move: server returned status ${result.status}`); } logger.debug(`Successfully moved ${itemType} from ${fullFromPath} to ${fullToPath}`); } catch (error) { logger.error(`Error moving from ${fullFromPath} to ${fullToPath}:`, error); throw new Error(`Failed to move: ${(error as Error).message}`); } }
- Zod input schema for the tool: validates fromPath and toPath as non-empty strings, overwrite as optional boolean defaulting to false.{ fromPath: z.string().min(1, 'Source path must not be empty'), toPath: z.string().min(1, 'Destination path must not be empty'), overwrite: z.boolean().optional().default(false) },