#!/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
echo "Checking and installing mcp_code_executor dependencies..."
cd /app/mcp_servers/mcp_code_executor
npm install
npm run build
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 mcp_code_executor server..."
cd /app/mcp_servers/mcp_code_executor
nohup node build/index.js > /app/mcp_server_logs/mcp_code_executor.log 2>&1 &
echo "Starting filesystem server..."
nohup npx @modelcontextprotocol/server-filesystem /app/filesystem > /app/mcp_server_logs/filesystem.log 2>&1 &
echo "Starting nlp-search-infra-server with proxy settings..."
cd /app/mcp_servers/nlp-search-infra-server
nohup ./start_with_proxy.sh > /app/mcp_server_logs/nlp-search-infra-server.log 2>&1 &
echo "Waiting for all servers to start..."
sleep 5
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 5
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 "$@"