A seamless bridge connecting local AI coding agents (Google Antigravity, Gemini CLI, Claude Code, Cursor, Windsurf) and local terminal scripts to persistent Google Colab cloud sessions via the Model Context Protocol (googlecolab/colab-mcp).
| Challenge with Raw Colab MCP | How Colab Agent Bridge Solves It |
|---|---|
New Tabs Opened Repeatedly: One-shot tools trigger open <url> on every execution. |
Zero New Tabs: Runs a persistent background daemon that reuses your open Colab tab. |
| Lost In-Memory State: One-off scripts disconnect and lose session continuity. | Shared Kernel Memory: Variables, loaded models, and imports remain in memory across calls. |
| Silent Disconnections: Agents fail if the browser tab hasn't finished connecting. | Automatic Tab Verification: Automatically detects connection status (--check) and guides you. |
| Complex Setup: Manual socket configuration and proxy management. | 1-Click Agent Skill & CLI: Native integration with Antigravity and a simple colab-exec CLI. |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Google Colab Web Notebook (Browser Tab - Opened ONCE) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Persistent WebSocket (ws://localhost:56595)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Colab Bridge Daemon (colab-daemon) โ
โ Maintains persistent MCP transport & shared kernel session โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Fast Local Control API (http://localhost:56594)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Coding Agents (Antigravity, Claude, Gemini) / CLI โ
โ Executes code on-demand in ~2s with zero browser disruption โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Clone and install dependencies via uv (recommended) or pip:
git clone https://github.com/LucasSilvaFerreira/colab-agent-bridge.git
cd colab-agent-bridge
./install.shOr install in editable mode:
uv pip install -e .
# or
pip install -e .Check if your Colab tab is currently connected:
colab-exec --checkIf no tab is open, the tool will provide the connection URL and can open it once in your browser.
# Inline snippet
colab-exec -c "import torch; print('CUDA Available:', torch.cuda.is_available())"
# Execute a Python script
colab-exec -f examples/02_gpu_benchmark.py
# Inspect all cells in the active notebook
colab-exec --cellsTested on Google Colab with examples/02_gpu_benchmark.py (
- Standard CPU:
2.008s - NVIDIA L4 GPU (24 GB VRAM):
0.201s(~10x speedup)
This repository includes a ready-to-use skill in .agents/skills/colab-mcp/:
- For Current Workspace: Automatically discovered in
.agents/skills/colab-mcp/. - For All Workspaces (Global):
mkdir -p ~/.gemini/config/skills/colab-mcp cp -r .agents/skills/colab-mcp/* ~/.gemini/config/skills/colab-mcp/
Once installed, your agent will automatically activate the skill whenever you ask:
- "Run this PyTorch training benchmark in Google Colab"
- "Check available GPU VRAM in Colab"
- "Add a cell to my open Colab notebook and display the results"
You can also use colab_bridge in your own Python automation scripts:
from colab_bridge import execute, check_status
# 1. Verify connection
connected, status = check_status()
print(f"Colab Connected: {connected}")
# 2. Execute code
success, output, result = execute("""
import os, platform
print(f"Running on: {platform.platform()}")
print(f"Storage: {os.statvfs('/').f_bavail * 4096 / (1024**3):.2f} GB free")
""")
print(output)Under the hood, Google Colab provides 7 native MCP tools managed by the bridge:
| Tool | Parameters | Description |
|---|---|---|
add_code_cell |
cellIndex, language, code |
Inserts a new code cell and returns newCellId. |
add_text_cell |
cellIndex, content |
Inserts a Markdown/LaTeX cell. |
run_code_cell |
cellId |
Runs the cell in the cloud kernel and captures stdout/stderr. |
get_cells |
cellIndexStart, cellIndexEnd, includeOutputs |
Retrieves cell content and execution streams. |
update_cell |
cellId, content |
Updates existing cell code or text. |
delete_cell |
cellId |
Deletes a cell by ID. |
move_cell |
cellId, cellIndex |
Re-orders cells in the notebook. |
colab-agent-bridge/
โโโ .agents/skills/colab-mcp/ # AI Agent Skill (Antigravity, Gemini CLI)
โ โโโ SKILL.md # Skill definition & execution runbook
โ โโโ references/
โ โ โโโ colab_tools.md # Complete Colab MCP tools reference
โ โโโ scripts/
โ โโโ colab_daemon.py # WebSocket + HTTP control daemon
โ โโโ colab_exec.py # CLI client
โ โโโ run_colab_code.py # Standalone runner
โโโ src/colab_bridge/ # Core Python package
โ โโโ __init__.py # Public API exports
โ โโโ daemon.py # Daemon engine
โ โโโ client.py # Python client functions
โ โโโ cli.py # CLI entry point (colab-exec)
โโโ examples/ # Ready-to-run examples
โ โโโ 01_hello_colab.py # System & directory check
โ โโโ 02_gpu_benchmark.py # PyTorch CUDA tensor benchmark
โ โโโ 03_shared_state.py # Shared kernel state verification
โโโ install.sh # 1-step installer
โโโ pyproject.toml # Package configuration
โโโ README.md # Documentation
Apache License 2.0. See LICENSE for details.