Skip to main content
Glama
gunjanjp

Linux Bash MCP Server

by gunjanjp

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
NameRequiredDescriptionDefault
pathNoDirectory path to list (optional, defaults to current directory).
detailedNoShow detailed information (ls -la) (optional, defaults to false)

Implementation Reference

  • 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),
            },
          ],
        };
      }
  • 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
          }
        },
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'List contents' implies a read-only operation, it doesn't explicitly state this or mention other important behaviors like error handling, permission requirements, output format, or whether it works with symbolic links. The WSL2 environment context is useful but insufficient for a mutation-sensitive agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without unnecessary words. It's appropriately sized for a simple directory listing tool and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple read operation with 2 parameters and 100% schema coverage, the description is minimally adequate. However, with no annotations and no output schema, the agent lacks information about return format, error conditions, and behavioral constraints. The description doesn't compensate for these gaps, leaving the tool underspecified for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 100% description coverage, so parameters are fully documented in the structured fields. The description adds no additional parameter information beyond what's already in the schema descriptions. This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List contents') and resource ('directory in WSL2 Linux environment'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'execute_bash_command' or 'get_system_info', which could also potentially list directory contents through different mechanisms.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'execute_bash_command' (which could run 'ls' commands) or explain why this specialized tool exists. There's no context about prerequisites, limitations, or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/gunjanjp/linuxshell-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server