Skip to main content
Glama

Filesystem MCP Server

Official

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

NameRequiredDescriptionDefault
pathYes

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "path": { "type": "string" } }, "required": [ "path" ], "type": "object" }

Implementation Reference

  • 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 } }; }
  • 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(), });
  • 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 } }; } );
  • 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), }; }

Other Tools

Related 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/modelcontextprotocol/filesystem'

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