Skip to main content
Glama

execute_command

Execute Unix/macOS terminal commands through a secure MCP server with controlled access and permission management.

Instructions

Execute a Unix/macOS terminal command.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesThe command to execute
session_idNoOptional session ID for permission management

Implementation Reference

  • Core handler implementation for executing commands.
    async _executeCommand(command, { commandType = null, sessionId = null } = {}) {
      const lists = this.config.getEffectiveCommandLists();
      const allowSeparators = this.config.get('security', 'allow_command_separators', true);
    
      const validation = validateCommand(
        command, lists.read, lists.write, lists.system,
        lists.blocked, lists.dangerous_patterns,
        allowSeparators,
      );
    
      if (!validation.is_valid) return { success: false, output: '', error: validation.error };
    
      if (commandType && validation.command_type !== commandType) {
        return { success: false, output: '', error: `Command type mismatch. Expected ${commandType}, got ${validation.command_type}` };
      }
    
      const actualType = validation.command_type;
    
      // Directory check
      const dirCheck = this._checkDirectoryAccess(command, sessionId);
      if (!dirCheck.allowed) return dirCheck.response;
    
      // Permission check for write/system
      if (actualType !== 'read' && this.config.get('security', 'allow_user_confirmation', true)) {
        const requireSessionId = this.config.get('security', 'require_session_id', false);
        if (sessionId && requireSessionId) {
          const hasApproval =
            this.sessionManager.hasCommandApproval(sessionId, command) ||
            this.sessionManager.hasCommandTypeApproval(sessionId, actualType);
          if (!hasApproval) {
            return {
              success: false,
              output: '',
              error: `Command '${command}' requires approval. Use approve_command_type tool with session_id '${sessionId}'.`,
              requires_approval: true,
              command_type: actualType,
              session_id: sessionId,
            };
          }
        }
        // no session or session validation disabled — auto-approve
      }
    
      // Execute the command
      try {
        logger.info(`Executing command: ${command}`);
        const maxOutputSize = this.config.get('output', 'max_size', 100 * 1024);
    
        const { stdout, stderr, code } = await new Promise((resolve) => {
          const child = exec(command, { shell: '/bin/sh' }, (err, stdout, stderr) => {
            resolve({ stdout: stdout || '', stderr: stderr || '', code: err ? (err.exitCode ?? 1) : 0 });
          });
        });
    
        let output = stdout;
        if (output.length > maxOutputSize) {
          output = output.slice(0, maxOutputSize) + '\n... [output truncated due to size]';
        }
    
        return {
          success: code === 0,
          output,
          error: stderr,
          exit_code: code,
          command_type: actualType,
        };
      } catch (e) {
        logger.error(`Error executing command: ${e.message}`);
        return { success: false, output: '', error: e.message };
      }
    }
  • src/server.js:71-84 (registration)
    Registration of the execute_command tool in the MCP server.
    this.server.tool(
      'execute_command',
      'Execute a Unix/macOS terminal command.',
      {
        command: z.string().describe('The command to execute'),
        session_id: z.string().optional().describe('Optional session ID for permission management'),
      },
      async ({ command, session_id }) => {
        const requireSessionId = this.config.get('security', 'require_session_id', false);
        const sid = (!session_id || !requireSessionId) ? this.claudeDesktopSessionId : session_id;
        const result = await this._executeCommand(command, { sessionId: sid });
        return { content: [{ type: 'text', text: JSON.stringify(result) }] };
      },
    );
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 but only specifies the target platform (Unix/macOS). It omits critical information: whether execution is sandboxed, destructive capabilities, error handling behavior, or that the session_id parameter relates to permission management (though the schema covers this).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The single-sentence description is efficiently structured with no redundancy, but for a high-risk tool capable of arbitrary system modification, this brevity represents under-specification rather than effective conciseness.

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 high complexity and risk of arbitrary command execution, combined with absent annotations and no output schema, the description is dangerously incomplete. It lacks safety warnings, return value documentation, and clarification of destructive capabilities that are essential for agent decision-making.

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 'command' and 'session_id' adequately documented in the input schema. The tool description adds no additional parameter context, meeting the baseline expectation when the schema is comprehensive.

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 ('Unix/macOS terminal command'), providing specific platform context. However, it fails to distinguish from sibling tool 'execute_read_command', leaving ambiguity about whether this tool performs write operations or general execution.

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 provided on when to use this tool versus 'execute_read_command' or other siblings. Given the high-risk nature of arbitrary command execution, the absence of prerequisites, safety warnings, or selection criteria is a significant gap.

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/wwqdrh/MCPcmd'

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