list_directory
List directory contents in WSL2 Linux to view files and folders, with options for basic or detailed output.
Instructions
List contents of a directory in WSL2 Linux environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Directory path to list (optional, defaults to current directory) | . |
| detailed | No | Show detailed information (ls -la) (optional, defaults to false) |
Implementation Reference
- src/index.js:513-559 (handler)The handler function for the 'list_directory' tool. It destructures the input arguments, constructs an 'ls' command (with optional '-la' for detailed view), executes it via WSL using execAsync, and returns a structured JSON response with the directory listing or error.async listDirectory(args) { const { path: dirPath = ".", detailed = false } = args; if (!this.wslDistribution) { throw new Error("WSL distribution not configured"); } try { const command = detailed ? `ls -la '${dirPath}'` : `ls '${dirPath}'`; const wslCommand = `wsl -d ${this.wslDistribution} -- ${command}`; console.error(`[DEBUG] Listing directory: ${wslCommand}`); const { stdout, stderr } = await execAsync(wslCommand); return { content: [ { type: "text", text: JSON.stringify({ success: true, path: dirPath, detailed: detailed, wslDistribution: this.wslDistribution, listing: stdout || "", stderr: stderr || "", timestamp: new Date().toISOString() }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ success: false, path: dirPath, wslDistribution: this.wslDistribution, error: error.message, timestamp: new Date().toISOString() }, null, 2), }, ], }; }
- src/index.js:240-254 (schema)The input schema defining the parameters for the 'list_directory' tool: optional 'path' (defaults to '.') and optional 'detailed' boolean (defaults to false). Used for validation in tool calls.inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory path to list (optional, defaults to current directory)", default: "." }, detailed: { type: "boolean", description: "Show detailed information (ls -la) (optional, defaults to false)", default: false } }, },
- src/index.js:288-289 (registration)The switch case in the CallToolRequestSchema handler that registers and dispatches 'list_directory' tool calls to the listDirectory method.case "list_directory": return await this.listDirectory(args);
- src/index.js:237-255 (registration)The tool specification object returned by ListToolsRequestSchema handler, registering the 'list_directory' tool with its name, description, and input schema.{ name: "list_directory", description: "List contents of a directory in WSL2 Linux environment", inputSchema: { type: "object", properties: { path: { type: "string", description: "Directory path to list (optional, defaults to current directory)", default: "." }, detailed: { type: "boolean", description: "Show detailed information (ls -la) (optional, defaults to false)", default: false } }, }, },