AI-Safe Terminal MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
AI-Safe Terminal MCP Server
Prevent AI tool calls from hanging with automatic command safety and smart execution strategies.
π Overview
This MCP (Model Context Protocol) server automatically intercepts and enhances terminal command execution for AI assistants, providing:
Automatic Hang Prevention - No more frozen AI sessions waiting for commands
Smart Command Classification - Routes test/build/long commands to background execution
Cross-Platform Support - Works on macOS, Linux, and Windows
Transparent Operation - Zero configuration required for AI assistants
Comprehensive Logging - Full context for debugging and monitoring
Related MCP server: Terminal MCP Server
π Quick Start
1. Installation
# Clone or extract this project
cd mcp-ai-terminal
# Install Python dependencies
pip install -r requirements.txt
# Install system-wide terminal backends
chmod +x install-ai-terminal.sh
./install-ai-terminal.sh2. Start MCP Server
# Start the MCP server
python mcp-ai-terminal-server.py --port 8000
# Or use the launcher script
./start-mcp-server.sh3. Configure AI Client
Add to your AI client's MCP configuration:
{
"mcpServers": {
"ai-safe-terminal": {
"command": "python",
"args": ["/path/to/mcp-ai-terminal-server.py"],
"env": {}
}
}
}π οΈ Architecture
AI Assistant
β
MCP Server (This Project)
β
βββββββββββββββββββββββββββββββββββββββββββ
β Smart Command Classification β
βββββββββββββββββββββββββββββββββββββββββββ€
β Quick Commands β 8s timeout β
β Test Commands β Background execution β
β Build Commands β Background execution β
β Long Commands β Background execution β
βββββββββββββββββββββββββββββββββββββββββββ
β
Cross-Platform Backends
βββ Unix/macOS: unified-terminal-system.sh
βββ Windows: unified-terminal-system.ps1
βββ Enhanced: freeze-resistant-terminal.shπ― Key Features
Automatic Command Classification
Test Commands:
pytest,mvn test,npm testβ BackgroundBuild Commands:
make,gradle build,npm run buildβ BackgroundLong Commands:
git clone,npm install,docker buildβ BackgroundQuick Commands:
ls,git status,cat file.txtβ 8s timeout
Hang Prevention Mechanisms
Strict Timeouts: Commands killed after safe thresholds
Background Jobs: Long commands run without blocking AI
Freeze Detection: Monitors output and CPU usage
Process Tree Cleanup: Ensures no zombie processes
Graceful Termination: SIGTERM β SIGKILL escalation
Cross-Platform Support
macOS: Native bash with timeout fallbacks
Linux: Full GNU coreutils support
Windows: PowerShell jobs with native timeout handling
π API Reference
Tools Provided
run_command_safe
Execute terminal commands with automatic safety measures.
{
"command": "mvn clean test",
"cwd": "/path/to/project",
"force_background": false,
"timeout": 8
}check_command_status
Monitor background command progress.
{
"show_output": true
}get_terminal_context
Retrieve recent terminal activity for debugging.
{
"lines": 50
}π§ͺ Testing
Run Test Suite
# Test all components
./test-mcp-system.sh
# Test specific scenarios
./test-hang-prevention.sh
./test-background-execution.sh
./test-cross-platform.shManual Testing
# Test quick command (should complete in <8s)
python mcp-ai-terminal-server.py test-quick "echo 'Hello World'"
# Test background command (should return immediately)
python mcp-ai-terminal-server.py test-background "sleep 30"
# Test freeze detection (should terminate automatically)
python mcp-ai-terminal-server.py test-freeze "while true; do echo ping; sleep 1; done"π Project Structure
mcp-ai-terminal/
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ mcp-ai-terminal-server.py # Main MCP server
βββ start-mcp-server.sh # Server launcher
βββ install-ai-terminal.sh # System installation
βββ backends/
β βββ unified-terminal-system.sh # Unix/macOS backend
β βββ unified-terminal-system.ps1 # Windows backend
β βββ freeze-resistant-terminal.sh # Enhanced freeze detection
β βββ ai-terminal # Universal launcher
βββ tests/
β βββ test-mcp-system.sh # Full system tests
β βββ test-hang-prevention.sh # Hang prevention tests
β βββ test-cross-platform.sh # Platform compatibility tests
βββ docs/
β βββ ARCHITECTURE.md # Technical architecture
β βββ CROSS-PLATFORM-GUIDE.md # Platform-specific guide
β βββ MCP-INTEGRATION.md # MCP client integration
β βββ TROUBLESHOOTING.md # Common issues and solutions
βββ examples/
βββ example-ai-client-config.json # Sample MCP configuration
βββ demo-commands.sh # Example command scenarios
βββ benchmark-performance.sh # Performance testingπ§ Configuration
Environment Variables
export AI_TERMINAL_TIMEOUT=8 # Default timeout for quick commands
export AI_TERMINAL_BG_TIMEOUT=300 # Timeout for background commands
export AI_TERMINAL_OUTPUT_DIR=/tmp/ai-terminal-outputs
export AI_TERMINAL_LOG_LEVEL=INFOCustom Command Classification
Edit mcp-ai-terminal-server.py to customize command patterns:
self.test_patterns = ["test", "spec", "check", "verify"]
self.build_patterns = ["build", "compile", "package", "deploy"]
self.long_patterns = ["install", "download", "clone", "sync"]π¨ Safety Features
Timeout Protection
Quick Commands: 8 second maximum execution time
Background Commands: Run independently, never block AI
Freeze Detection: Automatic termination of unresponsive processes
Resource Management
Process Cleanup: Automatic cleanup of terminated processes
Output Limiting: Prevents memory exhaustion from large outputs
Disk Space: Automatic cleanup of old log files
Cross-Platform Reliability
Timeout Fallbacks: Perl-based timeouts on macOS when
gtimeoutunavailableWindows Jobs: PowerShell background jobs with native timeout support
Signal Handling: Proper process termination across all platforms
π€ Integration Examples
MCP Config
{
"mcpServers": {
"ai-safe-terminal": {
"command": "python3",
"args": ["/Users/you/.local/bin/mcp-ai-terminal-server.py"]
}
}
}π Performance
Benchmark Results
Quick Commands: <100ms overhead
Background Commands: <50ms startup time
Freeze Detection: <3s response time
Memory Usage: <10MB for server + backends
Scalability
Concurrent Commands: Up to 50 background jobs
Log Retention: Automatic cleanup after 7 days
Platform Support: Tested on 12+ OS configurations
π Troubleshooting
Common Issues
"MCP server not responding"
# Check if server is running
ps aux | grep mcp-ai-terminal-server
# Check logs
tail -f /tmp/ai-terminal-outputs/mcp-server.log"Commands still hanging"
# Verify backend installation
ai-terminal help
# Test freeze detection
./backends/freeze-resistant-terminal.sh test-freeze"Cross-platform issues"
# Test platform detection
python -c "import platform; print(platform.system())"
# Verify backend scripts
ls -la backends/See docs/TROUBLESHOOTING.md for detailed solutions.
π Development
Contributing
Fork the repository
Create feature branch:
git checkout -b feature/amazing-featureRun tests:
./tests/test-mcp-system.shCommit changes:
git commit -m 'Add amazing feature'Push branch:
git push origin feature/amazing-featureOpen Pull Request
Testing New Features
# Add new test case
echo 'test_my_feature() { ... }' >> tests/test-mcp-system.sh
# Run specific test
./tests/test-mcp-system.sh test_my_feature
# Validate across platforms
./tests/test-cross-platform.shπ License
MIT License - see LICENSE file for details.
π Acknowledgments
MCP Protocol: Model Context Protocol specification
Cross-Platform Testing: Community feedback from macOS, Linux, and Windows users
AI Safety Research: Insights from AI tool call reliability studies
Ready to eliminate AI command hanging forever? Start with the Quick Start guide above! π
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Connect AI assistants to your approved computer for files, commands, browser and desktop tasks.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
- DNS-DATA RemoteDeprecatedcom.dns-data
Connect AI assistants to authorized Windows and macOS devices for files, commands, and management.
Related MCP Servers
- AlicenseAqualityAmaintenanceAllows AI assistants to safely execute common Unix/macOS terminal commands through a controlled interface with comprehensive security features.824 PyPI10MIT
- FlicenseNot gradedqualityDmaintenanceEnables safe execution of terminal commands across different shells (bash, cmd, PowerShell) with configurable timeouts, working directories, and resource limits for command-line operations through AI assistants.-
- AlicenseAqualityDmaintenanceEnables AI assistants to execute terminal commands on a host machine with configurable, granular permission controls and safety protections. It features multiple security modes, including allowlists and manual approval, to ensure safe command execution within specified directories.6Apache 2.0
- AlicenseNot gradedqualityDmaintenanceProvides secure, sandboxed terminal access for AI assistants via the Model Context Protocol, with multi-layer risk analysis and auditable command execution.22 npm8MIT