Skip to main content
Glama
andresthor

Command-Line MCP Server

by andresthor

execute_command

Execute Unix/macOS terminal commands through a controlled interface with security features for AI assistants.

Instructions

Execute a Unix/macOS terminal command.

Args: command: The command to execute session_id: Optional session ID for permission management

Returns: A dictionary with command output and status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes
session_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The internal method `_execute_command` that validates and executes the command.
    async def _execute_command(
        self,
        command: str,
        command_type: str | None = None,
        session_id: str | None = None,
    ) -> dict[str, Any]:
        """Execute a Unix/macOS terminal command.
    
        Args:
            command: The command to execute
            command_type: Optional type of command (read, write, system)
            session_id: Optional session ID for permission management
    
        Returns:
            A dictionary with command output and status
        """
        # Get the latest command lists and separator settings
        command_lists = self.config.get_effective_command_lists()
        allow_separators = self.config.get("security", "allow_command_separators", True)
    
        # Validate the command
        validation = validate_command(
            command,
            command_lists["read"],
            command_lists["write"],
            command_lists["system"],
            command_lists["blocked"],
            command_lists["dangerous_patterns"],
            allow_command_separators=allow_separators,
        )
    
        if not validation["is_valid"]:
            return {
                "success": False,
                "output": "",
                "error": validation["error"],
            }
  • The MCP tool registration for `execute_command`, which acts as a wrapper for the internal `_execute_command` method.
    async def execute_command(
        command: str, session_id: str | None = None
    ) -> dict[str, Any]:
        """
        Execute a Unix/macOS terminal command.
    
        Args:
            command: The command to execute
            session_id: Optional session ID for permission management
    
        Returns:
            A dictionary with command output and status
        """
        # For Claude Desktop compatibility, use the fixed session ID
        require_session_id = self.config.get(
            "security", "require_session_id", False
        )
        if not session_id or not require_session_id:
            session_id = self.claude_desktop_session_id
            logger.info(f"Using persistent Claude Desktop session: {session_id}")
    
        return await self._execute_command(command, session_id=session_id)
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. It states the tool executes commands and returns output with status, but lacks critical details like security implications (e.g., destructive commands), permission requirements, error handling, or rate limits. This is inadequate for a tool that could 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.

Conciseness4/5

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

The description is front-loaded with the core purpose, followed by structured Arg and Return sections. It's efficient with minimal waste, though the Arg/Return formatting could be more integrated. Every sentence adds value, but slight improvements in flow could achieve a perfect score.

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

Completeness3/5

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

Given the tool's high complexity (executing arbitrary commands), no annotations, and an output schema (which covers return values), the description is minimally adequate. It explains the basic operation and parameters but lacks safety warnings, sibling differentiation, and detailed behavioral context, making it incomplete 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?

Schema description coverage is 0%, so the description must compensate. It adds basic semantics for both parameters: 'command' as 'The command to execute' and 'session_id' as 'Optional session ID for permission management.' However, it doesn't provide examples, format details, or constraints beyond what's implied, leaving gaps in understanding.

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 tool's purpose as 'Execute a Unix/macOS terminal command,' which is a specific verb+resource combination. However, it doesn't explicitly distinguish this from sibling tools like 'execute_read_command' or 'list_available_commands,' which would be needed for a score of 5.

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 'execute_read_command' or 'approve_command_type.' It mentions 'session_id' for 'permission management' but doesn't explain when this is required or optional, leaving usage context unclear.

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/andresthor/cmd-line-mcp'

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