#!/bin/bash
# Digital Ocean MCP Server Setup Script for Claude Code
# Run this script to add the Digital Ocean MCP server

echo "==========================================================="
echo "  Digital Ocean MCP Server Setup for Claude Code"
echo "==========================================================="
echo ""

# Set the API token as environment variable
export DIGITALOCEAN_API_TOKEN="dop_v1_8bb780b3b00b9f0a4858e0e37130ca48e4220f7c9de256e06128c55080edd248"

echo "✓ Digital Ocean API token set"
echo ""

# Add the MCP server using the claude CLI
echo "Adding Digital Ocean MCP server..."
echo "Running: claude mcp add digitalocean --env DIGITALOCEAN_API_TOKEN=****** -- npx -y @digitalocean/mcp"
echo ""

# Check if claude command exists
if command -v claude &> /dev/null; then
    echo "✓ Found Claude CLI: $(which claude)"
    echo ""

    # Add the Digital Ocean MCP server
    # Focusing on App Platform and Databases since that's what we're using
    claude mcp add digitalocean \
        --env DIGITALOCEAN_API_TOKEN=$DIGITALOCEAN_API_TOKEN \
        -- npx -y "@digitalocean/mcp" --services apps,databases,droplets,networking

    if [ $? -eq 0 ]; then
        echo ""
        echo "✓ Digital Ocean MCP server added successfully!"
        echo ""
        echo "Available Services:"
        echo "  • App Platform (apps)"
        echo "  • Databases"
        echo "  • Droplets"
        echo "  • Networking"
        echo ""
        echo "I can now manage your Digital Ocean resources directly!"
        echo "Try asking me to:"
        echo "  - List your apps"
        echo "  - Check app status"
        echo "  - View deployment logs"
        echo "  - Manage databases"
        echo "  - Deploy new versions"
    else
        echo ""
        echo "✗ Failed to add MCP server"
        echo "Exit code: $?"
    fi
else
    echo "✗ Claude CLI command not found in PATH"
    echo ""
    echo "MANUAL SETUP REQUIRED:"
    echo "------------------------------------------------------"
    echo ""
    echo "Since the 'claude' command is not in your PATH, please run this command manually:"
    echo ""
    echo "claude mcp add digitalocean \\"
    echo "  --env DIGITALOCEAN_API_TOKEN=dop_v1_8bb780b3b00b9f0a4858e0e37130ca48e4220f7c9de256e06128c55080edd248 \\"
    echo "  -- npx -y @digitalocean/mcp --services apps,databases,droplets,networking"
    echo ""
    echo "Or if you're using Claude Code via VS Code extension:"
    echo "1. Open the Command Palette (Ctrl+Shift+P)"
    echo "2. Type: 'Claude Code: Add MCP Server'"
    echo "3. Enter name: digitalocean"
    echo "4. Enter command: npx @digitalocean/mcp --services apps,databases,droplets,networking"
    echo "5. Add environment variable: DIGITALOCEAN_API_TOKEN=dop_v1_8bb780b3b00b9f0a4858e0e37130ca48e4220f7c9de256e06128c55080edd248"
    echo ""
    echo "For more help, see: https://www.digitalocean.com/community/tutorials/claude-code-mcp-server"
fi

echo ""
echo "==========================================================="
