Skip to main content
Glama
lofcz

MCP Smart Filesystem Server

by lofcz

list_directory

Display directory contents with file metadata including sizes and line counts to help users explore and understand file system structure.

Instructions

List contents of a directory with metadata including file sizes and line counts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesDirectory path to list. Use '.' for workspace root

Implementation Reference

  • index.ts:65-77 (registration)
    Registration of the 'list_directory' tool in the MCP tools array, specifying name, description, and input schema requiring a 'path' parameter.
      name: 'list_directory',
      description: 'List contents of a directory with metadata including file sizes and line counts',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: "Directory path to list. Use '.' for workspace root"
          }
        },
        required: ['path']
      }
    },
  • Dispatch handler in the CallToolRequestSchema that parses input arguments, validates the path, invokes the listDirectory function, and formats the response as MCP content.
    case 'list_directory': {
      const schema = z.object({ path: z.string() });
      const { path } = schema.parse(args);
      const validatedPath = await validatePath(path);
      const result = await listDirectory(validatedPath);
      
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(result, null, 2)
        }]
      };
    }
  • TypeScript interfaces defining the structure of directory entries and the overall directory listing output returned by the listDirectory handler.
    export interface DirectoryEntry {
      name: string;
      type: 'file' | 'directory';
      size: string | null;
      lines?: number;
      itemCount?: number;
    }
    
    export interface DirectoryListing {
      path: string;
      entries: DirectoryEntry[];
      summary: {
        totalFiles: number;
        totalDirectories: number;
        totalSize: string;
      };
    }
  • lib.ts:194-267 (handler)
    Core implementation of the list_directory tool: asynchronously reads directory entries, categorizes files and directories, computes metadata (sizes, line counts for small text files, subdir item counts), and returns structured DirectoryListing.
    export async function listDirectory(dirPath: string): Promise<DirectoryListing> {
      const entries = await fs.readdir(dirPath, { withFileTypes: true });
      const result: DirectoryEntry[] = [];
      let totalFiles = 0;
      let totalDirs = 0;
      let totalBytes = 0;
    
      for (const entry of entries) {
        const fullPath = path.join(dirPath, entry.name);
        
        if (entry.isDirectory()) {
          totalDirs++;
          try {
            const subEntries = await fs.readdir(fullPath);
            result.push({
              name: entry.name,
              type: 'directory',
              size: null,
              itemCount: subEntries.length
            });
          } catch {
            result.push({
              name: entry.name,
              type: 'directory',
              size: null,
              itemCount: 0
            });
          }
        } else if (entry.isFile()) {
          totalFiles++;
          try {
            const stats = await fs.stat(fullPath);
            totalBytes += stats.size;
            
            // For text files, try to count lines
            let lines: number | undefined;
            if (stats.size < 10 * 1024 * 1024) { // Only for files < 10MB
              const isBinary = await isBinaryFile(fullPath);
              if (!isBinary) {
                try {
                  const content = await readFileContent(fullPath);
                  lines = countLines(content);
                } catch {
                  // Ignore errors reading file content
                }
              }
            }
            
            result.push({
              name: entry.name,
              type: 'file',
              size: formatSize(stats.size),
              lines
            });
          } catch {
            result.push({
              name: entry.name,
              type: 'file',
              size: '0 B'
            });
          }
        }
      }
    
      return {
        path: dirPath,
        entries: result,
        summary: {
          totalFiles,
          totalDirectories: totalDirs,
          totalSize: formatSize(totalBytes)
        }
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions metadata output (file sizes, line counts) which is useful, but doesn't cover important aspects like pagination behavior, error conditions (e.g., non-existent paths), permission requirements, or rate limits. For a read operation with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 a single, efficient sentence that states the core purpose and key output details. Every word earns its place with no redundancy or unnecessary elaboration. It's appropriately sized and front-loaded with the essential information.

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

Completeness3/5

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

For a simple read operation with 1 parameter and 100% schema coverage, the description covers the basic purpose and output format. However, with no annotations and no output schema, it should ideally provide more behavioral context about error handling, permissions, or result format. The description is minimally adequate but leaves gaps in understanding the tool's complete behavior.

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?

Schema description coverage is 100% with a single 'path' parameter well-documented in the schema. The description adds no additional parameter information beyond what the schema provides. With high schema coverage, the baseline is 3 even without parameter details in the description.

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 verb 'list' and resource 'contents of a directory' with specific metadata details (file sizes and line counts). It distinguishes from siblings like 'find_files' (search) and 'get_file_info' (single file), but doesn't explicitly name alternatives. Purpose is specific but sibling differentiation is implicit rather than explicit.

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

Usage Guidelines3/5

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

The description implies usage for directory listing with metadata, but provides no explicit guidance on when to use this versus alternatives like 'list_allowed_directories' or 'find_files'. The schema description suggests using '.' for workspace root, which gives some context, but no when-not-to-use or prerequisite information is provided.

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/lofcz/mcp-filesystem-smart'

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