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

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)

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