terminal_input
Send text or keyboard commands to terminal sessions to control TUI applications through simulated input for automated interaction.
Instructions
Send input to a terminal session
Args: session_id: ID of the terminal session input_text: Text to type (for alphanumeric input) key: Special key to send (Return, Tab, Escape, etc.)
Returns: Dictionary with status and input confirmation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| input_text | No | ||
| key | No |
Implementation Reference
- src/terminal_control_mcp/server.py:57-94 (handler)Handler function for the 'terminal_input' tool. Decorated with @mcp.tool() for automatic registration. Handles sending text input or special keys to a specific terminal session, with error handling for missing sessions.@mcp.tool() async def terminal_input( session_id: str, input_text: Optional[str] = None, key: Optional[str] = None ) -> Dict[str, Any]: """Send input to a terminal session Args: session_id: ID of the terminal session input_text: Text to type (for alphanumeric input) key: Special key to send (Return, Tab, Escape, etc.) Returns: Dictionary with status and input confirmation """ if session_id not in sessions: return {"status": "error", "error": f"Session {session_id} not found"} session = sessions[session_id] try: if input_text is not None: await session.send_text(input_text) action = f"typed text: {input_text}" elif key is not None: await session.send_key(key) action = f"sent key: {key}" else: return { "status": "error", "error": "Must provide either input_text or key", } logger.info(f"Session {session_id}: {action}") return {"session_id": session_id, "status": "sent", "action": action} except Exception as e: logger.error(f"Failed to send input to session {session_id}: {e}") return {"status": "error", "error": str(e)}