get_file_info
Retrieve detailed metadata about files or directories, including size, timestamps, permissions, and type, to understand file characteristics without accessing content.
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/filesystem/index.ts:651-661 (handler)The main handler function for the get_file_info tool. It validates the input path, retrieves detailed file statistics using getFileStats, formats the info into a readable text string, and returns it in both content and structuredContent formats as required by MCP.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:139-141 (schema)Zod schema defining the input arguments for the get_file_info tool, specifically requiring a 'path' string.const GetFileInfoArgsSchema = z.object({ path: z.string(), });
- src/filesystem/index.ts:636-662 (registration)Registration of the get_file_info tool on the MCP server, including name, title, detailed description, input/output schemas, annotations indicating it's read-only, and reference to the handler function.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 } }; } );