list_directory
List contents of a directory in a WSL2 Linux environment. Specify a path or use the current directory. Optionally, display detailed information using 'ls -la'.
Instructions
List contents of a directory in WSL2 Linux environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| detailed | No | Show detailed information (ls -la) (optional, defaults to false) | |
| path | No | Directory path to list (optional, defaults to current directory) | . |
Implementation Reference
- src/index.js:513-559 (handler)The main handler function for the 'list_directory' tool. It destructures the input arguments for directory path and detailed flag, constructs an appropriate 'ls' command based on the detailed parameter, executes it via WSL using execAsync, and returns a structured response with the directory listing or error information.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)Input schema for the list_directory tool, specifying the 'path' parameter (string, optional, defaults to '.') and 'detailed' parameter (boolean, optional, defaults to false). This defines the validation and structure for tool inputs.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:238-255 (registration)Registration of the 'list_directory' tool in the ListToolsRequestSchema response. Includes the tool name, description, and input schema. This is how the tool is advertised to MCP clients.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 } }, }, },
- src/index.js:288-289 (registration)Dispatch case in the CallToolRequestSchema handler that routes calls to the 'list_directory' tool to its handler method.case "list_directory": return await this.listDirectory(args);