mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-13 13:47:23 -04:00
fix: improve MCP service startup reliability
- Clarify OPENAI_API_BASE can be left empty for default endpoint - Increase initial wait time from 3s to 5s - Add health checking for all MCP services (ports 8000-8003) - Retry up to 10 times with 1s intervals - Install netcat for port checking - Display warnings if services aren't ready Helps diagnose and prevent MCP client initialization errors.
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
# Docker Compose automatically reads .env from project root
|
# Docker Compose automatically reads .env from project root
|
||||||
|
|
||||||
# AI Model API Configuration
|
# AI Model API Configuration
|
||||||
OPENAI_API_BASE=https://your-openai-proxy.com/v1
|
# OPENAI_API_BASE: Leave empty to use default OpenAI endpoint, or set to custom proxy URL
|
||||||
|
OPENAI_API_BASE=
|
||||||
OPENAI_API_KEY=your_openai_key_here # https://platform.openai.com/api-keys
|
OPENAI_API_KEY=your_openai_key_here # https://platform.openai.com/api-keys
|
||||||
|
|
||||||
# Data Source Configuration
|
# Data Source Configuration
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ FROM python:3.10-slim AS base
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies
|
# Install system dependencies
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends netcat-openbsd && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install Python dependencies
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,30 @@ MCP_PID=$!
|
|||||||
|
|
||||||
# Step 3: Wait for services to initialize
|
# Step 3: Wait for services to initialize
|
||||||
echo "⏳ Waiting for MCP services to start..."
|
echo "⏳ Waiting for MCP services to start..."
|
||||||
sleep 3
|
sleep 5
|
||||||
|
|
||||||
|
# Verify MCP services are responsive
|
||||||
|
echo "🔍 Checking MCP service health..."
|
||||||
|
MAX_RETRIES=10
|
||||||
|
RETRY_COUNT=0
|
||||||
|
SERVICES_READY=false
|
||||||
|
|
||||||
|
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
|
||||||
|
# Check if all ports are listening
|
||||||
|
if nc -z localhost 8000 && nc -z localhost 8001 && nc -z localhost 8002 && nc -z localhost 8003; then
|
||||||
|
SERVICES_READY=true
|
||||||
|
echo "✅ All MCP services are ready"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
RETRY_COUNT=$((RETRY_COUNT + 1))
|
||||||
|
echo "⏳ Waiting for services... (attempt $RETRY_COUNT/$MAX_RETRIES)"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$SERVICES_READY" = false ]; then
|
||||||
|
echo "⚠️ Warning: Some MCP services may not be ready"
|
||||||
|
echo " Check logs in /app/logs/ for details"
|
||||||
|
fi
|
||||||
|
|
||||||
# Step 4: Run trading agent with config file
|
# Step 4: Run trading agent with config file
|
||||||
echo "🤖 Starting trading agent..."
|
echo "🤖 Starting trading agent..."
|
||||||
|
|||||||
Reference in New Issue
Block a user