install-robust.sh•5.83 kB
#!/bin/bash
# GCP MCP Server - Robust installer with better error handling
set -e
echo "🚀 Installing GCP MCP Server"
echo "=============================="
# Function to check command existence
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to get Python version
get_python_version() {
local python_cmd="$1"
if command_exists "$python_cmd"; then
$python_cmd -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>/dev/null || echo "unknown"
else
echo "not_found"
fi
}
# Check for Python installations
echo "🐍 Checking Python installations..."
PYTHON_CMD=""
PYTHON_VERSION=""
# Check for python3.11 first (preferred)
if command_exists python3.11; then
PYTHON_VERSION=$(get_python_version python3.11)
if [[ "$PYTHON_VERSION" == "3.11" ]]; then
PYTHON_CMD="python3.11"
echo "✅ Found Python 3.11"
fi
fi
# Fallback to python3 if it's 3.10+ (MCP requires 3.10+)
if [[ -z "$PYTHON_CMD" ]] && command_exists python3; then
PYTHON_VERSION=$(get_python_version python3)
if [[ "$PYTHON_VERSION" =~ ^3\.(10|11|12)$ ]]; then
PYTHON_CMD="python3"
echo "✅ Found Python $PYTHON_VERSION (using python3)"
elif [[ "$PYTHON_VERSION" =~ ^3\.(8|9)$ ]]; then
echo "⚠️ Found Python $PYTHON_VERSION but MCP requires Python 3.10+"
fi
fi
# Fallback to python if it's 3.10+
if [[ -z "$PYTHON_CMD" ]] && command_exists python; then
PYTHON_VERSION=$(get_python_version python)
if [[ "$PYTHON_VERSION" =~ ^3\.(10|11|12)$ ]]; then
PYTHON_CMD="python"
echo "✅ Found Python $PYTHON_VERSION (using python)"
elif [[ "$PYTHON_VERSION" =~ ^3\.(8|9)$ ]]; then
echo "⚠️ Found Python $PYTHON_VERSION but MCP requires Python 3.10+"
fi
fi
# If no suitable Python found
if [[ -z "$PYTHON_CMD" ]]; then
echo "❌ No suitable Python found!"
echo ""
echo "🔧 Please install Python 3.10+ using one of these methods:"
echo ""
echo "📦 macOS (using Homebrew):"
echo " brew install python@3.11"
echo ""
echo "📦 Ubuntu/Debian:"
echo " sudo apt update"
echo " sudo apt install python3.11 python3.11-venv python3.11-pip"
echo ""
echo "📦 CentOS/RHEL:"
echo " sudo yum install python311 python311-pip"
echo ""
echo "📦 Or download from https://www.python.org/downloads/"
exit 1
fi
echo "✅ Using Python: $PYTHON_CMD (version $PYTHON_VERSION)"
# Check if we're in the right directory
if [ ! -f "pyproject.toml" ]; then
echo "❌ This doesn't look like the gcp-mcp directory"
echo "💡 Make sure you're in the gcp-mcp directory:"
echo " git clone https://github.com/JayRajGoyal/gcp-mcp.git"
echo " cd gcp-mcp"
echo " ./install-robust.sh"
exit 1
fi
# Check if pip is available
echo "📦 Checking pip availability..."
if ! $PYTHON_CMD -m pip --version >/dev/null 2>&1; then
echo "❌ pip is not available for $PYTHON_CMD"
echo "💡 Try installing pip:"
echo " curl https://bootstrap.pypa.io/get-pip.py | $PYTHON_CMD"
exit 1
fi
echo "✅ pip is available"
# Create virtual environment
echo "🔧 Setting up virtual environment..."
if [ -d "venv" ]; then
echo "📁 Removing existing virtual environment..."
rm -rf venv
fi
echo "📦 Creating new virtual environment..."
$PYTHON_CMD -m venv venv
# Activate virtual environment
echo "🔄 Activating virtual environment..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
# Windows
source venv/Scripts/activate
else
# Unix-like (Linux, macOS)
source venv/bin/activate
fi
# Upgrade pip in virtual environment
echo "⬆️ Upgrading pip..."
python -m pip install --upgrade pip
# Install core dependencies first
echo "📚 Installing core dependencies..."
python -m pip install \
mcp \
structlog \
click \
pydantic \
python-dateutil \
typing-extensions
echo "☁️ Installing Google Cloud dependencies..."
python -m pip install \
google-auth \
google-cloud-logging \
google-cloud-monitoring \
google-cloud-error-reporting
# Try to install resource manager (optional)
echo "🔧 Installing optional dependencies..."
if python -m pip install google-cloud-resource-manager; then
echo "✅ Google Cloud Resource Manager installed"
else
echo "⚠️ Google Cloud Resource Manager installation failed (optional)"
fi
# Install the package itself
echo "📦 Installing gcp-mcp package..."
python -m pip install -e .
# Test the installation
echo "🧪 Testing installation..."
if python -c "import gcp_mcp; print('✅ Import successful')" 2>/dev/null; then
echo "✅ Installation successful!"
else
echo "❌ Installation test failed"
echo "💡 Try running the test manually:"
echo " source venv/bin/activate"
echo " python -c 'import gcp_mcp'"
exit 1
fi
# Test CLI
echo "🔧 Testing CLI..."
if python -m gcp_mcp.cli --help >/dev/null 2>&1; then
echo "✅ CLI working!"
else
echo "❌ CLI test failed"
exit 1
fi
echo ""
echo "🎉 Installation complete!"
echo ""
echo "📋 Next steps:"
echo "1. Get your GCP service account credentials JSON file"
echo "2. Test the server:"
echo " source venv/bin/activate # (if not already activated)"
echo " python -m gcp_mcp.cli --credentials /path/to/your/credentials.json"
echo ""
echo "🔗 For Claude Code integration, add this to your config:"
echo '{'
echo ' "mcpServers": {'
echo ' "gcp": {'
echo " \"command\": \"$PYTHON_CMD\","
echo ' "args": ['
echo ' "-m", "gcp_mcp.cli",'
echo ' "--credentials", "/path/to/your/credentials.json"'
echo ' ],'
echo " \"cwd\": \"$(pwd)\""
echo ' }'
echo ' }'
echo '}'
echo ""
echo "📖 See QUICKSTART.md for detailed instructions"