Skip to main content

A Model Context Protocol (MCP) server for secure terminal command execution and file system operations

Project description

Terminal Controller for MCP

A Model Context Protocol (MCP) server that enables secure terminal command execution, directory navigation, and file system operations through a standardized interface.

Features

  • 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

How It Works

Terminal Controller implements the Model Context Protocol (MCP) to provide a secure interface between LLMs and your terminal. It exposes several tools that allow models to:

  1. Execute terminal commands with proper error handling and timeout controls
  2. Navigate through directories while maintaining proper access controls
  3. List contents of directories with clear visual formatting
  4. Track command history for reference and auditing

Installation

Prerequisites

  • Python 3.10+
  • MCP-compatible client (such as Claude Desktop)

Automated Setup (Recommended)

The easiest way to set up Terminal Controller is using the provided setup script:

  1. Clone this repository:

    git clone https://github.com/GongRzhe/terminal-controller-mcp.git
    cd terminal-controller-mcp
    
  2. Run the setup script:

    python setup_mcp.py
    

This script will:

  • Create a Python virtual environment (.venv) if it doesn't exist
  • Install all required dependencies from requirements.txt
  • Generate the MCP configuration file with correct paths
  • Display configuration instructions for various MCP clients

Manual Setup (Alternative)

If you prefer to set up manually:

  1. Clone this repository:

    git clone https://github.com/GongRzhe/terminal-controller-mcp.git
    cd terminal-controller-mcp
    
  2. Create a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Configure your MCP client to use the server. For Claude Desktop, add this to your claude_desktop_config.json:

    "terminal-controller": {
      "command": "/path/to/terminal-controller/.venv/bin/python", # "/path/to/terminal-controller/.venv/Scripts/python"
      "args": [
        "/path/to/terminal-controller/terminal_controller.py"
      ],
      "env": {
        "PYTHONPATH": "/path/to/terminal-controller"
      }
    }
    

Client Configuration

Claude Desktop

The configuration path varies by operating system:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Cursor

For Cursor, use the path displayed after running the setup script.

Other MCP Clients

For other clients, refer to their documentation on how to configure external MCP servers.

Usage

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"

API Reference

Terminal Controller exposes the following MCP tools:

execute_command

Execute a terminal command and return its results.

Parameters:

  • command: The command line command to execute
  • timeout: Command timeout in seconds (default: 30)

Returns:

  • Output of the command execution, including stdout, stderr, and execution status

get_command_history

Get recent command execution history.

Parameters:

  • count: Number of recent commands to return (default: 10)

Returns:

  • Formatted command history record

get_current_directory

Get the current working directory.

Returns:

  • Path of current working directory

change_directory

Change the current working directory.

Parameters:

  • path: Directory path to switch to

Returns:

  • Operation result information

list_directory

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

Security Considerations

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

Limitations

  • 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

Troubleshooting

If you encounter issues:

  1. Check that your Python version is 3.10 or higher
  2. Verify that the paths in your configuration file are correct and absolute
  3. Make sure the virtual environment is properly activated when installing dependencies
  4. Review your MCP client's logs for connection errors

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terminal_controller-0.1.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

terminal_controller-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file terminal_controller-0.1.1.tar.gz.

File metadata

  • Download URL: terminal_controller-0.1.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for terminal_controller-0.1.1.tar.gz
Algorithm Hash digest
SHA256 64c39e7889db12a8a2a44425f12e9b171c0545d09b13f556386723a5d466edef
MD5 9b6f90bf5e5b7ba8edd69fe555684353
BLAKE2b-256 1788bcb143bc9e848a72f7725cdb0c93f64235450ad3bd44863a07e1e0296048

See more details on using hashes here.

File details

Details for the file terminal_controller-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for terminal_controller-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3d6ed9f24a3796956be5cc258c9e1afd89aeeaa5c38a2f406d3d445d4b54ee2
MD5 2cec816cfdbd161a2994308bfb971d04
BLAKE2b-256 b70bc1e209a2ed08aeac528e03b43268b01cf7076dbf842a2489f484dbe8a18c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page