get_file_info
Retrieve detailed file or directory metadata, including size, permissions, creation time, and type, without accessing file content. Operates within predefined directories for secure file system insights.
Instructions
Retrieve detailed metadata about a file or directory. Returns comprehensive information including size, creation time, last modified time, permissions, and type. This tool is perfect for understanding file characteristics without reading the actual content. Only works within allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file or directory to get information about |
Implementation Reference
- src/index.ts:682-705 (handler)Main handler for get_file_info tool: validates input, checks path permissions, retrieves file stats, and returns formatted metadata.case 'get_file_info': { const parsed = GetFileInfoArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } const validPath = await validatePath(parsed.data.path, config) const info = await getFileStats(validPath) await logger.debug(`Retrieved file info: ${validPath}`) endMetric() return { content: [ { type: 'text', text: Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join('\n'), }, ], } }
- src/index.ts:143-145 (schema)Zod schema defining the input arguments for the get_file_info tool (path parameter).const GetFileInfoArgsSchema = z.object({ path: z.string().describe('Path to the file or directory to get information about'), })
- src/index.ts:316-324 (registration)Tool registration in the list_tools response, including name, description, and input schema reference.{ name: 'get_file_info', description: 'Retrieve detailed metadata about a file or directory. Returns comprehensive ' + 'information including size, creation time, last modified time, permissions, ' + 'and type. This tool is perfect for understanding file characteristics ' + 'without reading the actual content. Only works within allowed directories.', inputSchema: zodToJsonSchema(GetFileInfoArgsSchema) as ToolInput, },
- src/index.ts:170-181 (helper)Helper function that fetches and formats detailed file system stats using Node.js fs.stat.async function getFileStats(filePath: string): Promise<FileInfo> { const stats = await fs.stat(filePath) return { size: stats.size, created: stats.birthtime, modified: stats.mtime, accessed: stats.atime, isDirectory: stats.isDirectory(), isFile: stats.isFile(), permissions: stats.mode.toString(8).slice(-3), } }