A Model Context Protocol (MCP) server that enables secure terminal command execution, directory navigation, and file system operations through a standardized interface.
- Command Execution: Run terminal commands with timeout controls and comprehensive output capture
- Directory Management: Navigate and list directory contents with intuitive formatting
- Security Measures: Built-in safeguards against dangerous commands and operations
- Command History: Track and display recent command executions
- Cross-Platform Support: Works on both Windows and UNIX-based systems
- File Operations: Read, write, update, insert, and delete file content with row-level precision
To install Terminal Controller for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @GongRzhe/terminal-controller-mcp --client claude
- Python 3.11+
- An MCP-compatible client (such as Claude Desktop)
- UV/UVX installed (optional, for UVX method)
Install the package directly from PyPI:
pip install terminal-controller
Or if you prefer to use UV:
uv pip install terminal-controller
If you prefer to install from source:
-
Clone this repository:
git clone https://github.com/GongRzhe/terminal-controller-mcp.git cd terminal-controller-mcp
-
Run the setup script:
python setup_mcp.py
There are two ways to configure Claude Desktop to use Terminal Controller:
Add this to your Claude Desktop configuration file:
"terminal-controller": {
"command": "uvx",
"args": ["terminal_controller"]
}
"terminal-controller": {
"command": "python",
"args": ["-m", "terminal_controller"]
}
The configuration path varies by operating system:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
For Cursor, use similar configuration settings as Claude Desktop.
For other clients, refer to their documentation on how to configure external MCP servers.
Once configured, you can use natural language to interact with your terminal through your MCP client:
- "Run the command
ls -la
in the current directory" - "Navigate to my Documents folder"
- "Show me the contents of my Downloads directory"
- "Show me my recent command history"
- "Read the content of config.json"
- "Update line 5 in my script.py file with 'print("Hello World")'"
- "Delete lines 10-15 from the log file"
- "Insert a new line at the beginning of my text file"
Terminal Controller exposes the following MCP tools:
Execute a terminal command and return its results.
Parameters:
command
: The command line command to executetimeout
: Command timeout in seconds (default: 30)
Returns:
- Output of the command execution, including stdout, stderr, and execution status
Get recent command execution history.
Parameters:
count
: Number of recent commands to return (default: 10)
Returns:
- Formatted command history record
Get the current working directory.
Returns:
- Path of current working directory
Change the current working directory.
Parameters:
path
: Directory path to switch to
Returns:
- Operation result information
List files and subdirectories in the specified directory.
Parameters:
path
: Directory path to list contents (default: current directory)
Returns:
- List of directory contents, formatted with icons for directories and files
Write content to a file with overwrite or append options.
Parameters:
path
: Path to the filecontent
: Content to writemode
: Write mode ('overwrite' or 'append', default: 'overwrite')
Returns:
- Operation result information including verification of successful write
Read content from a file with optional row selection.
Parameters:
path
: Path to the filestart_row
: Starting row to read from (0-based, optional)end_row
: Ending row to read to (0-based, inclusive, optional)
Returns:
- File content or selected lines
Insert content at specific row(s) in a file.
Parameters:
path
: Path to the filecontent
: Content to insertrow
: Row number to insert at (0-based, optional)rows
: List of row numbers to insert at (0-based, optional)
Returns:
- Operation result information
Delete content at specific row(s) from a file.
Parameters:
path
: Path to the filerow
: Row number to delete (0-based, optional)rows
: List of row numbers to delete (0-based, optional)
Returns:
- Operation result information
Update content at specific row(s) in a file.
Parameters:
path
: Path to the filecontent
: New content to place at the specified row(s)row
: Row number to update (0-based, optional)rows
: List of row numbers to update (0-based, optional)
Returns:
- Operation result information
Terminal Controller implements several security measures:
- Timeout controls to prevent long-running commands
- Blacklisting of dangerous commands (rm -rf /, format, mkfs)
- Proper error handling and isolation of command execution
- Access only to the commands and directories specifically granted
- Only commands that complete within the timeout period will return results
- By default, the server has access to the same file system permissions as the user running it
- Some interactive commands may not work as expected due to the non-interactive nature of the terminal interface
If you encounter issues:
- Check that your Python version is 3.11 or higher
- Verify that your Claude Desktop configuration is correct
- Try running the terminal controller directly to check for errors:
python -m terminal_controller
- For UVX-related issues, try:
uvx terminal_controller
- Review your MCP client's logs for connection errors
Contributions are welcome! Please feel free to submit a Pull Request.
MIT