colab-forge MCP Server
by stdevMac
README.md
# colab-forge
[](package.json)
[](LICENSE)
[](docs/mcp-and-agents.md)
[](docs/recipes.md)
[](app/README.md)
[](https://stdevmac.github.io/colab-forge/)
Turn your Google Colab Pro/Pro+ GPUs into a local-first **OpenAI-compatible API**, **17-tool MCP server**, **LoRA training rig**, **React 19 Web Studio**, and **native menu-bar tray app** with zero local CUDA setup and guaranteed auto-shutdown.
Everything runs on `127.0.0.1:7860` over private OpenSSH tunnels (`colab ssh --proxy-mode`) to ephemeral Colab VMs running Python 3.13, PyTorch 2.14, and CUDA 13.0. No browser tabs to babysit, no public ngrok URLs, and no forgotten A100 burning through your Compute Units overnight.
> **Links:** [Live Landing Page](https://stdevmac.github.io/colab-forge/) · [GitHub Repo](https://github.com/stdevMac/colab-forge) · [Getting Started](docs/getting-started.md) · [Built-in & Custom Recipes](docs/recipes.md) · [MCP & AI Agents](docs/mcp-and-agents.md) · [Architecture](docs/architecture.md) · [Desktop Tray App](app/README.md)
---
## Why colab-forge?
If you already pay for Google Colab Pro or Pro+, you have access to T4, L4, A100, G4 (96 GiB Blackwell), and H100 GPUs that boot in 4 to 11 seconds. Using them from notebooks works fine for exploration, but falls apart the moment you want to kick off a LoRA run from your terminal, point the OpenAI SDK at an open-weights model, or let Claude Code generate an image or transcribe a recording.
| Without colab-forge | With colab-forge |
| :--- | :--- |
| Copy-paste code into browser cells and pray the tab doesn't disconnect | Run `colab-forge train lora` or `train script` from your terminal with live SSE loss curves and automatic `./runs/<job_id>/output/` download |
| Stand up separate scripts, ngrok tunnels, and ad-hoc FastAPI servers per model | Point any OpenAI SDK or `curl` at `http://127.0.0.1:7860/v1` across 8 GenAI modalities over private loopback SSH tunnels |
| Remember to manually disconnect runtimes before closing your laptop | Two-layer idle watchdog (local daemon + in-VM fail-safe), macOS `caffeinate` while active, and instant teardown on training completion or failure |
| Burn Compute Units on a malformed JSONL file 4 minutes into setup | Zero-CU streaming dataset pre-flight validator rejects broken `.jsonl`/`.json`/`.csv` files before provisioning a VM |
| Wire up MCP servers by hand in every coding client | `colab-forge connect claude-code` (or `cursor`, `codex`, `claude-desktop`) configures all 17 tools with an automatic `0600` `.bak` backup |
---
## What You Can Do in 60 Seconds
Start the loopback daemon once (`colab-forge start --open`), then drive your Colab GPUs from the CLI, any OpenAI client, Web Studio, or your AI coding agent:
```bash
# Fine-tune Qwen2.5-0.5B with 4-bit QLoRA on the bundled 20-row chat dataset (auto-stops VM on exit)
colab-forge train lora \
--model Qwen/Qwen2.5-0.5B-Instruct \
--dataset examples/sample_sft.jsonl \
--gpu T4 \
--steps 5
# Run any local PyTorch script on a T4 and pull /content/output back to ./runs/<job_id>/output/
colab-forge train script examples/tiny_train.py --gpu T4
# Lazy-boot multimodal GenAI workers on demand (archived automatically under ./outputs/)
colab-forge generate image "Minimalist studio photo of a mechanical keyboard" --out keyboard.png
colab-forge generate speech "Hello from Colab Forge." --voice af_heart --out hello.wav
colab-forge generate transcribe hello.wav --language en
colab-forge generate chat "Explain LoRA in two sentences." --stream
colab-forge generate music "Warm analog synthwave bassline" --duration 8 --out synth.wav
colab-forge generate video "Slow pan over a neon Tokyo alley" --frames 25 --steps 20 --out tokyo.mp4
colab-forge generate vision keyboard.png --prompt "Describe the lighting and layout"
colab-forge generate embed "Local-first GPU orchestration on Google Colab"
```
Because `colab-forge` exposes `/v1/*` on loopback, existing OpenAI SDK code works by swapping only `baseURL`:
```ts
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://127.0.0.1:7860/v1",
apiKey: process.env.COLAB_FORGE_AUTH_TOKEN || "local",
});
const res = await client.chat.completions.create({
model: "Qwen/Qwen2.5-7B-Instruct",
messages: [{ role: "user", content: "Summarize QLoRA in two sentences." }],
});
```
---
## Quickstart
### 1. Prerequisites
- **Node.js >= 22** and **pnpm**
- **`google-colab-cli`** installed and logged into your Google account:
```bash
uv tool install google-colab-cli
colab login
```
### 2. Install, Build & Check Your Environment
```bash
pnpm install
pnpm build
node dist/src/cli.js doctor
```
`doctor` verifies Node >= 22, the `colab` binary, OAuth status, your live Compute Unit balance, and the managed Ed25519 SSH key (`~/.config/colab-forge/id_ed25519`).
### 3. Start the Local Daemon & Web Studio
```bash
node dist/src/cli.js start --open
```
The daemon binds strictly to `127.0.0.1:7860`:
- **Web Studio:** `http://127.0.0.1:7860`
- **MCP Endpoint:** `http://127.0.0.1:7860/mcp`
- **OpenAI Base URL:** `http://127.0.0.1:7860/v1`
Pass `--idle <sec>` or `--idle-timeout <sec>` (for example, `colab-forge start --idle-timeout 120`) to override the default 600-second idle auto-stop window. Want to explore Web Studio and the CLI without spending a single Compute Unit? Start with `COLAB_FORGE_PROVIDER=mock`.
### Environment Variables
| Variable | Effect |
| :--- | :--- |
| `COLAB_FORGE_AUTH_TOKEN` | Optional Bearer token required on `/api/*` (except `GET /api/health` and `/api/auth/*`), `/v1/*`, `/mcp`, and `/outputs/*`. Web Studio unlocks with an `HttpOnly; SameSite=Strict` HMAC cookie (`POST /api/auth/session`); CLI commands forward the Bearer token automatically for loopback URLs. |
| `COLAB_FORGE_OUTPUTS_DIR`, `COLAB_FORGE_RUNS_DIR`, `COLAB_FORGE_STATE_DIR` | Override local output, training run, and state storage directories (falls back to the OS app-data directory when `cwd` is non-writable). |
| `COLAB_FORGE_PROVIDER=mock` | Run against the built-in zero-CU `MockComputeProvider` for local UI, CLI, and integration testing. |
| `COLAB_FORGE_ALLOW_TRUST_REMOTE_CODE=1` | Explicit opt-in required before allowing `trustRemoteCode: true` via HTTP or MCP. |
| `COLAB_FORGE_ALLOW_UNSAFE_POLICY=1` | Explicit opt-in required to weaken CostGuard policy bounds or set `idleTimeoutSec: 0` over HTTP. |
See [docs/getting-started.md](docs/getting-started.md) for the full walkthrough, Secrets Vault setup (`HF_TOKEN`, `WANDB_API_KEY`), and CostGuard defaults.
---
## Built-in Recipes (10)
Run `colab-forge recipes` to inspect all 10 built-in recipes plus any custom YAML recipes under `~/.config/colab-forge/recipes/`, complete with GPU fallback chains and live CU/hr estimates.
| Recipe ID | Kind | Capability | Default GPU Chain | Min VRAM | Endpoints / Output | Python 3.13 / PyTorch 2.14 / CUDA 13.0 Hardening |
| :--- | :---: | :---: | :--- | :---: | :--- | :--- |
| **`train-sft-lora`** | `job` | `training` | `L4 → A100 → G4 → T4` | 15 GB | `./runs/<job_id>/output/` (PEFT adapter, tokenizer, `metrics.json`) | Zero-CU streaming pre-flight validation; SM >= 8 `bf16` guard; `compute_dtype` + `prepare_model_for_kbit_training` fp16/fp32 `GradScaler` safety; `transformers` 5.x + TRL `SFTTrainer` compat |
| **`train-script`** | `job` | `training` | `T4 → L4 → A100 → G4` | 12 GB | `./runs/<job_id>/output/` (synced from `/content/output`) | Streams local script/project (`--project`), data (`--data`), and `requirements.txt` over SSH `tar`; parses JSON stdout progress lines into live SSE metrics |
| **`image-flux`** | `service` | `image` | `L4 → A100 → G4 → T4` | 15 GB | `POST /v1/images/generations` (archives PNG to `./outputs/images/`) | Runs `FLUX.1-schnell` on >= 20 GB VRAM + `HF_TOKEN`; auto-falls back to `stabilityai/sdxl-turbo` (`variant="fp16"`) when ungated or low-VRAM; SM >= 8 `bf16` guard |
| **`voice-tts`** | `service` | `tts` | `T4 → L4` | 8 GB | `POST /v1/audio/speech` (archives WAV to `./outputs/audio/`) | Kokoro-82M (`24 kHz` WAV) with auto-installed `espeak-ng` phonemizer and fallback |
| **`whisper-stt`** | `service` | `stt` | `T4 → L4` | 4 GB | `POST /v1/audio/transcriptions`, `GET /v1/models` (archives JSON to `./outputs/transcripts/`) | Decodes and resamples audio to 16 kHz mono float32 numpy; startup `libcublas.so.12` check with automatic GPU `transformers` Whisper ASR fallback on CUDA 13.0+ |
| **`llm-serve`** | `service` | `llm` | `G4 → A100 → L4 → T4` | 12 GB | `POST /v1/chat/completions`, `GET /v1/models` | Uses vLLM OpenAI server (with optional `loraPath`/`loraName` adapter mounting for 1-click "Test LoRA in Chat"); skips `vllm` install on Python 3.13+ to preserve PyTorch 2.14 / CUDA 13.0 and launches built-in FastAPI + `transformers` OpenAI server |
| **`music-gen`** | `service` | `music` | `T4 → L4` | 10 GB | `POST /api/generate/music` (streams WAV to `./outputs/music/`) | Meta MusicGen (`facebook/musicgen-small` / medium / large) text-to-music WAV synthesis with SM >= 8 `bf16` guard |
| **`video-gen`** | `service` | `video` | `L4 → A100 → G4` | 16 GB | `POST /api/generate/video` (streams MP4 to `./outputs/videos/`) | Diffusers text-to-video MP4 generation (Wan2.1 / CogVideoX / LTX-Video) with CPU offload and VRAM optimization |
| **`vision-vlm`** | `service` | `vision` | `L4 → T4 → A100 → G4` | 12 GB | `POST /api/generate/vision` (multipart up to 25 MiB or JSON) | Qwen2.5-VL multimodal image analysis (`multipart/form-data` `file`, `imagePath`, or `imageBase64`) with SM >= 8 `bf16` guard |
| **`embed-serve`** | `service` | `embeddings` | `T4 → L4` | 4 GB | `POST /v1/embeddings`, `GET /v1/models` | OpenAI-compatible dense vector embeddings (`BAAI/bge-small-en-v1.5` and curated sentence-transformers) with L2 normalization |
Deep dive and curated model list (plus custom Hugging Face causal LM IDs): [docs/recipes.md](docs/recipes.md).
---
## Live Verification Results
Core recipes, real idle auto-teardown, Web Studio, and the 17-tool Streamable HTTP MCP surface were tested end-to-end against live Google Colab GPUs (`google-colab-cli v0.8.0`, Python 3.13, PyTorch 2.14, CUDA 13.0):
- **Total Compute Units Consumed:** **`0.16 CU`** (`999.82 CU → 999.66 CU`, well under the `2.0 CU` test budget)
- **Zero-Leak Cleanup Verified After Every Test:** `Usage rate: 0.00/hr`, `Active assignments: 0`, zero lingering Colab sessions
| # | Live Test | Result | Verified Outcome |
| :-: | :--- | :---: | :--- |
| 1 | **LoRA Training (`train-sft-lora`)** | PASS | 4-bit QLoRA (`Qwen/Qwen2.5-0.5B-Instruct`, `examples/sample_sft.jsonl`, 5 steps on T4): live loss `4.7054 → 2.5196` (`vram=0.7GB`), downloaded `adapter_model.safetensors` (35.2 MB) + `adapter_config.json` + tokenizer + `metrics.json`, auto-stopped VM (`0.00/hr`) |
| 2 | **Voice TTS (`voice-tts`) + Real Idle Auto-Teardown** | PASS | Synthesized valid 93,644-byte `RIFF/WAVE` on T4 with `--idle-timeout 25`; after 40s idle, adaptive watchdog auto-terminated the T4 VM (`0` active assignments, `0.00/hr`) |
| 3 | **Audio Transcription (`whisper-stt`)** | PASS | Transcribed Test 2's 1.95s WAV via GPU `transformers` Whisper ASR fallback on CUDA 13.0, archived transcript JSON under `./outputs/transcripts/`, stopped cleanly (`0.00/hr`) |
| 4 | **Image Generation (`image-flux`)** | PASS | Auto-fell back to `stabilityai/sdxl-turbo` (`variant="fp16"`) on T4, generated valid 219,900-byte PNG archived under `./outputs/images/`, stopped cleanly (`0.00/hr`) |
| 5 | **LLM Serving (`llm-serve`)** | PASS | Served `Qwen/Qwen2.5-0.5B-Instruct` on T4 via FastAPI + `transformers` OpenAI server (ready in 43s), returned exact chat completion (`44` tokens), stopped cleanly (`0.00/hr`) |
| 6 | **Daemon + Web Studio + MCP (17 Tools) + Tray Smoke Check** | PASS (`0 CU`) | Verified `GET /api/health`, `GET /api/tray-summary`, `GET /api/events`, `GET /api/doctor`, `GET /` (React 19 Web Studio), and `POST /mcp` (`initialize`, `tools/list` returning all 17 tools, `tools/call` `colab_status`) |
---
## Empirical Colab Runtime & Compute Unit Table
Measured live against Google Colab Pro/Pro+ (`google-colab-cli` + OpenSSH proxy):
| Runtime | Boot Time | Live Burn Rate | Verified Hardware | `/content` Disk |
| :--- | :---: | :---: | :--- | :---: |
| **CPU** | ~5s | `0.08 CU/hr` | Standard CPU, 12 GiB RAM | — |
| **T4** | ~10s | `1.24 CU/hr` | Tesla T4 (15.4 GiB VRAM), 12 GiB RAM | 235.6 GB free |
| **L4** | ~11s | `2.33 CU/hr` | NVIDIA L4 (23.0 GiB VRAM), 52 GiB RAM | 235.6 GB free |
| **A100** | ~4s | `8.16 CU/hr` | A100-SXM4 (40.9 GiB VRAM), 83 GiB RAM | 236 GB free |
| **G4** | *(capacity-dependent)* | `~10.05 CU/hr` | RTX PRO 6000 Blackwell (96 GiB VRAM), 176 GiB RAM | 236 GB |
| **H100** | *(capacity-dependent)* | `~18.05 CU/hr` | NVIDIA H100 (80 GiB VRAM), 176 GiB RAM | 236 GB |
---
## Desktop Tray App (macOS & Linux, Tauri v2)
`app/` packages the `colab-forge` daemon, compiled React 19 Web Studio (`web/dist/`), and a SHA-256-verified Node.js 22 LTS sidecar into a native **Tauri v2** menu-bar / system-tray app:
- **Live 5s CU Status Badge:** Polls `GET /api/tray-summary` every 5 seconds (`Idle · 999.7 CU (0.00/hr)` or `Active · 1 GPU · 2.33 CU/hr · 8m left`).
- **Native Web Studio Window:** Opens or focuses a `1340×860` window (min `960×640`, remembers window bounds). Closing the window keeps the tray app and daemon alive in the background.
- **Instant Stop All GPUs Kill Switch:** Calls `POST /api/sessions/stop-all` directly from the menu bar to terminate active Colab VMs and SSH tunnels immediately.
- **One-Click Client Wiring & Autostart:** Copies `http://127.0.0.1:<port>/mcp`, toggles Claude Code / Cursor / Codex / Claude Desktop in **Connect a client ▸**, and manages OS login autostart (`tauri-plugin-autostart`).
- **Graceful `SIGTERM` Shutdown:** Quitting sends `SIGTERM` to the sidecar daemon and waits for active Colab GPUs and SSH tunnels to terminate cleanly before exit.
```bash
# Build TS + Web Studio + Tauri v2 bundle (embeds latest dist/ and web/dist/)
pnpm build && pnpm app:build
# Launch on macOS
open "app/src-tauri/target/release/bundle/macos/Colab Forge.app"
```
On Linux, `pnpm app:build` produces `.deb` and `.AppImage` bundles under `app/src-tauri/target/release/bundle/`. See [app/README.md](app/README.md) for Rust/system prerequisites and dev mode (`cd app && npm run dev`).
---
## Connect AI Coding Clients (17 MCP Tools)
`colab-forge connect` injects the Streamable HTTP MCP server entry (`http://127.0.0.1:7860/mcp`) into your client's config file, preserves existing servers, and writes an atomic `0600` `.bak` backup before touching disk:
```bash
# Preview changes without modifying disk
colab-forge connect claude-code --dry-run
# Configure your client
colab-forge connect claude-code
colab-forge connect cursor
colab-forge connect codex
colab-forge connect claude-desktop
# Remove cleanly later
colab-forge connect cursor --remove
```
To keep the daemon running in the background without the desktop app, install the CLI OS service (macOS LaunchAgent or Linux `systemd --user`):
```bash
colab-forge service install
colab-forge service status
colab-forge service uninstall
```
The repository also ships a cost-aware Agent Skill at [`plugin/skills/colab-forge/SKILL.md`](plugin/skills/colab-forge/SKILL.md) that teaches agents to check `colab_status` first, pick the smallest GPU tier that fits VRAM, batch warm inference calls, and shut down sessions when done. Full 17-tool reference and OpenAI SDK examples: [docs/mcp-and-agents.md](docs/mcp-and-agents.md).
---
## Custom Recipes & Zero-CU Dataset Pre-Flight
Copy [`examples/custom-recipe.yaml`](examples/custom-recipe.yaml) into `~/.config/colab-forge/recipes/*.yaml` to register your own GPU service or batch training job without writing TypeScript. Template variables (`{{sessionName}}`, `{{gpu}}`, `{{vramGb}}`, `{{remotePort}}`, `{{idleTimeoutSec}}`, `{{remoteWorkDir}}`, `{{remoteOutputDir}}`, `{{params.<name>}}`) interpolate automatically, and validated parameters are also exported as base64 JSON in `COLAB_FORGE_PARAMS_JSON` for injection-safe Python access.
```bash
mkdir -p ~/.config/colab-forge/recipes
cp examples/custom-recipe.yaml ~/.config/colab-forge/recipes/custom-embeddings.yaml
colab-forge recipes
```
For programmatic recipes with custom Zod schemas, upload specs, or progress parsers, import from the zero-side-effect `colab-forge/recipe` export (`defineRecipe`, `PreflightValidationError`, `z`, `GPU_TIERS`, `DEFAULT_REMOTE_PORT`).
Before provisioning any GPU for LoRA training, `train-sft-lora` and `POST /api/preflight/dataset` stream-validate local `.jsonl`/`.json`/`.csv` files (`text`, `messages`, `instruction`/`output`, `prompt`/`completion`, or custom `textField`) and fail fast with HTTP `400` (`PREFLIGHT_FAILED`) on missing files or malformed lines at **0 CU**.
---
## CLI Reference
| Command | Description |
| :--- | :--- |
| `colab-forge doctor [--json]` | Verify Node >= 22, `colab` CLI, OAuth, live CU balance, and Ed25519 SSH key |
| `colab-forge start [--port 7860] [--idle <sec> \| --idle-timeout <sec>] [--open]` | Start loopback daemon (Web Studio, MCP server, OpenAI gateway) with optional idle-timeout override |
| `colab-forge status [--port 7860] [--json]` | Show live CU balance, burn rate, active GPUs, orphans, countdowns, and recent jobs |
| `colab-forge recipes [--json]` | List all 10 built-in recipes and custom `~/.config/colab-forge/recipes/*.yaml` recipes with GPU chains and CU/hr |
| `colab-forge train lora --dataset <pathOrId> [--model <id>] [--epochs <n>] [--steps <n>] [--grad-accum <n>] [--lora-alpha <n>] [--max-seq-len <n>] [--no-4bit] [--text-field <col>] [--push-to-hub <repo>] [--resume <path>] [--save-checkpoints] [--json]` | Run QLoRA/LoRA fine-tuning with pre-flight validation, live streaming metrics, checkpoint sync, and auto-stop |
| `colab-forge train script <entrypoint> [--project <dir>] [--data <dir>] [--requirements <file>] [--packages <pkg>] [--env KEY=VAL] [--gpu <list>] [--json]` | Upload and run any local Python training script/project with `/content/output` sync and auto-stop |
| `colab-forge up <recipe> [--model <id>] [--param key=value] [--gpu <list>] [--idle <sec>] [--port 7860] [--json]` | Warm up a service recipe (`image-flux`, `voice-tts`, `whisper-stt`, `llm-serve`, `music-gen`, `video-gen`, `vision-vlm`, `embed-serve`, or custom YAML) |
| `colab-forge generate <image\|speech\|transcribe\|chat\|music\|video\|vision\|embed> ...` | Run multimodal GenAI inference via the local `/v1/*` and `/api/generate/*` gateways (lazy-booting the GPU service if idle) |
| `colab-forge jobs <list\|status\|logs\|cancel> [jobId]` | Inspect or cancel training jobs (`list`/`status`/`logs` fall back to local StateStore when daemon is offline) |
| `colab-forge dashboard [--port 7860] [--print]` | Open (or print with `--print`) the local Web Studio dashboard URL |
| `colab-forge stop [name \| --all]` | Stop one or all active Colab GPU sessions (and orphan VMs in offline fallback) |
| `colab-forge connect <claude-code\|cursor\|codex\|claude-desktop> [--dry-run \| --remove]` | Safely inject or remove the `colab-forge` MCP server config with atomic `0600` `.bak` backup |
| `colab-forge service <install\|status\|uninstall>` | Manage macOS LaunchAgent / Linux `systemd --user` background service |
---
## Documentation Index
| Guide | What's Inside |
| :--- | :--- |
| [Getting Started](docs/getting-started.md) | Zero-to-first-GPU walkthrough: `colab login`, `doctor`, zero-CU mock mode, first LoRA train, first GenAI call, Secrets Vault, and CostGuard safety settings |
| [Recipes Guide](docs/recipes.md) | Detailed breakdown of all 10 built-in recipes, curated live-verified LLM models, custom YAML recipes, and the `colab-forge/recipe` TypeScript plugin API |
| [MCP & AI Agents](docs/mcp-and-agents.md) | Wiring up Claude Code, Cursor, Codex, and Claude Desktop, OpenAI SDK drop-in examples, full 17-tool MCP catalog, Bearer auth, and cost-aware agent patterns |
| [Architecture](docs/architecture.md) | System diagram, SSH-first multiplexing rationale, security controls, two-layer idle watchdog, and the complete HTTP / SSE / OpenAI gateway contract |
| [Desktop Tray App](app/README.md) | Building, running, and troubleshooting the native Tauri v2 menu-bar app for macOS and Linux |
| [Live Landing Page](https://stdevmac.github.io/colab-forge/) | Interactive Recipe Workbench, GPU/CU burn estimator, and tray demo (source in [`site/index.html`](site/index.html), deployed via `.github/workflows/pages.yml`) |
| [GitHub Repository](https://github.com/stdevMac/colab-forge) | Source code, issues, and release history |
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues