colab-cli-mcp
Enables execution of Python code on Google Colab GPU/TPU runtimes and provides management of Colab sessions, kernels, files, and logs.
Allows mounting a Google Drive in a Colab session to access and transfer files from the VM.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@colab-cli-mcpStart a T4 GPU session and run this Python code"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
colab-cli-mcp
Google 公式の google-colab-cli をラップした
リモート MCP サーバーです。ブラウザ・ws://localhost・SSH トンネルを一切使わずに、
Notion AI などの MCP クライアントから Colab の GPU/TPU ランタイムで Python を実行できます。
Notion AI ──HTTPS(OAuth)──▶ colab-cli-mcp ──subprocess──▶ colab CLI ──HTTPS──▶ Colab runtimeMCP ツール
ツール | 対応する CLI | 説明 |
|
| ランタイム作成(gpu: T4/L4/G4/H100/A100、tpu: v5e1/v6e1、無指定は CPU) |
|
| セッション一覧(runtime token は返しません) |
|
| 状態確認 |
|
| ランタイム解放 |
|
| カーネル再起動 |
|
| Python コード実行 |
|
| uv / pip でパッケージ導入 |
|
| VM 上のファイル一覧 |
|
| VM 上のテキストを取得 |
|
| VM 上にテキストを書き込み |
|
| 大きい/バイナリファイル用 |
|
| ファイル削除 |
|
| Google Drive マウント |
|
| 実行履歴 |
|
| 同じ VM にブラウザから接続する URL |
|
| CLI バージョン |
実装メモ:
install_packagesとmount_driveはcolab exec経路で実行しています。colab install/colab drivemount自体は正常に動作しますが、colab-cli 0.6.0 のrun_automation()にはcolab execが持っているセッション存在チェック (if not s) がなく、セッションがローカル状態から消えているとAttributeError: 'NoneType' object has no attribute 'url'という生のトレースバックを返します。 exec 経路にそろえることで、エラー処理を統一し、タイムアウト指定と 完了マーカーによる成否判定を可能にしています。
Google Drive のマウントについて: Drive の認可が未取得の場合、 どちらの方式でもヘッドレスでは完結しません。
colab drivemountの認証フックはopen("/dev/tty")での手動確認を要求するため、TTY のないコンテナでは 600 秒のタイムアウトまでハングします。exec 経路ならtimeout秒で 打ち切って原因を含むエラーを返します。初回はsession_notebook_urlの URL を ブラウザで開き、Drive アクセスを一度許可してください。
repl / console / edit / ssh / pay / update は対話専用なので意図的に除外しています。
Related MCP server: mcp-colab-gpu
2 層の認証
MCP クライアント → 本サーバー:
--auth token|none|google|github|oidc本サーバー → Colab: Colab CLI 自身の
--colab-auth oauth2|adc
1. MCP 側(Notion AI から繋ぐ)
colab-cli-mcp \
--transport http --host 0.0.0.0 --port 8080 --path /mcp \
--auth google \
--base-url https://colab-mcp.example.com \
--oauth-client-id xxxxx.apps.googleusercontent.com \
--oauth-client-secret GOCSPX-xxxxx \
--allowed-identity you@example.comGoogle Cloud Console のリダイレクト URI には <base-url>/auth/callback を登録します。
公開が必要なエンドポイント: /mcp, /.well-known/oauth-authorization-server,
/.well-known/oauth-protected-resource/mcp, /authorize, /token, /register,
/consent, /auth/callback。
警告:
--allowed-identityを省略すると、OAuth を通った 任意の Google アカウントが あなたの Colab で任意コードを実行できます。必ず自分のアドレス(または@domain)を指定してください。
2. Colab CLI 側(ヘッドレスサーバーでの初回認証)
CLI はブラウザなしでも認証できます(auth.py の remote flow / token_usage=remote)。
サーバー上で 1 回だけ手で実行してトークンを作ります。
# コンテナ内で 1 回だけ
docker compose run --rm --entrypoint colab colab-cli-mcp sessions
# → 表示された URL を手元のブラウザで開き、
# 表示された認可コードを貼り付ける(~/.config/colab-cli/token.json に保存)ADC を使う場合は --colab-auth adc にして、
gcloud auth application-default login \
--scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory~/.config/colab-cli/ と workspace は 必ず volume で永続化してください(compose 済み)。
Docker
GHCR の公式イメージを使う(ビルド不要)
main への push ごとに GitHub Actions が linux/amd64 + linux/arm64 の
マルチアーキイメージを自動で公開しています。
docker pull ghcr.io/animationsaver/colab-cli-mcp:latestタグ: latest / main / sha-<short> / リリース時は 1.2.3・1.2。
cp .env.example .env
# .env を編集(最低限 COLAB_CLI_MCP_AUTH_TOKEN を openssl rand -hex 24 で埋める)
docker compose -f docker-compose.ghcr.yml up -d
# 初回のみ: Colab CLI の認証(トークンは volume に残るので 1 回だけ)
docker compose -f docker-compose.ghcr.yml run --rm --entrypoint colab colab-cli-mcp sessions動作確認:
curl -X POST http://127.0.0.1:8080/mcp \
-H "Authorization: Bearer $COLAB_CLI_MCP_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}'イメージを更新するときは docker compose -f docker-compose.ghcr.yml pull && \ docker compose -f docker-compose.ghcr.yml up -d。
ソースからビルドする
export COLAB_CLI_MCP_BASE_URL=https://colab-mcp.example.com
export COLAB_CLI_MCP_OAUTH_CLIENT_ID=...
export COLAB_CLI_MCP_OAUTH_CLIENT_SECRET=...
export COLAB_CLI_MCP_ALLOWED_IDENTITY=you@example.com
docker compose up -d --buildTLS は Caddy / nginx / Cloudflare Tunnel などで前段終端してください。
環境変数
COLAB_CLI_MCP_ + TRANSPORT / HOST / PORT / PATH / AUTH / AUTH_TOKEN(csv) /
BASE_URL / OAUTH_CLIENT_ID / OAUTH_CLIENT_SECRET / OAUTH_SCOPE(csv) /
OAUTH_REDIRECT_PATH / OAUTH_NO_CONSENT / OIDC_CONFIG_URL / ALLOWED_IDENTITY(csv) /
EXECUTABLE / COLAB_AUTH / COLAB_OAUTH_CONFIG / COLAB_STATE / WORKSPACE
設計上のポイント
ローカル FS のサンドボックス: upload/download のローカル側は workspace 配下に限定(
..は拒否)。セッション単位のロック: Colab カーネルは同時 1 リクエストなので
asyncio.Lockで直列化。秘密情報の非公開:
sessions.jsonのtoken(runtime proxy token)はツール出力から除去。出力の正規化: rich の枠線・ANSI・アップデートバナーを除去してから返す。
既知の上流バグ: 長時間実行は google-colab-cli#14 (80 秒で無応答)の影響を受ける可能性があります。
run_codeのtimeoutは余裕を持たせてください。
開発
uv sync
uv run ruff check . && uv run ruff format --check .
uv run pytest -qMultiple Google accounts
Every account gets its own HOME under <workspace>/accounts/<name>/, so its
token.json, sessions.json, settings.json and history stay separate. The
default account keeps the container HOME (~/.config/colab-cli), so an
already authenticated deployment keeps working with no migration.
Tool | Purpose |
| Show configured accounts, which one is active, and their sessions |
| Make an account active for every later call (creates it if new) |
| Sign an account in: first call returns the Google URL, second call takes the code |
| Delete a named account credentials, sessions and history |
Sign in a second account without a terminal:
switch_account { "account": "work" }authorize_account {}-> returnsauthorization_urlOpen the URL, approve, copy the code Google shows
authorize_account { "code": "4/0A..." }->signed_in: true
Google はコードを「その URL を発行したサインインフロー」に紐付けるため、URL を表示した CLI
プロセスはプロンプトで待機したまま保持され、2 回目の呼び出しが同じプロセスへコードを入力
します。待機は 15 分(PENDING_PROMPT_TTL)で失効するので、過ぎた場合は 2. からやり直して
ください。
Start the server on a given account with --colab-account NAME or
COLAB_CLI_MCP_COLAB_ACCOUNT=NAME.
Google allows one Colab runtime assignment per account, so separate accounts are also the way to run more than one runtime at a time.
Session lifetime and the keep-alive daemon
colab new starts a detached keep-alive process (colab keep-alive, recorded as
keep_alive_pid) that pings /tun/m/<endpoint>/keep-alive/ every 60 seconds. It
is detached from any terminal, so closing the shell does not end the session -
but it lives inside this container, so docker compose down, a restart or an
image update kills it, and Colab then idles the runtime out.
The daemon also stops on its own after 24 hours (time_limit_reached), when the
local session record disappears (session_not_found), when the endpoint changes
(endpoint_mismatch), or after two consecutive 4xx replies
(consecutive_4xx_errors, usually a missing colaboratory OAuth scope). Check
session_log for the keep_alive_stopped event and its reason.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityDmaintenanceLocal-first MCP server for controlling Google Colab as a development, shell, file, and training runtime, with tools for notebook editing, GPU acceleration, and file transfer.596Apache 2.0
- AlicenseAqualityCmaintenanceEnables MCP-compatible AI assistants to run Python code on Google Colab GPU/TPU runtimes, supporting accelerators like T4, A100, H100, with background execution and Google Drive integration.102MIT
- AlicenseAqualityDmaintenanceMCP server that allocates Google Colab GPU runtimes (T4/L4) and executes Python code on them. Lets any MCP-compatible AI assistant run GPU-accelerated code without local GPU hardware.37MIT
- Alicense-qualityFmaintenanceEnables Claude Code to execute shell commands, Python code, and file transfers on a Google Colab T4 GPU via an MCP server, bridging the GPU gap for AI coding agents.5MIT
Related MCP Connectors
Remote MCP for Gemini upgrade evals, prompt regressions, output diffs, and eval receipts.
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
Create, browse, remix, collaborate on, and run durable AI workflow nodes from MCP hosts.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/nmt3325/colab-cli-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server