Skip to main content
Glama

bash

Execute shell commands directly from Claude Code MCP to perform system operations, manage files, and run scripts within the development environment.

Instructions

Execute a shell command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe shell command to execute
timeoutNoOptional timeout in milliseconds (max 600000)

Implementation Reference

  • The handler function for the bash tool. It checks for banned commands, calls executeCommand helper, formats response, and handles errors.
    async ({ command, timeout }) => {
      try {
        // Check for banned commands
        const bannedCommands = [
          'alias', 'curl', 'curlie', 'wget', 'axel', 'aria2c', 'nc', 'telnet',
          'lynx', 'w3m', 'links', 'httpie', 'xh', 'http-prompt', 'chrome', 'firefox', 'safari'
        ];
        
        const commandParts = command.split(' ');
        if (bannedCommands.includes(commandParts[0])) {
          return {
            content: [{ 
              type: "text", 
              text: `Error: The command '${commandParts[0]}' is not allowed for security reasons.`
            }],
            isError: true
          };
        }
        
        const result = await executeCommand(command, timeout);
        return {
          content: [{ type: "text", text: result }]
        };
      } catch (error) {
        return {
          content: [{ 
            type: "text", 
            text: error instanceof Error ? error.message : String(error)
          }],
          isError: true
        };
      }
    }
  • Input schema for the bash tool using Zod: command (string) and optional timeout (number).
    {
      command: z.string().describe("The shell command to execute"),
      timeout: z.number().optional().describe("Optional timeout in milliseconds (max 600000)")
    },
  • Registration of the bash tool on the MCP server using server.tool().
    server.tool(
      "bash",
      "Execute a shell command",
      {
        command: z.string().describe("The shell command to execute"),
        timeout: z.number().optional().describe("Optional timeout in milliseconds (max 600000)")
      },
      async ({ command, timeout }) => {
        try {
          // Check for banned commands
          const bannedCommands = [
            'alias', 'curl', 'curlie', 'wget', 'axel', 'aria2c', 'nc', 'telnet',
            'lynx', 'w3m', 'links', 'httpie', 'xh', 'http-prompt', 'chrome', 'firefox', 'safari'
          ];
          
          const commandParts = command.split(' ');
          if (bannedCommands.includes(commandParts[0])) {
            return {
              content: [{ 
                type: "text", 
                text: `Error: The command '${commandParts[0]}' is not allowed for security reasons.`
              }],
              isError: true
            };
          }
          
          const result = await executeCommand(command, timeout);
          return {
            content: [{ type: "text", text: result }]
          };
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: error instanceof Error ? error.message : String(error)
            }],
            isError: true
          };
        }
      }
    );
  • Helper function that executes the shell command using Node's child_process.exec.
    export async function executeCommand(command: string, timeout?: number): Promise<string> {
      try {
        const options = timeout ? { timeout } : {};
        const { stdout, stderr } = await execPromise(command, options);
        if (stderr) {
          console.error(`Command stderr: ${stderr}`);
        }
        return stdout;
      } catch (error) {
        console.error(`Error executing command: ${command}`, error);
        throw error;
      }
    }
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. 'Execute a shell command' implies a potentially powerful and risky operation, but the description doesn't mention security implications, permission requirements, side effects, or what happens on timeout. This is a significant gap for a tool that can perform arbitrary system operations.

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 extremely concise at just three words, with zero wasted language. It's front-loaded with the essential purpose and doesn't include any unnecessary elaboration, making it efficient for quick understanding.

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 tool that executes arbitrary shell commands with no annotations and no output schema, the description is inadequate. It doesn't address the significant behavioral complexity, security implications, or what the tool returns. Given the power and risk of this operation, more context is needed for safe and effective 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 description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any additional meaning beyond what's in the schema - it doesn't explain command syntax, shell environment, or timeout behavior. This meets the baseline for high schema coverage.

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 'Execute a shell command' clearly states the verb ('execute') and resource ('shell command'), making the purpose immediately understandable. However, it doesn't distinguish this tool from potential sibling tools that might also execute commands or interact with the shell environment, 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 like 'editFile' or 'listFiles'. There's no mention of prerequisites, safety considerations, or typical use cases, leaving the agent with minimal context for appropriate tool selection.

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/auchenberg/claude-code-mcp'

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