terminal_mcp_server

thepeacefulprogrammer/terminal_mcp_server

3.2

If you are the rightful owner of terminal_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Terminal MCP Server is a comprehensive Model Context Protocol server that provides full terminal and system access capabilities to AI agents, enabling them to perform a wide range of development and system administration tasks autonomously.

Tools
5
Resources
0
Prompts
0

Terminal MCP Server

A comprehensive Model Context Protocol (MCP) server that provides full terminal and system access capabilities to AI agents. This server enables AI Coding Agents to execute any command-line operations, manage processes, execute Python scripts, and perform system-level tasks through a secure and robust MCP interface.

šŸŽÆ Project Vision

Transform AI agents into autonomous developers by providing complete terminal access equivalent to what a human developer would have. This server bridges the gap between AI reasoning and system-level operations, enabling:

  • Autonomous Development: AI agents can compile, test, debug, and deploy code
  • System Administration: Full access to Linux command-line operations
  • Process Management: Background process lifecycle management
  • Python Integration: Script execution with virtual environment support
  • Real-time Feedback: Streaming command outputs for immediate decision making
  • Project-Aware Execution: Commands execute from project directory with intelligent working directory detection

āœ… Current Features (Production Ready)

18 Fully Implemented MCP Tools

Command Execution
  • āœ… execute_command - Execute shell commands with real-time output and project-aware working directory
  • āœ… execute_command_background - Start commands in the background with process management
  • āœ… get_process_output - Retrieve output from background commands
Process Management
  • āœ… list_background_processes - List all active background processes
  • āœ… kill_background_process - Terminate background processes safely
  • āœ… get_process_status - Get detailed process status and monitoring
  • āœ… restart_background_process - Restart failed processes automatically
Python Integration
  • āœ… execute_python_script - Run Python scripts with output streaming and virtual environment support
  • āœ… execute_python_code - Execute Python code directly with project context
  • āœ… execute_python_code_with_streaming - Real-time streaming Python execution
  • āœ… install_python_package - Manage Python dependencies with virtual environment integration
Environment Management
  • āœ… change_directory - Change working directory with validation
  • āœ… get_current_directory - Get current directory information
  • āœ… set_environment_variable - Set environment variables with persistence
  • āœ… get_environment_variables - Get environment variables with filtering
Virtual Environment Tools
  • āœ… list_virtual_environments - Discover available virtual environments
  • āœ… activate_virtual_environment - Switch virtual environments seamlessly
  • āœ… create_virtual_environment - Create new virtual environments with package installation
  • āœ… install_dependencies - Install requirements.txt dependencies automatically

šŸš€ Key Features & Improvements

Project-Aware Working Directory (v1.1)

  • Intelligent Detection: Automatically detects project directory using pyproject.toml, README.md, and source structure
  • Natural Workflow: Commands like ls src/ work without absolute paths
  • Backward Compatible: Explicit working_directory parameters still override defaults
  • Configuration Driven: Customizable via config/config.yaml

Real-time Output Streaming

  • <50ms Latency: Near-instantaneous command feedback
  • Async Processing: Non-blocking execution with full async/await support
  • Stream Management: Proper buffering and output handling

Robust Process Management

  • Background Processes: Full lifecycle management with monitoring
  • Process Safety: Automatic cleanup and resource management
  • Status Monitoring: Real-time process status and health checks

Python Integration Excellence

  • Virtual Environment Support: Seamless venv creation and management
  • Dependency Management: Automatic package installation and requirements handling
  • Script Execution: Both file-based and direct code execution
  • Project Context: Python code executes with proper project imports

šŸ“‹ Implementation Status

āœ… Phase 1: Core Functionality - COMPLETE

  • āœ… Basic command execution with output streaming
  • āœ… Error handling and exit code reporting
  • āœ… Background process management
  • āœ… Working directory intelligence and project detection

āœ… Phase 2: Python Integration - COMPLETE

  • āœ… Python script execution
  • āœ… Virtual environment support
  • āœ… Dependency management
  • āœ… Real-time streaming execution

āœ… Phase 3: Advanced Features - COMPLETE

  • āœ… Process monitoring and restart capabilities
  • āœ… Advanced output handling and filtering
  • āœ… Performance optimizations
  • āœ… Comprehensive error handling

šŸŽÆ Current Status: Production Ready

  • 301 Unit Tests Passing (100% success rate)
  • >95% Code Coverage with comprehensive edge case testing
  • TDD Implementation ensuring robust and reliable functionality
  • Full MCP Compliance with proper tool registration and error handling

šŸŽÆ Target Use Case

Primary User: AI Coding Agent at /home/randy/workspace/personal/my_coding_agent

Capabilities Enabled:

  • āœ… Autonomous code compilation and testing
  • āœ… Real-time debugging with immediate feedback
  • āœ… File system operations and project management
  • āœ… Package installation and dependency management
  • āœ… System monitoring and process control
  • āœ… Integration testing and deployment tasks
  • āœ… Project-aware command execution

šŸ› ļø Installation & Setup

Quick Start (Production)

