get_file_info
Retrieve detailed metadata for files or directories by specifying their paths. Provides essential information for filesystem operations within allowed paths.
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, formats the information using 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)Registration of the 'get_file_info' tool in the listTools handler, including name, description, and input schema.{ 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 used by get_file_info to format fs.Stats into a readable 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, } }; }