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

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "path": { "description": "The path of the directory to list (relative to the workspace directory).", "type": "string" } }, "required": [ "path" ], "type": "object" }

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 };

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