Skip to main content
Glama
gunjanjp

Linux Bash MCP Server

by gunjanjp

execute_bash_script

Run bash script files in WSL2 Linux environments with optional arguments, working directory, and timeout settings for automated Linux operations.

Instructions

Execute a bash script file in WSL2 Linux environment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptPathYesPath to the bash script file
argsNoArguments to pass to the script (optional)
workingDirectoryNoWorking directory for the script (optional)
timeoutNoTimeout in milliseconds (optional, uses config default)

Implementation Reference

  • The core handler function that executes the specified bash script in the WSL Linux environment. It constructs a WSL command, handles arguments escaping, executes via execAsync, and returns structured output with success status, stdout, stderr.
    async executeBashScript(args) {
      const { 
        scriptPath, 
        args: scriptArgs = [], 
        workingDirectory = ".", 
        timeout = this.config?.scriptTimeout || 60000 
      } = args;
      
      if (!scriptPath || typeof scriptPath !== "string") {
        throw new Error("Script path is required and must be a string");
      }
    
      if (!this.wslDistribution) {
        throw new Error("WSL distribution not configured");
      }
    
      try {
        // Prepare arguments string
        const argsString = scriptArgs.map(arg => `'${arg.replace(/'/g, "'\"'\"'")}'`).join(' ');
        
        // Construct WSL command
        const wslCommand = `wsl -d ${this.wslDistribution} -- bash -c "cd '${workingDirectory}' && bash '${scriptPath}' ${argsString}"`;
        
        console.error(`[DEBUG] Executing script: ${wslCommand}`);
        
        const { stdout, stderr } = await execAsync(wslCommand, {
          timeout,
          maxBuffer: this.config?.maxBufferSize || 10 * 1024 * 1024,
        });
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: true,
                scriptPath: scriptPath,
                args: scriptArgs,
                workingDirectory: workingDirectory,
                wslDistribution: this.wslDistribution,
                stdout: stdout || "",
                stderr: stderr || "",
                timestamp: new Date().toISOString()
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                success: false,
                scriptPath: scriptPath,
                args: scriptArgs,
                workingDirectory: workingDirectory,
                wslDistribution: this.wslDistribution,
                error: error.message,
                stdout: error.stdout || "",
                stderr: error.stderr || "",
                timestamp: new Date().toISOString()
              }, null, 2),
            },
          ],
        };
      }
    }
  • Defines the tool's metadata, description, and input schema specification for validation in the ListTools response.
    {
      name: "execute_bash_script",
      description: "Execute a bash script file in WSL2 Linux environment",
      inputSchema: {
        type: "object",
        properties: {
          scriptPath: {
            type: "string",
            description: "Path to the bash script file",
          },
          args: {
            type: "array",
            items: { type: "string" },
            description: "Arguments to pass to the script (optional)",
          },
          workingDirectory: {
            type: "string",
            description: "Working directory for the script (optional)",
          },
          timeout: {
            type: "number",
            description: "Timeout in milliseconds (optional, uses config default)",
          }
        },
        required: ["scriptPath"],
      },
  • src/index.js:284-285 (registration)
    Maps the tool name to its handler function in the CallToolRequestSchema switch dispatcher.
    case "execute_bash_script":
      return await this.executeBashScript(args);
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. It states what the tool does but doesn't describe execution behavior: whether it runs synchronously/asynchronously, how errors are handled, what permissions are required, whether scripts can be destructive, or what output format to expect. For a potentially powerful execution tool, this leaves significant behavioral questions unanswered.

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 states the core functionality without unnecessary words. It's appropriately sized for a straightforward execution tool and front-loads the essential information. Every word earns its place.

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?

For a script execution tool with no annotations and no output schema, the description is insufficient. It doesn't address critical context like execution safety, error handling, output format, or integration with the WSL2 environment. The description should provide more behavioral context given the tool's potential complexity and lack of structured metadata.

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 already documents all four parameters thoroughly. The description adds no parameter-specific information beyond what's in the schema. The baseline score of 3 reflects adequate parameter documentation through the schema alone, with no additional value from the description.

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 resource ('bash script file') with the specific environment context ('in WSL2 Linux environment'). It distinguishes from sibling 'execute_bash_command' by specifying script execution rather than command execution. However, it doesn't explicitly contrast with 'create_bash_script' which creates scripts rather than executing them.

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 like 'execute_bash_command' or 'create_bash_script'. It mentions the WSL2 environment but doesn't specify prerequisites, error conditions, or typical use cases. There's no explicit 'when to use' or 'when not to use' information.

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