Skip to main content
Glama
koopatroopa787

MCP PC Control Server

list_directory

Retrieve a detailed listing of files and directories in a specified path, including names, types, sizes, and modification times to understand directory structure and locate files.

Instructions

Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe path of the directory to list

Implementation Reference

  • The handler function that executes the 'list_directory' tool. It reads the directory contents using fs.readdir, gets stats for each entry, and returns a JSON-formatted list of items with name, type, size, and modification time.
    case "list_directory": {
      const dirPath = args.path as string;
      const entries = await fs.readdir(dirPath, { withFileTypes: true });
    
      const items = await Promise.all(
        entries.map(async (entry) => {
          const fullPath = path.join(dirPath, entry.name);
          const stats = await fs.stat(fullPath);
          return {
            name: entry.name,
            type: entry.isDirectory() ? "directory" : "file",
            size: stats.size,
            modified: stats.mtime.toISOString(),
          };
        })
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(items, null, 2),
          },
        ],
      };
    }
  • The tool definition including name, description, and input schema for 'list_directory', which specifies the required 'path' parameter.
    {
      name: "list_directory",
      description: "Get a detailed listing of all files and directories in a specified path. Results include names, types (file/directory), sizes, and modification times. Useful for understanding directory structure and finding files.",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "The path of the directory to list",
          },
        },
        required: ["path"],
      },
    },
  • src/index.ts:261-263 (registration)
    The handler for ListToolsRequestSchema that returns the TOOLS array, which includes the 'list_directory' tool registration.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return { tools: 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/koopatroopa787/first_mcp'

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