start_server.shโข6.85 kB
#!/bin/bash
# Katamari MCP Server Launcher
# Automatically sets up environment and starts server
set -e # Exit on any error
# Parse command line arguments for transport selection
TRANSPORTS="stdio" # Default
SHOW_HELP=false
while [[ $# -gt 0 ]]; do
case $1 in
-t|--transports)
TRANSPORTS="$2"
shift 2
;;
-h|--help)
SHOW_HELP=true
shift
;;
*)
echo "Unknown option: $1"
SHOW_HELP=true
shift
;;
esac
done
# Show help
if [ "$SHOW_HELP" = true ]; then
echo "๐ Katamari MCP Server Launcher"
echo ""
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -t, --transports TRANSPORTS Comma-separated list of transports"
echo " Available: stdio, sse, websocket"
echo " Default: stdio"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Start with stdio only (MCP compatible)"
echo " $0 -t stdio,sse # Start with stdio + SSE (port 49152)"
echo " $0 -t sse,websocket # Start with SSE + WebSocket (ports 49152-49153)"
echo " $0 -t stdio,sse,websocket # Start with all transports"
echo ""
echo "Transport Information:"
echo " stdio - MCP compatibility, local tools (no port)"
echo " sse - Web clients, streaming updates (port 49152)"
echo " websocket - Real-time bidirectional (port 49153)"
exit 0
fi
echo "๐ Starting Katamari MCP Server..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in right directory
if [ ! -f "katamari_mcp/server.py" ]; then
print_error "Please run this script from katamari-mcp root directory"
exit 1
fi
# Check Python version
PYTHON_VERSION=$(python3 --version 2>&1 | grep -oE '\d+\.\d+' || echo "unknown")
MAJOR_VERSION=$(echo "$PYTHON_VERSION" | cut -d. -f1)
MINOR_VERSION=$(echo "$PYTHON_VERSION" | cut -d. -f2)
if [ "$MAJOR_VERSION" -lt 3 ] || ([ "$MAJOR_VERSION" -eq 3 ] && [ "$MINOR_VERSION" -lt 9 ]); then
print_error "Python 3.9+ required. Found: $PYTHON_VERSION"
exit 1
fi
print_status "Python version: $PYTHON_VERSION โ"
# Check if virtual environment exists
if [ ! -d ".venv" ]; then
print_status "Creating virtual environment..."
python3 -m venv .venv
print_success "Virtual environment created"
else
print_status "Virtual environment found"
fi
# Activate virtual environment
if [ -f ".venv/bin/activate" ]; then
print_status "Activating virtual environment..."
source .venv/bin/activate
print_success "Virtual environment activated"
elif [ -f ".venv/Scripts/activate" ]; then
# Windows support
print_status "Activating virtual environment (Windows)..."
source .venv/Scripts/activate
print_success "Virtual environment activated"
else
print_error "Virtual environment activation script not found"
exit 1
fi
# Check if dependencies are installed
print_status "Checking dependencies..."
# Check critical dependencies
MISSING_DEPS=()
check_dep() {
if ! python -c "import $1" 2>/dev/null; then
MISSING_DEPS+=("$1")
else
echo -e " โ $2"
fi
}
check_dep "torch" "PyTorch"
check_dep "transformers" "Transformers"
check_dep "aiohttp" "aiohttp"
check_dep "mcp" "MCP"
check_dep "pydantic" "Pydantic"
check_dep "beautifulsoup4" "BeautifulSoup4"
check_dep "psutil" "psutil"
if [ ${#MISSING_DEPS[@]} -gt 0 ]; then
print_warning "Missing dependencies: ${MISSING_DEPS[*]}"
print_status "Installing missing dependencies..."
# Install CPU-only PyTorch first (faster download)
print_status "Installing PyTorch (CPU-only)..."
pip install torch --index-url https://download.pytorch.org/whl/cpu
# Install remaining dependencies
print_status "Installing remaining dependencies..."
pip install transformers pydantic aiohttp mcp pytest-asyncio beautifulsoup4 psutil
print_success "Dependencies installed"
else
print_success "All dependencies already installed"
fi
# Check for optional dependencies based on selected transports
if [[ "$TRANSPORTS" == *"sse"* ]] || [[ "$TRANSPORTS" == *"websocket"* ]]; then
print_status "Checking web transport dependencies..."
# Check for websockets if WebSocket transport is requested
if [[ "$TRANSPORTS" == *"websocket"* ]]; then
if ! python -c "import websockets" 2>/dev/null; then
print_warning "websockets package required for WebSocket transport"
print_status "Installing websockets..."
pip install websockets
print_success "websockets installed"
else
echo -e " โ websockets"
fi
fi
fi
# Test server import
print_status "Testing server import..."
if python -c "from katamari_mcp.server import KatamariServer; print('โ
Server import successful')" 2>/dev/null; then
print_success "Server import test passed"
else
print_error "Server import test failed"
exit 1
fi
# Create data directories
print_status "Ensuring data directories exist..."
mkdir -p .katamari/acp/{feedback,metrics,adjustments,performance}
print_success "Data directories ready"
# Check if first-time setup (LLM download)
if [ ! -d ".venv/lib/python*/site-packages/transformers/models/qwen2" ] 2>/dev/null; then
print_warning "First-time setup detected"
print_status "Tiny LLM (Qwen2-0.5B) will be downloaded on first use (~500MB)"
print_status "Please ensure stable internet connection"
echo ""
fi
# Start server
print_success "Environment setup complete!"
echo ""
echo "๐ฏ Starting Katamari MCP Server..."
echo " - Transports: $TRANSPORTS"
# Show transport-specific information
if [[ "$TRANSPORTS" == *"stdio"* ]]; then
echo " - stdio: MCP compatible (no port)"
fi
if [[ "$TRANSPORTS" == *"sse"* ]]; then
echo " - SSE: Web clients on http://localhost:49152"
fi
if [[ "$TRANSPORTS" == *"websocket"* ]]; then
echo " - WebSocket: Real-time on ws://localhost:49153"
fi
echo " - Web Search: DuckDuckGo + Brave Search"
echo " - Web Scraping: HTML to markdown conversion"
echo " - Adaptive Learning: Enabled"
echo " - Press Ctrl+C to stop"
echo ""
# Set environment variables
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
# Start server with selected transports
python -m katamari_mcp.server "$TRANSPORTS"