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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | The path of the directory to list (relative to the workspace directory). |
Input Schema (JSON Schema)
Implementation Reference
- src/index.ts:464-473 (handler)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;
- src/tools/list_directory.ts:6-12 (schema)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);
- src/tools/index.ts:53-53 (registration)Registration of listDirectoryTool in the allTools array, which is exported and used by the MCP server.listDirectoryTool,
- src/tools/index.ts:13-13 (registration)Import of the listDirectoryTool for inclusion in allTools.import { listDirectoryTool } from "./list_directory.js";
- src/tools/list_directory.ts:14-37 (schema)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 };