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
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | ||
| session_id | No |
Implementation Reference
- src/cmd_line_mcp/server.py:648-685 (handler)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"], } - src/cmd_line_mcp/server.py:152-173 (registration)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)