Get File Info
get_file_infoRetrieve detailed metadata about a file or directory: size, creation and modification times, permissions, and type. No content reading required.
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes |
Implementation Reference
- src/filesystem/index.ts:670-681 (handler)The handler function that executes the get_file_info tool logic - validates the path, calls getFileStats, formats the result as text, and returns it.
async (args: z.infer<typeof GetFileInfoArgsSchema>) => { const validPath = await validatePath(args.path); const info = await getFileStats(validPath); const text = Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join("\n"); return { content: [{ type: "text" as const, text }], structuredContent: { content: text } }; } ); - src/filesystem/index.ts:158-160 (schema)Zod schema for input validation of get_file_info - defines 'path' as a required string.
const GetFileInfoArgsSchema = z.object({ path: z.string(), }); - src/filesystem/index.ts:655-681 (registration)Registration of the 'get_file_info' tool with the MCP server, including title, description, input/output schemas, and readOnlyHint annotation.
server.registerTool( "get_file_info", { title: "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: { path: z.string() }, outputSchema: { content: z.string() }, annotations: { readOnlyHint: true } }, async (args: z.infer<typeof GetFileInfoArgsSchema>) => { const validPath = await validatePath(args.path); const info = await getFileStats(validPath); const text = Object.entries(info) .map(([key, value]) => `${key}: ${value}`) .join("\n"); return { content: [{ type: "text" as const, text }], structuredContent: { content: text } }; } ); - src/filesystem/lib.ts:144-155 (helper)The getFileStats helper function that uses fs.stat to retrieve file metadata (size, created, modified, accessed, isDirectory, isFile, permissions).
export 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), }; } - src/filesystem/lib.ts:24-32 (helper)The FileInfo interface defining the shape of data returned by getFileStats.
interface FileInfo { size: number; created: Date; modified: Date; accessed: Date; isDirectory: boolean; isFile: boolean; permissions: string; }