Skip to main content
Glama
FutureAtoms

Agentic Control Framework (ACF)

by FutureAtoms

execute_command

Runs a command in a specified shell with optional timeout, enabling terminal control for automation and task execution.

Instructions

Execute command

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes
shellNo
timeout_msNo

Implementation Reference

  • The main handler function for execute_command. It supports both one-shot command execution (waiting for completion) and long-running session-based execution. It checks blocked commands, resolves the shell, executes via execa, and returns structured results including stdout, stderr, exit code, and session info for async commands.
    async function executeCommand(command, options = {}) {
      try {
        // Check for blocked commands
        if (isCommandBlocked(command)) {
          return {
            success: false,
            message: `Command blocked for security reasons: ${command}`,
            blockedCommand: true
          };
        }
    
        const shell = options.shell || config.defaultShell;
        const timeout = options.timeout_ms ? parseInt(options.timeout_ms, 10) : config.commandTimeout;
        const waitForCompletion = options.waitForCompletion !== false; // Default to true
    
        // For simple commands, wait for completion
        if (waitForCompletion) {
          try {
            const { shellCmd, shellArgs } = getShellCommand(shell, command);
            const result = await execa(shellCmd, shellArgs, {
              timeout,
              reject: false
            });
    
            const output = result.stdout || '';
            const error = result.stderr || '';
            const success = result.exitCode === 0;
    
            return {
              success,
              content: output || error || (success ? 'Command completed successfully' : 'Command failed'),
              command,
              shell,
              exitCode: result.exitCode,
              stdout: output,
              stderr: error,
              message: success ? 'Command completed successfully' : `Command failed with exit code ${result.exitCode}`
            };
          } catch (error) {
            if (error.code === 'ETIMEDOUT') {
              return {
                success: false,
                message: `Command timed out after ${timeout}ms`,
                command,
                content: 'Command timed out'
              };
            }
            throw error;
          }
        }
    
        // For long-running commands, return session info
        const sessionId = ++sessionCounter;
        const session = {
          id: sessionId,
          command,
          shell,
          startTime: Date.now(),
          output: [],
          error: [],
          status: 'running'
        };
    
        sessions.set(sessionId, session);
    
        // Execute the command
        const { shellCmd, shellArgs } = getShellCommand(shell, command);
        const subprocess = execa(shellCmd, shellArgs, {
          timeout,
          buffer: false,
          reject: false,
          stdio: ['ignore', 'pipe', 'pipe']
        });
    
        session.subprocess = subprocess;
        session.pid = subprocess.pid;
    
        // Collect output
        subprocess.stdout.on('data', (data) => {
          session.output.push(data.toString());
        });
    
        subprocess.stderr.on('data', (data) => {
          session.error.push(data.toString());
        });
    
        // Handle completion
        subprocess.then((result) => {
          session.status = result.failed ? 'failed' : 'completed';
          session.exitCode = result.exitCode;
          session.endTime = Date.now();
        }).catch((error) => {
          session.status = 'error';
          session.errorMessage = error.message;
          session.endTime = Date.now();
        });
    
        // Return initial response for session-based execution
        return {
          success: true,
          pid: session.pid,
          sessionId,
          command,
          shell,
          status: session.status,
          message: `Command started with PID ${session.pid}`,
          content: `Command started with PID ${session.pid}`
        };
    
      } catch (error) {
        logger.error(`Error executing command: ${error.message}`);
        return {
          success: false,
          message: error.message,
          content: error.message
        };
      }
    }
  • Tool schema registration in the tools/list response, defining name 'execute_command', description, and inputSchema with required 'command' property and optional 'shell' and 'timeout_ms'.
    { name:'execute_command', description:'Execute command', inputSchema:{ type:'object', properties:{ command:{type:'string'}, shell:{type:'string'}, timeout_ms:{type:'number'} }, required:['command'] } },
  • The tools/call dispatch case for 'execute_command' in the MCP server, which extracts the command and options (shell, timeout_ms, waitForCompletion) and delegates to terminalTools.executeCommand().
    case 'execute_command': {
      const wait = (typeof args.waitForCompletion === 'boolean') ? args.waitForCompletion : true;
      const r = await terminalTools.executeCommand(args.command, { shell: args.shell, timeout_ms: args.timeout_ms, waitForCompletion: wait });
      data = (r && r.success !== undefined) ? r : { success: true, ...r };
      break;
    }
  • Helper function isCommandBlocked that checks if a command contains blocked keywords from the BLOCKED_COMMANDS env or config.
    function isCommandBlocked(command) {
      const lowerCommand = command.toLowerCase().trim();
      return config.blockedCommands.some(blocked => 
        lowerCommand.includes(blocked.toLowerCase())
      );
    }
  • Helper function getShellCommand that builds the platform-specific shell command and arguments for executing a command string.
    // Helper to build shell command per platform
    function getShellCommand(shell, command) {
      const isWin = process.platform === 'win32';
      const sh = (shell || '').toLowerCase();
      if (isWin) {
        if (sh.includes('powershell')) {
          return { shellCmd: shell, shellArgs: ['-NoProfile', '-Command', command] };
        }
        if (sh.includes('cmd')) {
          return { shellCmd: shell, shellArgs: ['/c', command] };
        }
        if (sh.includes('bash')) {
          return { shellCmd: shell, shellArgs: ['-c', command] };
        }
        // Fallback to powershell
        return { shellCmd: 'powershell.exe', shellArgs: ['-NoProfile', '-Command', command] };
      }
      // POSIX shells
      return { shellCmd: shell || '/bin/bash', shellArgs: ['-c', command] };
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It fails to disclose any behavioral traits such as whether the command runs synchronously, returns output, or requires specific permissions. The description gives no insight into side effects or safety.

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

Conciseness2/5

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

While extremely short (two words), the description is under-specified rather than concise. It lacks essential context that an agent needs, making it ineffective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters, no output schema, and no annotations, the description is completely inadequate. It fails to explain what the tool does, how to use it, or what to expect.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning the schema has no descriptions for the parameters. The description adds no meaning to 'command', 'shell', or 'timeout_ms', leaving the agent without understanding their purpose or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute command' is a tautology that merely restates the tool name. It does not specify what kind of command, the context, or how it differentiates from sibling tools like 'execute_command' or similar tool names in the list.

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 (e.g., other execution tools or shell-related operations). No mention of prerequisites or exclusions.

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/FutureAtoms/agentic-control-framework'

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