#!/bin/bash
set -e
export PATH="$PATH:/usr/bin:/usr/local/bin"
echo "Node.js version: $(node --version)"
echo "NPM version: $(npm --version)"
echo "Python version: $(python --version)"
CONFIG_FILE="/app/config.toml"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Warning: Config file $CONFIG_FILE not found, using default config"
fi
if [ -f "/app/mcp_servers/mcp_code_executor/build/index.js" ]; then
echo "✅ mcp_code_executor build found"
else
echo "⚠️ mcp_code_executor build not found, attempting rebuild..."
cd /app/mcp_servers/mcp_code_executor
npm install && npm run build
fi
source /opt/conda/bin/activate mcp-agent
echo "Activated Python version: $(python --version)"
echo "Checking for uvicorn: $(which uvicorn || echo 'Not found')"
echo "Current directory: $(pwd)"
export PYTHONPATH=/app:$PYTHONPATH
export CODE_STORAGE_DIR=/app/code_storage
export CONDA_ENV_NAME=mcp-executor
export UV_PATH=/usr/local/bin/uv
mkdir -p /app/mcp_server_logs
if [ ! -d "/app/filesystem/GAIA" ]; then
echo "Creating GAIA directory in filesystem..."
mkdir -p /app/filesystem/GAIA
fi
if [ -d "/app/data/GAIA" ]; then
echo "Copying GAIA data to filesystem directory..."
cp -r /app/data/GAIA /app/filesystem/
fi
echo "Starting main server..."
cd /app
nohup uvicorn main:app --host 0.0.0.0 --port 8000 > /app/mcp_server_logs/main_server.log 2>&1 &
sleep 10
echo "=== Service Startup Status Check ==="
echo "Main Server (8000): $(curl -s http://localhost:8000 > /dev/null && echo 'Running' || echo 'Not started')"
echo "Starting Streamable HTTP MCP server..."
cd /app
python -m uvicorn streamable_http_server:app --host 0.0.0.0 --port 8088 --log-level debug
exec "$@"