webdav_get_file_info
Retrieve detailed metadata about files and directories on WebDAV servers, including file properties, size, modification dates, and directory contents for comprehensive file system management.
Instructions
Get detailed metadata about a file or directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/handlers/tool-handlers.ts:654-692 (handler)Core handler implementation for webdav_get_file_info tool. Registers the tool with schema, executes webdavService.stat(path), formats output using formatSize, and returns structured text response or error.server.tool( "webdav_get_file_info", "Get detailed metadata about a file or directory", { path: z.string().min(1, "Path must not be empty"), }, async ({ path }) => { try { const stats = await webdavService.stat(path); const info = { name: stats.basename, path: stats.filename, type: stats.type, size: stats.size || 0, sizeFormatted: formatSize(stats.size || 0), lastModified: stats.lastmod, mimeType: stats.mime, }; return { content: [{ type: "text", text: Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join("\n"), }], }; } catch (error) { return { content: [{ type: "text", text: `Error getting file info: ${(error as Error).message}`, }], isError: true, }; } }, );
- src/lib.ts:79-79 (registration)Calls setupToolHandlers which registers the webdav_get_file_info tool among others on the MCP server.setupToolHandlers(server, webdavService);
- Helper function to format file sizes in human-readable form, used in the tool's output.// Helper function to format file size function formatSize(bytes: number): string { const units = ["B", "KB", "MB", "GB", "TB"]; if (bytes === 0) return "0 B"; const i = Math.floor(Math.log(bytes) / Math.log(1024)); if (i < 0 || i === 0) return `${bytes} ${units[0]}`; const unitIndex = Math.min(i, units.length - 1); return `${(bytes / Math.pow(1024, unitIndex)).toFixed(2)} ${ units[unitIndex] }`; }
- WebDAVService.stat method called by the tool handler to retrieve file/directory metadata from the WebDAV server.async stat(path: string): Promise<FileStat> { const fullPath = this.getFullPath(path); logger.debug(`Getting stats for: ${fullPath}`); try { const result = await this.client.stat(fullPath); // Convert the result to our FileStat interface const stats = this.convertToFileStat( this.isResponseData(result) ? result.data : result, ); logger.debug(`Got stats for: ${fullPath}`, { type: stats.type }); return stats; } catch (error) { logger.error(`Error getting stats for ${fullPath}:`, error); throw new Error(`Failed to get file stats: ${(error as Error).message}`); } }
- src/services/webdav-service.ts:9-16 (schema)Type definition for FileStat returned by stat method, used to structure the tool's output.export interface FileStat { filename: string; basename: string; lastmod?: string; size?: number; type: "file" | "directory"; mime?: string; [key: string]: any;