get_file_info
Retrieve detailed metadata about files or directories including size, type, permissions, and modification dates to analyze file system contents.
Instructions
Get detailed information about a file or directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The file or directory path to get info about |
Implementation Reference
- src/index.ts:297-328 (handler)The handler for the 'get_file_info' tool. It validates the input path, resolves it safely, fetches file stats, checks if it's a directory and counts contents if so, then returns formatted file information including path, type, size, timestamps, and permissions.case "get_file_info": { const { path: targetPath } = FileInfoArgsSchema.parse(args); const safePath = validatePath(targetPath); const stats = await fs.stat(safePath); const isDirectory = stats.isDirectory(); let additionalInfo = ""; if (isDirectory) { try { const entries = await fs.readdir(safePath); additionalInfo = `\nContains: ${entries.length} items`; } catch (error) { additionalInfo = "\nUnable to read directory contents"; } } return { content: [ { type: "text", text: `Path: ${safePath}\n` + `Type: ${isDirectory ? 'Directory' : 'File'}\n` + `Size: ${formatFileSize(stats.size)}\n` + `Created: ${stats.birthtime.toLocaleString()}\n` + `Modified: ${stats.mtime.toLocaleString()}\n` + `Accessed: ${stats.atime.toLocaleString()}\n` + `Permissions: ${stats.mode.toString(8)}${additionalInfo}` } ] }; }
- src/index.ts:40-42 (schema)Zod input validation schema for the 'get_file_info' tool, defining the required 'path' parameter.const FileInfoArgsSchema = z.object({ path: z.string().describe("The file or directory path to get info about") });
- src/index.ts:172-185 (registration)Tool registration in the ListTools handler, providing name, description, and input schema for 'get_file_info'.{ name: "get_file_info", description: "Get detailed information about a file or directory", inputSchema: { type: "object", properties: { path: { type: "string", description: "The file or directory path to get info about" } }, required: ["path"] } },