get_file_info
Retrieve detailed file or directory metadata such as size, permissions, creation and modification times. Understand file characteristics without accessing content, limited to allowed 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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- src/filesystem/index.ts:651-661 (handler)The main handler function for the get_file_info tool. It validates the provided path, fetches file statistics using the getFileStats helper, formats the stats into a readable text string, and returns it as structured content.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, which requires a single 'path' string parameter.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 title, description, input/output schemas, annotations, and the inline 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 } }; } );
- src/filesystem/lib.ts:121-132 (helper)Core helper function that executes fs.stat to retrieve detailed file statistics including size, timestamps, type flags, and octal permissions, used by the get_file_info handler.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), }; }