Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions actions/setup/sh/start_mcp_gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,36 +141,30 @@ echo "Waiting for gateway to be ready..."
HEALTH_CHECK_HOST="localhost"
echo "Health endpoint: http://${HEALTH_CHECK_HOST}:${MCP_GATEWAY_PORT}/health"
echo "(Note: MCP_GATEWAY_DOMAIN is '${MCP_GATEWAY_DOMAIN}' for container access)"
MAX_ATTEMPTS=30
ATTEMPT=0
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
# First check if the gateway process is still running
if ! ps -p $GATEWAY_PID > /dev/null 2>&1; then
echo "ERROR: Gateway process (PID: $GATEWAY_PID) has exited unexpectedly!"
echo ""
echo "Gateway stdout output:"
cat /tmp/gh-aw/mcp-config/gateway-output.json 2>/dev/null || echo "No stdout output available"
echo ""
echo "Gateway stderr logs:"
cat /tmp/gh-aw/mcp-logs/stderr.log 2>/dev/null || echo "No stderr logs available"
exit 1
fi

# Check health endpoint using localhost (since we're running on the host)
HEALTH_RESPONSE=$(curl -f -s "http://${HEALTH_CHECK_HOST}:${MCP_GATEWAY_PORT}/health" 2>&1) && {
echo "Gateway is ready!"
echo "Health response: $HEALTH_RESPONSE"
break
}
ATTEMPT=$((ATTEMPT + 1))
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Gateway not ready yet (curl response: $HEALTH_RESPONSE), waiting 1 second..."
sleep 1
fi
done
echo "Retrying up to 120 times with 1s delay (120s total timeout)"

# Check health endpoint using localhost (since we're running on the host)
# Per MCP Gateway Specification v1.3.0, /health must return HTTP 200 with JSON body containing specVersion and gatewayVersion
# Use curl retry: 120 attempts with 1 second delay = 120s total
RESPONSE=$(curl -s --retry 120 --retry-delay 1 --retry-connrefused --retry-all-errors -w "\n%{http_code}" "http://${HEALTH_CHECK_HOST}:${MCP_GATEWAY_PORT}/health" 2>&1)
HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
HEALTH_RESPONSE=$(echo "$RESPONSE" | head -n -1)

# Always log the health response for debugging
echo "Health endpoint HTTP code: $HTTP_CODE"
if [ -n "$HEALTH_RESPONSE" ]; then
echo "Health response body: $HEALTH_RESPONSE"
else
echo "Health response body: (empty)"
fi

if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
echo "ERROR: Gateway failed to become ready after $MAX_ATTEMPTS attempts"
if [ "$HTTP_CODE" = "200" ] && [ -n "$HEALTH_RESPONSE" ]; then
echo "Gateway is ready!"
else
echo ""
echo "ERROR: Gateway failed to become ready"
echo "Last HTTP code: $HTTP_CODE"
echo "Last health response: ${HEALTH_RESPONSE:-(empty)}"
echo ""
echo "Checking if gateway process is still alive..."
if ps -p $GATEWAY_PID > /dev/null 2>&1; then
Expand Down
49 changes: 24 additions & 25 deletions actions/setup/sh/verify_mcp_gateway_health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,39 @@ echo ''

# Wait for gateway to be ready FIRST before checking config
echo '=== Testing Gateway Health ==='
max_retries=30
retry_count=0
gateway_ready=false
health_response=""

while [ $retry_count -lt $max_retries ]; do
# Capture both response body and HTTP code in a single curl call
response=$(curl -s -w "\n%{http_code}" "${gateway_url}/health")
http_code=$(echo "$response" | tail -n 1)
health_response=$(echo "$response" | head -n -1)

if echo "$http_code" | grep -q "200\|204"; then
echo "✓ MCP Gateway is ready!"
gateway_ready=true
break
fi
retry_count=$((retry_count + 1))
echo "Waiting for gateway... (attempt $retry_count/$max_retries)"
sleep 1
done

if [ "$gateway_ready" = false ]; then
echo "✗ Error: MCP Gateway failed to start after $max_retries attempts"
# Capture both response body and HTTP code in a single curl call
# Use curl retry: 120 attempts with 1 second delay = 120s total
echo "Calling health endpoint: ${gateway_url}/health"
echo "Retrying up to 120 times with 1s delay (120s total timeout)"
response=$(curl -s --retry 120 --retry-delay 1 --retry-connrefused --retry-all-errors -w "\n%{http_code}" "${gateway_url}/health")
http_code=$(echo "$response" | tail -n 1)
health_response=$(echo "$response" | head -n -1)

# Always log the health response for debugging
echo "Health endpoint HTTP code: $http_code"
if [ -n "$health_response" ]; then
echo "Health response body: $health_response"
else
echo "Health response body: (empty)"
fi

if [ "$http_code" = "200" ]; then
echo "✓ MCP Gateway is ready!"
else
echo ''
echo "✗ Error: MCP Gateway failed to start"
echo "Last HTTP code: $http_code"
echo "Last health response: ${health_response:-(empty)}"
echo ''
echo '=== Gateway Logs (Full) ==='
cat "${logs_folder}/gateway.log" || echo 'No gateway logs found'
exit 1
fi

# Parse and display version information from health response
echo ''
if [ -n "$health_response" ]; then
echo "Health response: $health_response"
echo ''

# Extract version information using jq if available
if command -v jq >/dev/null 2>&1; then
spec_version=$(echo "$health_response" | jq -r '.specVersion // "unknown"')
Expand Down
Loading