# Cube MCP Server

MCP server for EdgescaleAI Cube operations via Teleport and Apollo Container Registry (ACR) deployments.

## Prerequisites

- [Teleport client (tsh)](https://goteleport.com/download/) installed
- `kubectl` installed
- `helm` installed
- `docker` with buildx (for image builds)
- `aws` CLI (for Apollo publishing)
- Access to EdgescaleAI Teleport (`edgescaleai.teleport.sh`)

### Apollo Container Registry (ACR) Setup

To use the deployment tools, add these to your `~/.bashrc` or `~/.zshrc`:

```bash
export APOLLO_CLIENT="<your-client-id>"
export APOLLO_SECRET="<your-client-secret>"
```

Then restart your terminal or run `source ~/.bashrc`.

## Installation

```bash
cd cube-mcp
pip install -e .
```

## Usage with Claude Code

Add to your Claude Code settings (`.claude/settings.json` or global settings):

```json
{
  "mcpServers": {
    "cube": {
      "command": "cube-mcp"
    }
  }
}
```

Or run directly with uvx:

```json
{
  "mcpServers": {
    "cube": {
      "command": "uvx",
      "args": ["--from", "/path/to/cube-mcp", "cube-mcp"]
    }
  }
}
```

## Available Tools

### cube_login

Login to a Cube cluster via Teleport. Opens browser for SSO authentication.

**Parameters:**
- `cluster` (required): Cube cluster name (e.g., `staging-int`, `staging-pre-prod`)
- `proxy` (optional): Teleport proxy URL (defaults to `edgescaleai.teleport.sh`)

**Example:**
```
"Connect me to the staging-int Cube"
```

### cube_list

List all available Cube clusters accessible via Teleport.

**Example:**
```
"What Cubes are available?"
```

### cube_status

Get the status of the connected Cube node using `kubectl describe node`.

**Example:**
```
"What's the status of the Cube?"
```

---

## ACR / Apollo Deployment Tools

### helm_deploy

**The main deployment tool.** Builds, packages, pushes, and publishes a Helm chart to Apollo.

Handles the full pipeline:
1. Login to ACR (Docker + Helm)
2. Build and push Docker image (if Dockerfile found)
3. Bump Chart.yaml version
4. Package Helm chart
5. Push to ACR
6. Publish to Apollo via Lambda

**Parameters:**
- `chart_path` (optional): Path to chart directory. Auto-detected if not specified.
- `version` (optional): Exact version to use (e.g., "1.0.0"). Auto-bumps if not specified.
- `bump` (optional): "patch" (default), "minor", or "major"
- `app_version` (optional): Docker image tag version
- `skip_docker` (optional): Skip Docker build even if Dockerfile exists
- `dry_run` (optional): Show what would happen without doing it

**Examples:**
```
"Deploy my chart"                    → auto-detect everything, bump patch
"Deploy my chart as version 1.0.0"   → use exact version
"Deploy my chart, bump minor"        → bump minor version
"Deploy the chart at ./charts/foo"   → specify path
"Deploy my chart, dry run"           → preview without changes
```

### acr_login

Manually login to Apollo Container Registry (Docker + Helm).

**Example:**
```
"Login to ACR"
```

### acr_get_token

Get an OAuth2 token from ACR (for debugging).

**Example:**
```
"Get ACR token"
```

## Quick Start

### Cube Operations
1. Ask Claude to list available Cubes: *"What Cubes can I connect to?"*
2. Connect to a Cube: *"Connect me to staging-int"*
3. Check status: *"Show me the Cube status"*

### Helm Deployments
1. Navigate to your chart directory
2. Ask Claude: *"Deploy my chart"*
3. Or with options: *"Deploy my chart, bump minor version"*

## Manual Setup (if needed)

```bash
# Login to Teleport
tsh login --proxy=edgescaleai.teleport.sh

# List available Cubes
tsh kube ls

# Connect to a Cube
tsh kube login staging-int

# Verify
kubectl get nodes
```

## Development

```bash
# Install in development mode
pip install -e .

# Run directly
python -m cube_mcp.server
```

## Releasing Updates to Developers

### 1. Bump the version

Edit `pyproject.toml` and update the version number:

```toml
[project]
version = "0.1.1"  # Bump this
```

**Version format:** `MAJOR.MINOR.PATCH`
- PATCH (0.1.0 → 0.1.1): Bug fixes
- MINOR (0.1.0 → 0.2.0): New features
- MAJOR (0.1.0 → 1.0.0): Breaking changes

### 2. Build the wheel

```bash
pip3 install build  # Only needed once
python3 -m build
```

This creates `dist/cube_mcp-X.X.X-py3-none-any.whl`

### 3. Distribute to developers

Send them:
- The new `.whl` file
- `DEVELOPER_SETUP.md` (for new developers)

### 4. Developer installation

**New version (recommended):**
```bash
pip install cube_mcp-0.1.1-py3-none-any.whl
```

**Same version (force reinstall):**
```bash
pip install cube_mcp-0.1.0-py3-none-any.whl --force-reinstall
```

> **Note:** If the version number doesn't change, pip will say "Requirement already satisfied" and won't update. Either bump the version or have developers use `--force-reinstall`.
