#!/bin/bash
# ListMonk MCP Server Runner

# Check if environment variables are set
if [ -z "$LISTMONK_BASE_URL" ]; then
    echo "ERROR: LISTMONK_BASE_URL environment variable is not set"
    echo "Example: export LISTMONK_BASE_URL=http://localhost:9000/api"
    exit 1
fi

if [ -z "$LISTMONK_USERNAME" ] && [ -z "$LISTMONK_API_KEY" ]; then
    echo "ERROR: Either LISTMONK_USERNAME/LISTMONK_PASSWORD or LISTMONK_API_KEY must be set"
    echo "For Basic Auth:"
    echo "  export LISTMONK_USERNAME=admin"
    echo "  export LISTMONK_PASSWORD=your-password"
    echo "For API Key:"
    echo "  export LISTMONK_API_KEY=your-api-key"
    exit 1
fi

# Install dependencies if needed
if [ ! -d "node_modules" ]; then
    echo "Installing dependencies..."
    npm install --production
fi

# Run the MCP server
echo "Starting ListMonk MCP Server..."
node dist/index.js
