Skip to main content
Glama
gunjanjp

Linux Bash MCP Server

by gunjanjp

create_bash_script

Generate and save a bash script file with custom content, specifying the path and optionally making it executable. Ideal for automating tasks in Linux environments via the Linux Bash MCP Server.

Instructions

Create a bash script file with specified content

Input Schema

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

Implementation Reference

  • The handler function that implements the create_bash_script tool. It writes the provided content to the specified scriptPath in the WSL Linux environment and optionally makes it executable using chmod.
    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), }, ], }; } }
  • src/index.js:214-236 (registration)
    Registration of the create_bash_script tool in the list of tools, including its 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"], }, },
  • Input schema definition for the create_bash_script tool.
    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"],
  • Dispatch to the createBashScript handler in the tool request switch statement.
    case "create_bash_script": return await this.createBashScript(args);

Other Tools

Related 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