get_file_info
Retrieve metadata for files or directories, including details like size, type, and permissions, to analyze and manage filesystem content.
Instructions
Get detailed file/directory metadata
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file or directory |
Implementation Reference
- src/index.ts:411-426 (handler)Handler for the 'get_file_info' tool. Validates the path, retrieves file stats using fs.stat, formats the information using the formatFileInfo helper, and returns it as JSON-formatted text content.case 'get_file_info': { const { path: filePath } = request.params.arguments as { path: string }; validatePath(filePath); const stats = await fs.stat(filePath); const fileInfo = formatFileInfo(filePath, stats); return { content: [ { type: 'text', text: JSON.stringify(fileInfo, null, 2), }, ], }; }
- src/index.ts:208-221 (registration)Tool registration in the listTools response, including name, description, and input schema definition.{ name: 'get_file_info', description: 'Get detailed file/directory metadata', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file or directory', }, }, required: ['path'], }, },
- src/index.ts:50-64 (helper)Helper function that transforms fs.Stats object into a detailed file information object with path, size, type, timestamps, and permissions.function formatFileInfo(filePath: string, stats: Stats): Record<string, any> { return { path: filePath, size: stats.size, type: stats.isDirectory() ? 'directory' : 'file', created: stats.birthtime.toISOString(), modified: stats.mtime.toISOString(), accessed: stats.atime.toISOString(), permissions: { readable: stats.mode & fs.constants.R_OK ? true : false, writable: stats.mode & fs.constants.W_OK ? true : false, executable: stats.mode & fs.constants.X_OK ? true : false, } }; }