# Clone the repository
git clone <repository-url> terminal_mcp_server
cd terminal_mcp_server

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install production dependencies
pip install -e .

# Run the server
python -m terminal_mcp_server.server

Development Setup

# Install development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

# Run with coverage
pytest --cov=src --cov-report=html

Configuration

The server uses config/config.yaml for configuration:

terminal:
  execution:
    default_working_directory: "."  # Auto-detects project directory
    timeout: 300
    max_background_processes: 10
  
logging:
  level: "INFO"
  file: "logs/mcp_server.log"

šŸ“š Documentation

  • - Complete feature specifications
  • - Development history and completed tasks
  • API Documentation - Complete tool reference

šŸ”§ Architecture Overview

Design Principles

  • Async-First: All operations use async/await for non-blocking execution
  • Real-time Streaming: Command outputs stream in real-time using async generators
  • Process Safety: Comprehensive process lifecycle management with cleanup
  • Project Intelligence: Automatic project detection and context-aware execution
  • Resource Limits: Configurable limits for memory usage and process counts
  • Comprehensive Logging: Full audit trail of all operations

Technical Stack

  • FastMCP: MCP protocol implementation
  • psutil: Advanced process monitoring
  • asyncio: Asynchronous process execution
  • Pydantic: Data validation and modeling
  • pytest: Testing framework with >95% coverage

Project Structure

terminal_mcp_server/
ā”œā”€ā”€ src/terminal_mcp_server/    # Core server implementation
│   ā”œā”€ā”€ handlers/               # MCP tool handlers
│   ā”œā”€ā”€ models/                 # Data models and schemas
│   ā”œā”€ā”€ utils/                  # Utilities and managers
│   └── server.py              # Main server entry point
ā”œā”€ā”€ tests/unit/                # Comprehensive unit tests (301 tests)
ā”œā”€ā”€ config/                    # Configuration files
ā”œā”€ā”€ tools/                     # Development and debugging tools
└── tasks/                     # Project management and documentation

šŸŽ® MCP Tools Reference

Command Execution Tools

# Execute commands with project-aware working directory
execute_command(command="ls src/")
execute_command(command="pytest", working_directory="/custom/path")

# Background process management
execute_command_background(command="npm run dev")
list_background_processes()
get_process_status(process_id="abc123")
kill_background_process(process_id="abc123")

Python Integration Tools

# Execute Python code with project context
execute_python_code(code="import sys; print(sys.path)")
execute_python_script(script_path="scripts/deploy.py")

# Virtual environment management
create_virtual_environment(name="myproject")
activate_virtual_environment(name="myproject")
install_python_package(package="requests", virtual_environment="myproject")

Environment Management Tools

# Directory and environment management
get_current_directory()
change_directory(path="/home/user/project")
set_environment_variable(name="API_KEY", value="secret")
get_environment_variables(variables=["PATH", "HOME"])

🚧 Development Workflow

Code Quality Standards

  • Black: Code formatting (enforced)
  • isort: Import sorting (enforced)
  • flake8: Linting (enforced)
  • mypy: Type checking (enforced)
  • bandit: Security scanning (enforced)
  • pytest: >95% test coverage (achieved)

Testing Strategy

# Run all tests (301 tests)
pytest

# Run with coverage (>95% coverage)
pytest --cov=src --cov-report=html

# Run unit tests only
pytest tests/unit/

# Run specific test categories
pytest tests/unit/test_working_directory.py

Task Management

  • āœ… Follow the for implementation order
  • āœ… Use Test-Driven Development (TDD) approach
  • āœ… One sub-task at a time with user approval
  • āœ… Mark tasks complete only after tests pass

šŸŽÆ Success Metrics - ACHIEVED

  • āœ… Functionality: 100% of PRD requirements implemented (18/18 tools)
  • āœ… Performance: <50ms command execution latency (target: <100ms)
  • āœ… Reliability: >99% successful command execution rate
  • āœ… Integration: Seamless AI Coding Agent integration with project awareness
  • āœ… Testing: >95% code coverage with 301 comprehensive tests

šŸ” Recent Major Improvements

v1.1 - Working Directory Intelligence (Latest)

  • Project Auto-Detection: Automatically detects and uses project directory
  • Natural Command Execution: Commands work with relative paths (ls src/ vs /full/path/src/)
  • Backward Compatibility: Explicit working directories still override defaults
  • Enhanced User Experience: Eliminates need for absolute paths in development workflows

Performance Benchmarks

  • Command Execution: ~20ms average latency
  • Python Code Execution: ~80ms average latency
  • Background Process Creation: ~15ms average latency
  • Virtual Environment Operations: ~200ms average latency

šŸ¤ Contributing

This project follows a structured development approach:

  1. Review the PRD: Understand requirements in
  2. Follow Task List: Work through
  3. Test-Driven Development: Write tests first, then implement
  4. One Task at a Time: Complete tasks sequentially with approval

šŸ“„ License

MIT License - see file for details.


šŸŽ‰ Status: Production Ready! Full terminal access for AI agents with real-time command execution, background process management, comprehensive Python integration, and intelligent project-aware working directory detection!