get_file_info
Retrieve file or directory metadata, including size, type, permissions, creation, and modification times, to analyze file characteristics without accessing content. Works within permitted directories.
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 |
Implementation Reference
- src/handlers/file-handlers.ts:182-196 (handler)The handler function for the 'get_file_info' tool. Parses input arguments using the schema, validates the file path, retrieves file statistics using getFileStats utility, and returns formatted metadata as text.export async function handleGetFileInfo( args: unknown, allowedDirectories: string[], symlinksMap: Map<string, string>, noFollowSymlinks: boolean ) { const parsed = parseArgs(GetFileInfoArgsSchema, args, 'get_file_info'); const validPath = await validatePath(parsed.path, allowedDirectories, symlinksMap, noFollowSymlinks); const info = await getFileStats(validPath); return { content: [{ type: "text", text: Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join("\n") }], }; }
- src/schemas/file-operations.ts:51-54 (schema)TypeBox schema definition for GetFileInfoArgs, which requires a 'path' string parameter.export const GetFileInfoArgsSchema = Type.Object({ path: Type.String(), }); export type GetFileInfoArgs = Static<typeof GetFileInfoArgsSchema>;
- index.ts:245-246 (registration)Registers the 'get_file_info' tool handler in the toolHandlers object, binding it to FastMCP execution with server context.get_file_info: (a: unknown) => handleGetFileInfo(a, allowedDirectories, symlinksMap, noFollowSymlinks),
- index.ts:311-311 (registration)Declares the tool metadata (name and description) in the allTools array used for conditional registration based on permissions.{ name: "get_file_info", description: "Get file metadata" },
- src/utils/file-utils.ts:21-32 (helper)Utility function that retrieves and formats file statistics (size, dates, type, permissions) using fs.stat, used by the handler.export async function getFileStats(filePath: string): Promise<ImmutableFileInfo> { const stats = await fsPromises.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), }; }