Skip to main content
Glama

get_file_info

Read-only

Retrieve file metadata including size, timestamps, permissions, and content details for text or Excel files using absolute paths.

Instructions

                    Retrieve detailed metadata about a file or directory including:
                    - size
                    - creation time
                    - last modified time
                    - permissions
                    - type
                    - lineCount (for text files)
                    - lastLine (zero-indexed number of last line, for text files)
                    - appendPosition (line number for appending, for text files)
                    - sheets (for Excel files - array of {name, rowCount, colCount})

                    Only works within allowed directories.
                    
                    IMPORTANT: Always use absolute paths for reliability. Paths are automatically normalized regardless of slash direction. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.
                    This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • MCP tool handler for get_file_info: parses args with schema, calls getFileInfo(path), formats result as text ServerResult.
    export async function handleGetFileInfo(args: unknown): Promise<ServerResult> {
        try {
            const parsed = GetFileInfoArgsSchema.parse(args);
            const info = await getFileInfo(parsed.path);
    
            // Generic formatting for any file type
            const formattedText = Object.entries(info)
                .map(([key, value]) => `${key}: ${formatValue(value)}`)
                .join('\n');
    
            return {
                content: [{
                    type: "text",
                    text: formattedText
                }],
            };
        } catch (error) {
            const errorMessage = error instanceof Error ? error.message : String(error);
            return createErrorResponse(errorMessage);
        }
    }
  • Zod input schema for get_file_info tool requiring 'path' string.
    export const GetFileInfoArgsSchema = z.object({
      path: z.string(),
    });
  • Core getFileInfo function: validates path, fetches stats and type-specific metadata (lines, sheets, PDF pages, etc.), returns detailed file info record.
    export async function getFileInfo(filePath: string): Promise<Record<string, any>> {
        const validPath = await validatePath(filePath);
    
        // Get fs.stat as a fallback for any missing fields
        const stats = await fs.stat(validPath);
        const fallbackInfo = {
            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),
            fileType: 'text' as const,
            metadata: undefined as Record<string, any> | undefined,
        };
    
        // Get appropriate handler for this file type (async - includes binary detection)
        const handler = await getFileHandler(validPath);
    
        // Use handler to get file info, with fallback
        let fileInfo;
        try {
            fileInfo = await handler.getInfo(validPath);
        } catch (error) {
            // If handler fails, use fallback stats
            fileInfo = fallbackInfo;
        }
    
        // Convert to legacy format (for backward compatibility)
        // Use handler values with fallback to fs.stat values for any missing fields
        const info: Record<string, any> = {
            size: fileInfo.size ?? fallbackInfo.size,
            created: fileInfo.created ?? fallbackInfo.created,
            modified: fileInfo.modified ?? fallbackInfo.modified,
            accessed: fileInfo.accessed ?? fallbackInfo.accessed,
            isDirectory: fileInfo.isDirectory ?? fallbackInfo.isDirectory,
            isFile: fileInfo.isFile ?? fallbackInfo.isFile,
            permissions: fileInfo.permissions ?? fallbackInfo.permissions,
            fileType: fileInfo.fileType ?? fallbackInfo.fileType,
        };
    
        // Add type-specific metadata from file handler
        if (fileInfo.metadata) {
            // For text files
            if (fileInfo.metadata.lineCount !== undefined) {
                info.lineCount = fileInfo.metadata.lineCount;
                info.lastLine = fileInfo.metadata.lineCount - 1;
                info.appendPosition = fileInfo.metadata.lineCount;
            }
    
            // For Excel files
            if (fileInfo.metadata.sheets) {
                info.sheets = fileInfo.metadata.sheets;
                info.isExcelFile = true;
            }
    
            // For images
            if (fileInfo.metadata.isImage) {
                info.isImage = true;
            }
    
            // For PDF files
            if (fileInfo.metadata.isPdf) {
                info.isPdf = true;
                info.totalPages = fileInfo.metadata.totalPages;
                if (fileInfo.metadata.title) info.title = fileInfo.metadata.title;
                if (fileInfo.metadata.author) info.author = fileInfo.metadata.author;
            }
    
            // For binary files
            if (fileInfo.metadata.isBinary) {
                info.isBinary = true;
            }
        }
    
        return info;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare readOnlyHint=true, and the description aligns by describing a retrieval operation without contradiction. It adds valuable behavioral context beyond annotations: path normalization rules, reliability warnings about relative/tilde paths, and the 'only works within allowed directories' constraint. However, it doesn't mention rate limits, auth needs, or error conditions, leaving some gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with bullet points for metadata fields and clear sections for constraints and usage notes. It's appropriately sized but includes some verbose phrasing (e.g., 'This command can be referenced as...') that doesn't add critical value, slightly reducing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (single parameter, no output schema), the description is largely complete: it covers purpose, usage, parameter semantics, and behavioral constraints. However, it lacks details on error handling, exact return format, or examples, which would enhance completeness for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for the single 'path' parameter, the description fully compensates by providing rich semantics: it explains that paths must be absolute for reliability, describes normalization behavior, warns against relative/tilde paths, and ties usage to allowed directories. This adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('retrieve detailed metadata') and resources ('file or directory'), and distinguishes it from siblings like list_directory (which lists contents) or read_file (which reads content). It enumerates the specific metadata fields returned, making the purpose highly specific and differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool vs. alternatives: it specifies 'only works within allowed directories' (contextual constraint) and offers path usage rules (absolute vs. relative). It implicitly distinguishes from siblings by focusing on metadata retrieval rather than listing, reading, or writing files, though it doesn't name specific alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wonderwhy-er/ClaudeComputerCommander'

If you have feedback or need assistance with the MCP directory API, please join our Discord server