Skip to main content
Glama
cfdude

Mac Shell MCP Server

execute_command

Execute macOS terminal commands securely with built-in whitelisting and approval mechanisms for controlled shell operations.

Instructions

Execute a shell command on macOS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe command to execute
argsNoCommand arguments

Implementation Reference

  • MCP tool handler for 'execute_command': validates input with Zod, delegates to CommandService.executeCommand, formats stdout/stderr response or error.
    private async handleExecuteCommand(args: unknown) {
      const schema = z.object({
        command: z.string(),
        args: z.array(z.string()).optional(),
      });
    
      const { command, args: commandArgs = [] } = schema.parse(args);
    
      try {
        const result = await this.commandService.executeCommand(command, commandArgs);
    
        return {
          content: [
            {
              type: 'text',
              text: result.stdout,
            },
            {
              type: 'text',
              text: result.stderr ? `Error output: ${result.stderr}` : '',
            },
          ],
        };
      } catch (error) {
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `Command execution failed: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • Input schema definition for 'execute_command' tool as provided in ListTools response.
    inputSchema: {
      type: 'object',
      properties: {
        command: {
          type: 'string',
          description: 'The command to execute',
        },
        args: {
          type: 'array',
          items: {
            type: 'string',
          },
          description: 'Command arguments',
        },
      },
      required: ['command'],
    },
  • src/index.ts:90-110 (registration)
    Registration of 'execute_command' tool in the ListTools handler, including name, description, and schema.
    {
      name: 'execute_command',
      description: 'Execute a shell command on macOS',
      inputSchema: {
        type: 'object',
        properties: {
          command: {
            type: 'string',
            description: 'The command to execute',
          },
          args: {
            type: 'array',
            items: {
              type: 'string',
            },
            description: 'Command arguments',
          },
        },
        required: ['command'],
      },
    },
  • Core helper method implementing command execution logic: whitelist validation, approval queuing for risky commands, direct execution for safe ones using child_process.execFile.
    public async executeCommand(
      command: string,
      args: string[] = [],
      options: {
        timeout?: number;
        requestedBy?: string;
      } = {},
    ): Promise<CommandResult> {
      const securityLevel = this.validateCommand(command, args);
    
      // If command is not whitelisted, reject
      if (securityLevel === null) {
        throw new Error(`Command not whitelisted: ${command}`);
      }
    
      // If command is forbidden, reject
      if (securityLevel === CommandSecurityLevel.FORBIDDEN) {
        throw new Error(`Command is forbidden: ${command}`);
      }
    
      // If command requires approval, add to pending queue
      if (securityLevel === CommandSecurityLevel.REQUIRES_APPROVAL) {
        return this.queueCommandForApproval(command, args, options.requestedBy);
      }
    
      // For safe commands, execute immediately
      try {
        const timeout = options.timeout || this.defaultTimeout;
        const { stdout, stderr } = await execFileAsync(command, args, {
          timeout,
          shell: this.shell,
        });
    
        return { stdout, stderr };
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Command execution failed: ${error.message}`);
        }
        throw error;
      }
    }
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 critical behavioral aspects: whether execution is immediate or requires approval, what permissions are needed, whether commands run with elevated privileges, what happens on failure, or what output format to expect. For a potentially dangerous shell execution tool, this is inadequate transparency.

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 communicates the core functionality without unnecessary words. It's appropriately sized for a tool with two parameters and gets straight to the point. Every word earns its place, making it easy to parse quickly.

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 shell command execution (potentially destructive, security-sensitive) and the absence of both annotations and output schema, the description is insufficiently complete. It doesn't address safety considerations, error handling, output format, or how this interacts with the security-focused sibling tools. For a tool that could modify system state, more contextual information is needed.

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%, with both parameters ('command' and 'args') clearly documented in the schema. The description doesn't add any parameter-specific information beyond what the schema already provides. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even without additional param details in 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 action ('Execute') and target ('a shell command on macOS'), making the purpose immediately understandable. It distinguishes from siblings by focusing on command execution rather than security management or querying. However, it doesn't specify whether this executes immediately or requires approval, which could be more precise.

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?

No guidance is provided about when to use this tool versus alternatives like 'approve_command' or 'deny_command'. The description doesn't mention prerequisites, security implications, or whether this bypasses approval workflows. With siblings focused on security controls, this omission leaves significant ambiguity about appropriate usage contexts.

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/cfdude/mac-shell-mcp'

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