Skip to main content
Glama
ai-yliu

Filesystem MCP Server

by ai-yliu

list_directory

Browse and view contents of directories by listing files and folders with clear type indicators for easy navigation.

Instructions

List directory contents with [FILE] or [DIR] prefixes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the directory to list

Implementation Reference

  • The handler for the 'list_directory' tool. It validates the path, reads the directory contents, stats each entry to determine if it's a file or directory, formats with [DIR] or [FILE] prefixes, and returns the list as text.
    case 'list_directory': {
      const { path: dirPath } = request.params.arguments as { path: string };
      validatePath(dirPath);
      
      const entries = await fs.readdir(dirPath);
      const formattedEntries = await Promise.all(
        entries.map(async (entry) => {
          const entryPath = path.join(dirPath, entry);
          const stats = await fs.stat(entryPath);
          const prefix = stats.isDirectory() ? '[DIR]' : '[FILE]';
          return `${prefix} ${entry}`;
        })
      );
      
      return {
        content: [
          {
            type: 'text',
            text: formattedEntries.join('\n'),
          },
        ],
      };
    }
  • src/index.ts:158-171 (registration)
    Registration of the 'list_directory' tool in the list of tools provided by ListToolsRequestSchema, including its name, description, and input schema.
    {
      name: 'list_directory',
      description: 'List directory contents with [FILE] or [DIR] prefixes',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the directory to list',
          },
        },
        required: ['path'],
      },
    },
  • The input schema definition for the 'list_directory' tool, specifying the required 'path' parameter.
    inputSchema: {
      type: 'object',
      properties: {
        path: {
          type: 'string',
          description: 'Path to the directory to list',
        },
      },
      required: ['path'],
    },

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/ai-yliu/filesystem-mcp-server'

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