Skip to main content
Glama
gunjanjp

Linux Bash MCP Server

by gunjanjp

execute_bash_command

Execute bash commands in a WSL2 Linux environment from Claude Desktop to run scripts, manage files, and perform system operations on Windows.

Instructions

Execute a bash command in WSL2 Linux environment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe bash command to execute
workingDirectoryNoWorking directory for the command (optional, defaults to current directory)
timeoutNoTimeout in milliseconds (optional, uses config default)

Implementation Reference

  • The core handler function that destructures the input arguments, constructs a WSL bash command, executes it using execAsync, and returns a structured JSON response with success status, output, and error details if applicable.
    async executeBashCommand(args) {
      const { 
        command, 
        workingDirectory = ".", 
        timeout = this.config?.defaultTimeout || 30000 
      } = args;
      
      console.error(`[DEBUG] Executing command: ${command}`);
      
      if (!command || typeof command !== "string") {
        throw new Error("Command is required and must be a string");
      }
    
      if (!this.wslDistribution) {
        throw new Error("WSL distribution not configured");
      }
    
      try {
        // Construct WSL command
        const wslCommand = `wsl -d ${this.wslDistribution} -- bash -c "cd '${workingDirectory}' && ${command}"`;
        
        console.error(`[DEBUG] WSL command: ${wslCommand}`);
        
        const { stdout, stderr } = await execAsync(wslCommand, {
          timeout,
          maxBuffer: this.config?.maxBufferSize || 10 * 1024 * 1024,
        });
    
        console.error(`[DEBUG] Command executed successfully`);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: true,
                command: command,
                workingDirectory: workingDirectory,
                wslDistribution: this.wslDistribution,
                stdout: stdout || "",
                stderr: stderr || "",
                timestamp: new Date().toISOString()
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(`[ERROR] Command execution failed:`, error);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: false,
                command: command,
                workingDirectory: workingDirectory,
                wslDistribution: this.wslDistribution,
                error: error.message,
                stdout: error.stdout || "",
                stderr: error.stderr || "",
                timestamp: new Date().toISOString()
              }, null, 2),
            },
          ],
        };
      }
    }
  • Defines the JSON schema for tool inputs, specifying properties for command (required string), optional workingDirectory and timeout.
    inputSchema: {
      type: "object",
      properties: {
        command: {
          type: "string",
          description: "The bash command to execute",
        },
        workingDirectory: {
          type: "string",
          description: "Working directory for the command (optional, defaults to current directory)",
        },
        timeout: {
          type: "number",
          description: "Timeout in milliseconds (optional, uses config default)",
        }
      },
      required: ["command"],
    },
  • src/index.js:165-186 (registration)
    Registers the tool in the ListTools response, providing name, description, and input schema.
    {
      name: "execute_bash_command",
      description: "Execute a bash command in WSL2 Linux environment",
      inputSchema: {
        type: "object",
        properties: {
          command: {
            type: "string",
            description: "The bash command to execute",
          },
          workingDirectory: {
            type: "string",
            description: "Working directory for the command (optional, defaults to current directory)",
          },
          timeout: {
            type: "number",
            description: "Timeout in milliseconds (optional, uses config default)",
          }
        },
        required: ["command"],
      },
    },
  • src/index.js:282-283 (registration)
    In the CallToolRequestSchema handler, routes requests for this tool to the executeBashCommand method.
    case "execute_bash_command":
      return await this.executeBashCommand(args);
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action 'execute' but doesn't disclose critical traits: it doesn't mention that this executes arbitrary commands (potentially destructive), doesn't specify permission requirements (e.g., user privileges), doesn't describe output format (e.g., stdout/stderr capture), and doesn't note error handling. For a tool that can run any bash command, this lack of safety and behavioral context is a significant gap.

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 directly states the tool's purpose without any fluff. It's front-loaded with the core action and context, making it easy to parse. Every word earns its place, with no redundant or vague phrasing.

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

Completeness2/5

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

Given the complexity of executing arbitrary bash commands (high-risk operation), no annotations, and no output schema, the description is incomplete. It lacks critical context: no mention of security implications (e.g., command injection risks), no details on what happens on success/failure (e.g., return codes, output capture), and no guidance on error handling. For a tool with such broad and potentially dangerous capabilities, this is inadequate.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters (command, workingDirectory, timeout). The description adds no parameter-specific semantics beyond what's in the schema—it doesn't explain command syntax, working directory defaults, or timeout implications. Baseline 3 is appropriate since the schema does the heavy lifting, but the description doesn't compensate with additional insights.

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 verb 'execute' and the resource 'bash command' with the context 'in WSL2 Linux environment'. It distinguishes from siblings like 'execute_bash_script' by specifying raw command execution rather than script file execution. However, it doesn't explicitly contrast with 'check_wsl_status' or 'get_system_info', keeping it from a perfect score.

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 when to prefer 'execute_bash_command' over 'execute_bash_script' (e.g., for simple one-liners vs. complex scripts) or 'create_bash_script' (e.g., for reusable commands). There's also no mention of prerequisites like WSL2 being installed or running, which is implied but not stated.

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