list_directory
Retrieve a detailed directory listing from Obsidian iCloud MCP, distinguishing files and directories with [FILE] and [DIR] prefixes. Essential for navigating and identifying specific items within your Obsidian vault.
Instructions
Your task is to list directory under /Users/username/Library/Mobile Documents/iCloud~md~obsidian/Documents/my-vault. Get a detailed listing of all files and directories in a specified path. 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. Only works within allowed directories.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/file-system.ts:309-323 (handler)The handler function for the list_directory tool. It validates input using ListDirectoryArgsSchema, reads directory contents with fs.readdir, formats entries as [DIR] or [FILE], and returns formatted text.export async function listDirectory(args?: Record<string, unknown>) { const parsed = ListDirectoryArgsSchema.safeParse(args) if (!parsed.success) { throw new Error(`Invalid arguments for list_directory: ${parsed.error}`) } const entries = await fs.readdir(parsed.data.path, { withFileTypes: true }) const formatted = entries .map((entry) => `${entry.isDirectory() ? '[DIR]' : '[FILE]'} ${entry.name}`) .join('\n') return { content: [{ type: 'text', text: formatted }] } }
- src/schemas.ts:34-36 (schema)Zod schema defining the input for list_directory: an object with 'path' string.export const ListDirectoryArgsSchema = z.object({ path: z.string() })
- src/index.ts:136-139 (registration)Tool registration in ListToolsRequestHandler: defines name, description (from prompt), and inputSchema.name: 'list_directory', description: listDirectoryPrompt(args), inputSchema: zodToJsonSchema(ListDirectoryArgsSchema) as ToolInput },
- src/index.ts:199-201 (registration)Handler dispatch in CallToolRequestHandler switch: calls listDirectory on tool invocation.case 'list_directory': { return listDirectory(args) }
- src/prompts.ts:37-42 (helper)Prompt generator for the list_directory tool description, including root paths and usage instructions.export const listDirectoryPrompt = (rootPaths: string[]) => `Your task is to list directory under ${rootPaths.join(', ')}. ` + 'Get a detailed listing of all files and directories in a specified path. ' + '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. Only works within allowed directories.'