Skip to main content
Glama

get_file_info

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; }

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