get_file_info
Retrieve detailed file metadata including size, timestamps, permissions, and type to analyze file properties and manage system resources within allowed directories.
Instructions
Retrieve detailed metadata about a file or directory including size, creation time, last modified time, permissions, and type. Only works within allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/tools/filesystem.ts:137-150 (handler)The core handler function that implements the get_file_info tool logic: validates the file path for security and retrieves comprehensive file metadata including size, timestamps, type, and permissions.export async function getFileInfo(filePath: string): Promise<Record<string, any>> { const validPath = await validatePath(filePath); const stats = await fs.stat(validPath); 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), }; }
- src/server.ts:180-187 (registration)Tool registration in the MCP server's ListTools response, defining the name, description, and input schema for get_file_info.{ name: "get_file_info", description: "Retrieve detailed metadata about a file or directory including size, " + "creation time, last modified time, permissions, and type. " + "Only works within allowed directories.", inputSchema: zodToJsonSchema(GetFileInfoArgsSchema), },
- src/tools/schemas.ts:63-65 (schema)Zod input schema for the get_file_info tool, validating the required 'path' parameter.export const GetFileInfoArgsSchema = z.object({ path: z.string(), });
- src/server.ts:315-326 (handler)Server-side dispatcher handler for get_file_info: parses input args, invokes the core getFileInfo function, and formats the response for MCP.case "get_file_info": { const parsed = GetFileInfoArgsSchema.parse(args); const info = await getFileInfo(parsed.path); return { content: [{ type: "text", text: Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join('\n') }], }; }