Skip to main content
Glama

file_stat

Retrieve detailed statistics for files or directories, including size, permissions, and modification timestamps, to analyze and manage file system information.

Instructions

Get file or directory statistics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to file or directory

Implementation Reference

  • Implementation of the file_stat logic which retrieves file stats and returns them as a tool result.
    async function fileStatImpl(input: FileStatInput): Promise<ToolResult> {
      try {
        const absolutePath = path.resolve(input.path);
    
        const stats = await fs.stat(absolutePath);
        const lstat = await fs.lstat(absolutePath);
    
        const result: FileStat = {
          path: absolutePath,
          name: path.basename(absolutePath),
          size: stats.size,
          isFile: stats.isFile(),
          isDirectory: stats.isDirectory(),
          isSymlink: lstat.isSymbolicLink(),
          created: stats.birthtime.toISOString(),
          modified: stats.mtime.toISOString(),
          accessed: stats.atime.toISOString(),
        };
    
        // Add formatted size for convenience
        const formattedResult = {
          ...result,
          sizeFormatted: formatBytes(stats.size),
        };
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(formattedResult, null, 2),
            },
          ],
        };
      } catch (error) {
        const err = error as NodeJS.ErrnoException;
    
        if (err.code === 'ENOENT') {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'FILE_NOT_FOUND',
                  message: `Path not found: ${input.path}`,
                }),
              },
            ],
          };
        }
    
        if (err.code === 'EACCES') {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'PERMISSION_DENIED',
                  message: `Permission denied: ${input.path}`,
                }),
              },
            ],
          };
        }
    
        return {
          isError: true,
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                code: 'UNKNOWN_ERROR',
                message: `Error getting stats: ${err.message}`,
              }),
            },
          ],
        };
      }
    }
  • Registration of the 'file_stat' tool with the MCP server.
    server.tool(
      'file_stat',
      'Get file or directory statistics',
      {
        path: z.string().describe('Path to file or directory'),
      },
      async (args) => {
        const input = FileStatInputSchema.parse(args);
        return await fileStatImpl(input);
      }
    );
  • Zod schema definition for file_stat tool input validation.
    export const FileStatInputSchema = z.object({
      path: z.string().describe('Path to file or directory'),
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' statistics, implying a read-only operation, but doesn't specify what statistics are returned (e.g., size, type, permissions), error handling for invalid paths, or performance considerations. This leaves significant gaps for a tool with no annotation coverage.

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

Conciseness5/5

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

The description is extremely concise and front-loaded in a single sentence, with zero wasted words. It directly communicates the core functionality without unnecessary elaboration, making it efficient for quick understanding.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what statistics are returned (e.g., file size, modification time), how errors are handled, or the tool's scope compared to siblings. For a tool that retrieves metadata, more context is needed to guide effective use.

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

Parameters3/5

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

The description adds no parameter semantics beyond what the input schema provides. With 100% schema description coverage, the schema already documents the 'path' parameter adequately. The baseline score of 3 reflects that the schema does the heavy lifting, and the description doesn't compensate with additional context like path format examples or constraints.

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

Purpose4/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 a specific verb ('Get') and resource ('file or directory statistics'), making it immediately understandable. However, it doesn't differentiate from sibling tools like 'file_exists' or 'get_disk_usage' that also retrieve file system information, which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'file_exists' (checks existence), 'get_disk_usage' (gets space usage), and 'read_directory' (lists contents), there's no indication of when 'file_stat' is preferred for retrieving metadata such as size, permissions, or timestamps.

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/mcp-tool-shop-org/mcp-file-forge'

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