Skip to main content
Glama
gunjanjp

Linux Bash MCP Server

by gunjanjp

create_bash_script

Generate bash script files with custom content and set execution permissions for automating Linux tasks in WSL2 environments on Windows.

Instructions

Create a bash script file with specified content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptPathYesPath where to create the script file
contentYesContent of the bash script
executableNoMake the script executable (optional, defaults to true)

Implementation Reference

  • The core handler function for the 'create_bash_script' tool. It validates inputs, escapes the script content, writes it to the specified path in the WSL Linux environment using 'echo > file', makes it executable if requested via 'chmod +x', and returns a JSON-formatted success or error response.
    async createBashScript(args) { const { scriptPath, content, executable = true } = args; if (!scriptPath || typeof scriptPath !== "string") { throw new Error("Script path is required and must be a string"); } if (!content || typeof content !== "string") { throw new Error("Script content is required and must be a string"); } if (!this.wslDistribution) { throw new Error("WSL distribution not configured"); } try { // Escape content for bash const escapedContent = content.replace(/'/g, "'\"'\"'"); // Create the script file const createCommand = `wsl -d ${this.wslDistribution} -- bash -c "echo '${escapedContent}' > '${scriptPath}'"`; console.error(`[DEBUG] Creating script: ${scriptPath}`); await execAsync(createCommand); // Make executable if requested if (executable) { const chmodCommand = `wsl -d ${this.wslDistribution} -- chmod +x '${scriptPath}'`; await execAsync(chmodCommand); } return { content: [ { type: "text", text: JSON.stringify({ success: true, scriptPath: scriptPath, executable: executable, wslDistribution: this.wslDistribution, message: "Script created successfully", timestamp: new Date().toISOString() }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ success: false, scriptPath: scriptPath, wslDistribution: this.wslDistribution, error: error.message, timestamp: new Date().toISOString() }, null, 2), }, ], }; } }
  • The input schema definition for the 'create_bash_script' tool, specifying required parameters (scriptPath, content) and optional executable flag.
    inputSchema: { type: "object", properties: { scriptPath: { type: "string", description: "Path where to create the script file", }, content: { type: "string", description: "Content of the bash script", }, executable: { type: "boolean", description: "Make the script executable (optional, defaults to true)", default: true } }, required: ["scriptPath", "content"], },
  • src/index.js:214-236 (registration)
    The tool registration entry in the ListTools response, including name, description, and input schema.
    { name: "create_bash_script", description: "Create a bash script file with specified content", inputSchema: { type: "object", properties: { scriptPath: { type: "string", description: "Path where to create the script file", }, content: { type: "string", description: "Content of the bash script", }, executable: { type: "boolean", description: "Make the script executable (optional, defaults to true)", default: true } }, required: ["scriptPath", "content"], }, },
  • src/index.js:286-287 (registration)
    The dispatch case in the CallToolRequestHandler switch statement that routes calls to the createBashScript handler.
    case "create_bash_script": return await this.createBashScript(args);

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