thepeacefulprogrammer/terminal_mcp_server
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.
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:
- Review the PRD: Understand requirements in
- Follow Task List: Work through
- Test-Driven Development: Write tests first, then implement
- 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!