Provides capabilities to control terminal-based applications on CentOS systems through a virtual X11 display, supporting input simulation and screenshot capture.
Enables interaction with terminal-based applications on Debian systems through virtual display management, input simulation, and screenshot capture capabilities.
Supports controlling terminal applications on Fedora systems using virtual X11 display, allowing for keyboard input simulation and visual output capture.
Enables AI agents to interact with the htop process monitoring tool, including launching htop sessions, navigating through the interface, using search functionality, and capturing visual output as PNG screenshots.
Allows AI agents to interact with terminal-based applications on Ubuntu systems through virtual display management, input simulation, and screenshot capture.
Terminal Control MCP
A Model Context Protocol (MCP) server that enables AI agents to interact with terminal-based TUI applications through a virtual X11 display approach.
Overview
This project provides a comprehensive solution for controlling terminal applications programmatically using:
- Xvfb for headless virtual X11 display
- xterm for terminal emulation
- xdotool for input simulation and window management
- ImageMagick for PNG screenshot capture
The system captures actual visual terminal output as PNG screenshots, making it ideal for AI agents that need to see and interact with terminal applications.
Features
- Virtual Display Management: Headless X11 display using Xvfb
- Input Simulation: Send keyboard input and text to terminal applications
- Screenshot Capture: Take PNG screenshots of terminal output
- Window Management: Reliable window detection and focus handling
- Resource Cleanup: Proper process management with timeout handling
System Requirements
The following system packages must be installed:
Installation
This project uses the uv
package manager:
Quick Start
Running the Example
Try the included htop example to see the system in action:
This will:
- Launch htop in a virtual xterm session
- Press F3 to open the search dialog
- Type "python" as a search term
- Capture PNG screenshots at each step
- Clean up all processes
Basic Usage
Architecture
Core Components
- XTermSession Class: The main interface for terminal control
- Manages Xvfb virtual display lifecycle
- Spawns and controls xterm processes
- Handles input simulation via xdotool
- Captures screenshots using ImageMagick
- Virtual Display Approach: Unlike direct TTY manipulation, this system:
- Creates a real X11 environment with Xvfb
- Launches actual xterm instances
- Captures genuine visual output as PNG files
- Provides reliable input simulation
Key Methods
start_virtual_display()
: Initialize Xvfb virtual displaystart_xterm(command)
: Launch xterm with specified commandsend_key(key)
: Send special keys (F1, Escape, etc.)send_text(text)
: Send alphanumeric text inputtake_screenshot(filename)
: Capture PNG screenshotcleanup()
: Properly terminate all processes
Development
Project Structure
Development Commands
MCP Server Implementation (Planned)
The full MCP server will provide these tools:
terminal_launch
: Start a new terminal sessionterminal_input
: Send keyboard/text inputterminal_capture
: Take PNG screenshotterminal_close
: Clean up terminal session
Technical Details
Window Detection
The system uses multiple fallback strategies for reliable window ID detection:
Screenshot Capture
Uses ImageMagick's import
command for reliable PNG capture:
Resource Management
Implements proper cleanup with timeout handling:
Contributing
[TBD]
This server cannot be installed
Enables AI agents to interact with terminal-based TUI applications by capturing visual terminal output as PNG screenshots and simulating keyboard input through a virtual X11 display.
Related MCP Servers
- AsecurityAlicenseAqualityAllows AI assistants to seamlessly interact with Terminal.shop to browse products, manage shopping carts, place orders, and handle subscriptions through Terminal.shop's API.Last updated -192481JavaScriptMIT License
- AsecurityFlicenseAqualityEnables AI tools to capture and process screenshots of a user's screen, allowing AI assistants to see and analyze what the user is looking at through a simple MCP interface.Last updated -112Python
- -securityAlicense-qualityAllows AI assistants to safely execute common Unix/macOS terminal commands through a controlled interface with comprehensive security features.Last updated -4PythonMIT License
- -securityFlicense-qualityEnables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.Last updated -TypeScript