Skip to main content
Glama

list_directory_contents

Retrieve a structured listing of files and directories within a specified path in Vertex AI workspace, clearly marked as [FILE] or [DIR]. Helps navigate and identify specific files and folder contents without recursive search.

Instructions

Get a detailed listing of all files and directories directly within a specified path in the workspace filesystem. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is essential for understanding directory structure and finding specific files within a directory. Does not list recursively.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe path of the directory to list (relative to the workspace directory).

Implementation Reference

  • Handler logic for 'list_directory_contents' tool: parses args, validates path, reads directory entries using fs.readdir, formats output with [DIR]/[FILE] prefixes, sorts and joins.
    case "list_directory_contents": {
      const parsed = ListDirectoryArgsSchema.parse(args);
      const validPath = validateWorkspacePath(parsed.path);
      const entries = await fs.readdir(validPath, { withFileTypes: true });
      resultText = entries
        .map((entry) => `${entry.isDirectory() ? "[DIR] " : "[FILE]"} ${entry.name}`)
        .sort()
        .join("\n");
       if (!resultText) resultText = "(Directory is empty)";
      break;
  • Zod schema definition for input arguments (path: string) and conversion to JSON schema used in tool definition.
    // Schema definition (adapted from example.ts) - Exported
    export const ListDirectoryArgsSchema = z.object({
      path: z.string().describe("The path of the directory to list (relative to the workspace directory)."),
    });
    
    // Convert Zod schema to JSON schema
    const ListDirectoryJsonSchema = zodToJsonSchema(ListDirectoryArgsSchema);
  • Registration of listDirectoryTool in the allTools array, which is exported and used by the MCP server.
    listDirectoryTool,
  • Import of the listDirectoryTool for inclusion in allTools.
    import { listDirectoryTool } from "./list_directory.js";
  • Full tool definition including name, description, inputSchema reference, and buildPrompt for validation.
    export const listDirectoryTool: ToolDefinition = {
        name: "list_directory_contents", // Renamed slightly
        description:
          "Get a detailed listing of all files and directories directly within a specified path in the workspace filesystem. " +
          "Results clearly distinguish between files and directories with [FILE] and [DIR] " +
          "prefixes. This tool is essential for understanding directory structure and " +
          "finding specific files within a directory. Does not list recursively.",
        inputSchema: ListDirectoryJsonSchema as any, // Cast as any if needed
    
        // Minimal buildPrompt as execution logic is separate
        buildPrompt: (args: any, modelId: string) => {
            const parsed = ListDirectoryArgsSchema.safeParse(args);
            if (!parsed.success) {
                throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for list_directory_contents: ${parsed.error}`);
            }
            return {
                systemInstructionText: "",
                userQueryText: "",
                useWebSearch: false,
                enableFunctionCalling: false
            };
        },
        // No 'execute' function here
    };
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behavioral traits: the tool returns a detailed listing with [FILE] and [DIR] prefixes for clear distinction, operates on the workspace filesystem, and does not list recursively. It doesn't mention error conditions, permissions, or performance characteristics, but provides solid operational context.

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

Conciseness4/5

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

The description is appropriately sized with three sentences that each add value: the core functionality, output format details, and scope limitation. It's front-loaded with the main purpose. The third sentence ('This tool is essential...') could be considered slightly redundant but still provides useful context.

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

Completeness4/5

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

For a single-parameter tool with no annotations and no output schema, the description provides good coverage of what the tool does, how results are formatted, and its scope limitations. It doesn't describe the exact return format or error conditions, but given the tool's relative simplicity and clear behavioral description, it's reasonably complete.

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 input schema has 100% description coverage with a clear parameter description for 'path'. The description adds no additional parameter information beyond what's in the schema. According to scoring rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no param info in description.

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

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get a detailed listing'), resource ('files and directories'), and scope ('directly within a specified path'). It distinguishes from sibling tools like 'get_directory_tree' (which likely lists recursively) by explicitly stating 'Does not list recursively' and from 'search_filesystem' by focusing on directory listing rather than searching.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('essential for understanding directory structure and finding specific files within a directory') and distinguishes it from recursive alternatives by stating 'Does not list recursively'. However, it doesn't explicitly name alternative tools or provide when-not-to-use guidance beyond the non-recursive limitation.

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

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/shariqriazz/vertex-ai-mcp-server'

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