#!/bin/bash
#
# Installation Script for Claude Code MCP Server - Agent Orchestration Platform
#
# This script automates the installation and setup of the Agent Orchestration Platform
# including dependency installation, configuration, and Claude Desktop integration.
#
# Author: ADDER_6 | Created: 2025-06-26
#
set -euo pipefail
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
PROJECT_NAME="Agent Orchestration Platform"
MINIMUM_PYTHON_VERSION="3.10"
REQUIRED_MACOS_VERSION="12.0"
INSTALL_DIR="$HOME/.claude-code-mcp"
CONFIG_DIR="$HOME/.config/claude-desktop"
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Error handling
error_exit() {
log_error "$1"
exit 1
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Version comparison
version_gte() {
printf '%s\n%s\n' "$2" "$1" | sort -V -C
}
# Check prerequisites
check_prerequisites() {
log_info "Checking system prerequisites..."
# Check macOS version
if [[ "$(uname)" != "Darwin" ]]; then
error_exit "This installation script is designed for macOS only"
fi
local macos_version
macos_version=$(sw_vers -productVersion)
if ! version_gte "$macos_version" "$REQUIRED_MACOS_VERSION"; then
error_exit "macOS $REQUIRED_MACOS_VERSION or later is required (found: $macos_version)"
fi
log_success "macOS version: $macos_version"
# Check Python version
if ! command_exists python3; then
error_exit "Python 3 is required but not found. Please install Python $MINIMUM_PYTHON_VERSION or later."
fi
local python_version
python_version=$(python3 -c "import sys; print('.'.join(map(str, sys.version_info[:2])))")
if ! version_gte "$python_version" "$MINIMUM_PYTHON_VERSION"; then
error_exit "Python $MINIMUM_PYTHON_VERSION or later is required (found: $python_version)"
fi
log_success "Python version: $python_version"
# Check iTerm2
if ! command_exists osascript || ! osascript -e 'tell application "iTerm" to version' >/dev/null 2>&1; then
log_warning "iTerm2 not found or not running. The system will work with Terminal.app but iTerm2 is recommended."
else
log_success "iTerm2 detected"
fi
# Check Claude Code CLI
if ! command_exists claude-code; then
log_warning "Claude Code CLI not found. Please install it from: https://claude.ai/code"
read -p "Continue installation anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
error_exit "Installation cancelled"
fi
else
log_success "Claude Code CLI detected"
fi
}
# Install Python dependencies
install_dependencies() {
log_info "Installing Python dependencies..."
# Check if pip is available
if ! command_exists pip3; then
error_exit "pip3 is required but not found"
fi
# Install required packages
local packages=(
"fastmcp>=0.1.0"
"aiofiles>=0.8.0"
"cryptography>=41.0.0"
"pydantic>=2.0.0"
"PyContracts>=1.8.0"
"pytest>=7.4.0"
"pytest-asyncio>=0.21.0"
"pytest-cov>=4.1.0"
"pytest-benchmark>=4.0.0"
"hypothesis>=6.80.0"
)
for package in "${packages[@]}"; do
log_info "Installing $package..."
if ! pip3 install "$package"; then
log_warning "Failed to install $package, continuing..."
fi
done
log_success "Dependencies installation completed"
}
# Create directory structure
create_directories() {
log_info "Creating directory structure..."
# Create installation directory
mkdir -p "$INSTALL_DIR"/{bin,config,logs,data}
# Create Claude Desktop config directory
mkdir -p "$CONFIG_DIR"
log_success "Directory structure created"
}
# Copy project files
install_project_files() {
log_info "Installing project files..."
local project_root
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# Copy source code
cp -r "$project_root/src" "$INSTALL_DIR/"
# Copy configuration files
cp -r "$project_root/docs" "$INSTALL_DIR/"
# Copy scripts
cp -r "$project_root/scripts" "$INSTALL_DIR/"
# Make scripts executable
chmod +x "$INSTALL_DIR"/scripts/**/*.sh
log_success "Project files installed to $INSTALL_DIR"
}
# Generate configuration files
generate_config() {
log_info "Generating configuration files..."
# Create main configuration
cat > "$INSTALL_DIR/config/server.json" << EOF
{
"server": {
"host": "localhost",
"port": 8000,
"max_agents": 32,
"session_timeout": 3600
},
"security": {
"encryption_enabled": true,
"authentication_required": true,
"max_login_attempts": 5
},
"iterm": {
"integration_enabled": true,
"default_session": "Claude Code Agents"
},
"logging": {
"level": "INFO",
"file": "$INSTALL_DIR/logs/server.log",
"max_size": "10MB",
"backup_count": 5
}
}
EOF
# Create Claude Desktop MCP configuration
local claude_config="$CONFIG_DIR/mcp_settings.json"
if [[ -f "$claude_config" ]]; then
log_info "Backing up existing Claude Desktop configuration..."
cp "$claude_config" "$claude_config.backup.$(date +%Y%m%d_%H%M%S)"
fi
# Create or update MCP settings
cat > "$claude_config" << EOF
{
"mcpServers": {
"agent-orchestration": {
"command": "python3",
"args": ["$INSTALL_DIR/src/main.py"],
"env": {
"PYTHONPATH": "$INSTALL_DIR/src"
}
}
}
}
EOF
log_success "Configuration files generated"
}
# Create launcher script
create_launcher() {
log_info "Creating launcher script..."
cat > "$INSTALL_DIR/bin/start-server" << 'EOF'
#!/bin/bash
#
# Agent Orchestration Platform Launcher
#
INSTALL_DIR="$HOME/.claude-code-mcp"
export PYTHONPATH="$INSTALL_DIR/src:$PYTHONPATH"
cd "$INSTALL_DIR"
# Check if server is already running
if pgrep -f "python3.*main.py" > /dev/null; then
echo "Server is already running"
exit 1
fi
# Start the server
echo "Starting Agent Orchestration Platform server..."
python3 src/main.py --config config/server.json
EOF
chmod +x "$INSTALL_DIR/bin/start-server"
# Create stop script
cat > "$INSTALL_DIR/bin/stop-server" << 'EOF'
#!/bin/bash
#
# Agent Orchestration Platform Stop Script
#
echo "Stopping Agent Orchestration Platform server..."
pkill -f "python3.*main.py"
if [ $? -eq 0 ]; then
echo "Server stopped successfully"
else
echo "No running server found"
fi
EOF
chmod +x "$INSTALL_DIR/bin/stop-server"
log_success "Launcher scripts created"
}
# Add to PATH
setup_path() {
log_info "Setting up PATH..."
local shell_config
if [[ "$SHELL" == */zsh ]]; then
shell_config="$HOME/.zshrc"
elif [[ "$SHELL" == */bash ]]; then
shell_config="$HOME/.bashrc"
else
shell_config="$HOME/.profile"
fi
# Add to PATH if not already present
if ! grep -q "$INSTALL_DIR/bin" "$shell_config" 2>/dev/null; then
echo "export PATH=\"$INSTALL_DIR/bin:\$PATH\"" >> "$shell_config"
log_success "Added $INSTALL_DIR/bin to PATH in $shell_config"
else
log_info "PATH already configured"
fi
}
# Verify installation
verify_installation() {
log_info "Verifying installation..."
# Check if files exist
local required_files=(
"$INSTALL_DIR/src/main.py"
"$INSTALL_DIR/config/server.json"
"$INSTALL_DIR/bin/start-server"
"$CONFIG_DIR/mcp_settings.json"
)
for file in "${required_files[@]}"; do
if [[ ! -f "$file" ]]; then
error_exit "Required file not found: $file"
fi
done
# Test Python imports
log_info "Testing Python imports..."
cd "$INSTALL_DIR"
if ! python3 -c "import sys; sys.path.insert(0, 'src'); import src.types" 2>/dev/null; then
log_warning "Some Python imports may have issues, but installation continued"
fi
log_success "Installation verification completed"
}
# Print completion message
print_completion() {
echo
echo "==============================================="
log_success "$PROJECT_NAME installation completed!"
echo "==============================================="
echo
echo "Installation directory: $INSTALL_DIR"
echo "Configuration: $INSTALL_DIR/config/server.json"
echo "Claude Desktop config: $CONFIG_DIR/mcp_settings.json"
echo
echo "To start the server:"
echo " $INSTALL_DIR/bin/start-server"
echo
echo "To stop the server:"
echo " $INSTALL_DIR/bin/stop-server"
echo
echo "After installation:"
echo "1. Restart Claude Desktop to load the MCP configuration"
echo "2. Start the server using the launcher script"
echo "3. The server will be available for Claude Desktop integration"
echo
echo "For troubleshooting, check the logs at:"
echo " $INSTALL_DIR/logs/server.log"
echo
echo "Documentation is available at:"
echo " $INSTALL_DIR/docs/"
echo
}
# Uninstall function
uninstall() {
log_info "Uninstalling $PROJECT_NAME..."
# Stop server if running
"$INSTALL_DIR/bin/stop-server" 2>/dev/null || true
# Remove installation directory
if [[ -d "$INSTALL_DIR" ]]; then
rm -rf "$INSTALL_DIR"
log_success "Removed installation directory"
fi
# Remove Claude Desktop configuration
local claude_config="$CONFIG_DIR/mcp_settings.json"
if [[ -f "$claude_config" ]]; then
# Remove or comment out the agent-orchestration server
if command_exists jq; then
jq 'del(.mcpServers["agent-orchestration"])' "$claude_config" > "$claude_config.tmp" && mv "$claude_config.tmp" "$claude_config"
else
mv "$claude_config" "$claude_config.backup.uninstall"
log_info "Backed up Claude Desktop config to $claude_config.backup.uninstall"
fi
fi
log_success "Uninstallation completed"
}
# Main installation flow
main() {
echo "==============================================="
echo " $PROJECT_NAME Installer"
echo "==============================================="
echo
# Handle command line arguments
case "${1:-install}" in
"install")
check_prerequisites
install_dependencies
create_directories
install_project_files
generate_config
create_launcher
setup_path
verify_installation
print_completion
;;
"uninstall")
uninstall
;;
"help"|"--help"|"-h")
echo "Usage: $0 [install|uninstall|help]"
echo
echo "Commands:"
echo " install Install the Agent Orchestration Platform (default)"
echo " uninstall Remove the installation"
echo " help Show this help message"
exit 0
;;
*)
error_exit "Unknown command: $1. Use 'help' for usage information."
;;
esac
}
# Run main function with all arguments
main "$@"