
Colab-MCP (unofficial)
io.github.amgallego8由 GitHub 账号 amgallego8 发布v0.1.0更新于 Oct 27, 2026
Unofficial MCP server for Google Colab: runtimes, code, long jobs, files and notebooks.
概览
非官方 MCP 服务器,让助手端到端使用 Google Colab:创建 GPU/TPU 运行时、运行代码、编辑笔记本、跑长任务并传输文件。
- 可以做什么
- 创建、查看、重启和停止 Colab 运行时,包括 GPU/TPU 会话与用量信息
- 在运行时上执行代码或脚本,内核状态在多次调用间保留
- 创建和编辑本地 .ipynb 笔记本,逐单元格或整体运行,并转换为脚本
- 启动、查看日志、列出和取消长时间后台任务
- 上传下载文件与文件夹,列出和删除虚拟机上的文件,获取日志
- 可选:在虚拟机上挂载 Google Drive,并通过需手动开启的 Drive 工具管理云端笔记本
- 适用场景
- 适合让助手在 Colab 机器上做真实计算而无需浏览器标签页:训练任务、批处理脚本、GPU 实验,或逐单元格迭代笔记本。也适合需要长时间后台任务、轮询日志并把结果取回本地的流程。
- 运行要求
- 仅在 macOS 或 Linux 本地运行(不支持 Windows)。需要 uv 和官方 google-colab-cli,并用你的 Google 账号完成一次登录。需设置 COLAB_MCP_WORKDIR 指定唯一可读写的本地文件夹。可选:COLAB_MCP_ENV_FILE 指向密钥文件;COLAB_MCP_DRIVE=1 并完成一次 Google 登录以启用 Drive 工具。
安装
在 SourceWeft 中
- 打开 控制台中的 Colab-MCP (unofficial),将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Colab-MCP
An MCP server that lets an AI agent (Claude, or any MCP client) use Google Colab end to end: create and stop GPU/TPU runtimes, run code, work in notebooks cell by cell, launch long background jobs, and move files and folders in and out of the VM.
It is a thin, safe layer over Google's official Colab CLI (google-colab-cli). It does not reimplement Colab and does not depend on a browser tab.
🇪🇸 Resumen en español al final de este archivo.
Quick start
You need uv and the official Colab CLI, signed in once (macOS or Linux):
That registers the server in Claude Code, and uvx downloads it from PyPI the first time. For Claude Desktop, other clients, secrets and the optional Drive tools, see Install.
Status
- Tested against a simulated CLI (118 checks, plus 129 for Drive against a simulated Drive API, 28 for the Drive mount and 17 for local cleanup;
tests/): a real MCP client talks to the server over stdio and the code that normally runs on the VM is executed for real in a sandbox folder. - Validated live once. On a real Colab session (macOS, Claude as the client): creating a runtime, running code, a long background job with log polling, mounting Drive from the chat (below) and stopping the session, with one real batch workload (10 items, 0 errors). That is a single run, not a benchmark.
- Published on PyPI as
colab-cli-mcp0.1.0. The published package was installed in a clean environment (pip, anduvx) and listed its 42 tools over stdio. That check ran on Linux; use of theuvxroute with Claude on macOS has not been checked yet. - Not yet validated live: the Google Drive API tools (
drive_*), notebook execution cell by cell, folder uploads and downloads, and the behaviours listed under Known unknowns. Other MCP clients (Cursor, Codex, Windsurf) and Linux are untested. - Linux and macOS only (the Colab CLI does not support Windows).
Tools (42 + 8 optional Drive tools)
Typical flows:
- Interactive:
colab_ensure_session(gpu="T4")→colab_notebook_create→ add cells →colab_notebook_run_cellone by one (variables persist) → read outputs →colab_stop. - Batch:
colab_upload_dir→colab_job_start("python -u train.py")→ pollcolab_job_logs→colab_download_dir→colab_stop.
Google Drive projects and notebooks are a separate, opt-in feature (below). Deliberately not included anywhere: sign-in through a tool, colab auth, repl, console, ssh, edit. They are interactive and cannot work through a tool call.
Security model
- Local paths are confined to
COLAB_MCP_WORKDIR.../, absolute paths and symlinks that escape are rejected before anything runs. - Secrets never reach the model.
COLAB_MCP_ENV_FILEpoints to a localNAME=valuefile. The model only passes names (secrets=["OPENROUTER_API_KEY"]); values go to the kernel with--envand are scrubbed from every result. Known limit: while the command runs, the value is visible to other local users in the process list, because the CLI takes it as an argument. - No shell. The CLI is run with an argument list. Session names, GPU types, package specifiers and job ids are validated. Everything user-controlled that is embedded in code for the VM goes through
repr(). - Folder transfers are guarded. Uploads skip
.git, caches, symlinks and likely secrets (.env,*.pem,*.key…); downloads reject archives with paths that escape the target (zip-slip) or exceed a size limit. - No hard deletes on your computer.
colab_notebook_deletemoves the file to.colab-mcp-trash/.colab_rmonly touches the VM and refuses root-like paths. - Output is clipped to
COLAB_MCP_MAX_OUTPUTcharacters, and terminal colour codes (tracebacks) are stripped. - Code you run executes on Google's machines under your account and spends your compute units. Stop sessions you no longer need.
Big projects and Drive on the VM
For big datasets, checkpoints or results that must survive the session, mount Google Drive on the VM. This is separate from the optional "Drive notebooks" feature below and uses the Colab CLI's own sign-in.
- Mount it from the chat, no terminal.
colab_drive_mount_startruns the officialcolab drivemountin a pseudo-terminal (the CLI itself never opens a browser; it only prints a link and waits for Enter), opens Google's approval page in your browser. The link is not repeated in the chat (it contains your account e-mail); it is only returned if the browser could not be opened or withshow_link=true. You click Allow (the agent never sees credentials or codes) and tell the agent;colab_drive_mount_finishthen sends the Enter the CLI was waiting for andcolab_drive_statusconfirms. Onlyhttps://*.google.comlinks are ever opened, a pending mount is killed after 15 minutes, and there is at most one per session. If you prefer,colab drivemount -s SESSIONin a terminal still works. Mounting gives code running on that VM access to your whole Drive (Colab cannot scope it); only mount when you need it and stop the session afterwards. - The agent calls
colab_drive_project_dir("my-project"), which creates/content/drive/MyDrive/Colab-MCP/my-projectand returns the path. Datasets, checkpoints and outputs go there. - Stop the session when done. Files in that Drive folder remain; everything else on the VM is lost.
Guardrail: the file tools (colab_upload*, colab_download*, colab_ls, colab_rm) refuse any Drive path outside /content/drive/MyDrive/Colab-MCP/ (folder name configurable with COLAB_MCP_DRIVE_PROJECTS), including .., relative and case tricks. colab_drive_status never lists your files.
Residual risk, stated plainly: once Drive is mounted, any code that runs on the VM (colab_exec, colab_run, jobs, notebook cells) can read and change all of your Drive; the path guard only covers this server's file tools, and it cannot see symlinks created on the VM. Mount only when you need it, review the code you run, and stop the session afterwards.
Where things live (and how little stays on your computer)
Local footprint rules (footprint.py):
- Transfer zips are removed right after use and swept after 1 hour; saved plots after 2 days (
COLAB_MCP_IMAGE_DAYS); locally "deleted" notebooks after 7 days (COLAB_MCP_TRASH_DAYS,0= keep); working copies of Drive notebooks after 24 h (COLAB_MCP_DRIVE_COPY_HOURS,0= keep) and immediately when you save. The sweep runs when the server starts and oncolab_local_cleanup. - Only files inside
.colab-mcp/and.colab-mcp-trash/are ever removed. Symlinks are not followed. Your own notebooks and data are never touched. - Guards before downloads: at least
COLAB_MCP_MIN_FREE_GB(default 5) must stay free on the disk and the working folder may not exceedCOLAB_MCP_WORKDIR_MAX_GB(default 20,0= no cap).colab_local_footprintshows the numbers. Keep big data on the VM or in Drive and download only results.
Google Drive: projects and notebooks (opt-in)
Off by default. With COLAB_MCP_DRIVE=1 (the installer sets it when you set Drive up) these tools appear, and only these:
Layout in your Drive: Colab-MCP/<project>/<notebook>.ipynb. The Google permission (drive.file) only reaches files and folders this app created, so your existing "Colab Notebooks" folder and everything else stay invisible to it.
A skill that keeps the agent to exactly this lives in skills/colab-drive-notebooks/SKILL.md: copy that folder to ~/.claude/skills/ (Claude Code) or add it as a skill in your client.
Who is responsible for what
Nobody shares credentials. Each user signs in themselves, and the token lives only on their own disk. You choose once between two OAuth clients (below); this project never sees your token. The model never sees a sign-in link, code or token.
Quick start (every user)
From PyPI:
From a clone of this repository, bash install.sh asks "Set up Drive now?", runs the one-time choice below, and registers the server with the Drive tools enabled. Manually:
login walks you through creating your own Google Cloud "Desktop app" client (about 10 minutes, once, free; steps below). When you give it the path of the JSON you downloaded it stores it for you (0600). You answer to Google for your project. After that, signing in is just: a link opens in your browser, you click Allow, done. There is no code to paste.
No shared one-click client is shipped yet. If this repository reaches 1,000 stars, the maintainer intends to publish one (a ready-made client so that signing in needs no Google Cloud setup at all). That is a plan, not a promise. The code for it already exists: if a build ships colab_cli_mcp/shared_client.json, login offers a menu with shared and own.
The shared client is never used without an explicit choice (a terminal answer or --shared). Your choice is remembered in ~/.config/colab-mcp/drive/preference.json. From then on, when a Drive tool needs access and there is no valid token (first use, or after the 7-day expiry of apps in Testing mode), the server itself opens the browser consent page and waits for your click; you then repeat the request. Sign-in, the drive.file scope, the token file and every guardrail are identical in both cases.
Then leave per-call approval on for drive_notebook_delete in your MCP client — that prompt is the real human confirmation; the server cannot force it. uvx --from colab-cli-mcp colab-cli-mcp-drive status (or uv run colab-cli-mcp-drive status from a clone) shows what is configured.
To leave: colab-cli-mcp-drive logout (deletes the token and revokes it at Google), and remove the app at https://myaccount.google.com/permissions if revocation could not be confirmed.
Creating your own client (what login asks you to do)
- In the Google Cloud console create a project and enable the Google Drive API (guide).
- Configure the consent screen / Google Auth Platform (guide): under Audience pick External and add yourself under Test users; under Data Access → Add or Remove Scopes add only
.../auth/drive.file. - Google Auth platform → Clients → Create Client → Desktop app (Google's steps). Download the JSON and give its path to
login.
For the maintainer: publishing a shared client
Create the client as above (ideally in a dedicated Google account and project), then place the JSON at colab_cli_mcp/shared_client.json and commit it on purpose (git add -f; the file is git-ignored by default). Desktop-app client secrets are not confidential by design, but the project, its consent screen (support email, privacy policy link) and any Google verification requirements become yours. See TERMS.md.
Threat model (what this does and does not protect)
Residual risks, stated plainly. "Completely secure" is not a claim anyone can make; this is what remains:
- A prompt-injected or mistaken agent can still create junk notebooks (rate-limited) or trash a notebook this server created if you approve the call. They stay recoverable in the Drive trash.
- The confirmation-by-name check stops accidents, not a model that is determined to repeat the name; the human approval prompt in your client is the real control.
- Anyone who can read your user account's files can use your token until you log out. Disk encryption and a locked account are on you.
- Notebooks you create can contain code that will run later in Colab with your account; review what you open.
- In Testing mode Google expires refresh tokens after 7 days for external apps, so you may need to log in again weekly.
- If a Drive folder named
Colab-MCPis also created by code running on a Drive-mounted VM, Drive can end up with two folders of that name that this tool treats separately (⚠️ not verified). Prefer one route per project. - Not yet run against live Google Drive (see Known unknowns).
Env: COLAB_MCP_DRIVE (enable), COLAB_MCP_DRIVE_COPY_HOURS, COLAB_MCP_DRIVE_DIR (default ~/.config/colab-mcp/drive), COLAB_MCP_DRIVE_CLIENT, COLAB_MCP_DRIVE_TOKEN, COLAB_MCP_DRIVE_AUDIT, COLAB_MCP_DRIVE_FOLDER (default Colab-MCP).
Install
From PyPI (recommended)
Needs uv (curl -LsSf https://astral.sh/uv/install.sh | sh). The official Colab CLI must be installed and signed in first:
Claude Code:
Claude Desktop (claude_desktop_config.json; use the full path to uvx if the app cannot find it, see which uvx):
Other MCP clients: any client that can start a stdio server can run uvx colab-cli-mcp (untested, see Status).
Optional secrets file (outside any repository, readable only by you) and the Drive tools:
Add -e COLAB_MCP_ENV_FILE="$HOME/.config/colab-mcp/secrets.env" to the command above (or the same key under env in the JSON). For the optional Drive tools add -e COLAB_MCP_DRIVE=1 and sign in once as described in Google Drive.
Every person who uses it repeats these steps with their own Google account: the sign-in token is personal and must not be shared.
From source (to modify the code)
bash install.sh (macOS/Linux) from a clone asks before installing anything, signs you in to Colab, and registers the server with Claude Code (or prints the Claude Desktop config). The manual steps are below.
Optional secrets file (outside any repository, readable only by you):
Register in Claude Code:
Register in Claude Desktop (claude_desktop_config.json):
Every person who uses it repeats these steps with their own Google account: the sign-in token is personal and must not be shared.
Environment variables
How notebooks work
Notebooks are ordinary .ipynb files inside the working directory, edited locally with nbformat, so editing needs no runtime. colab_notebook_run_cell sends one cell to the runtime through colab exec; the kernel keeps its variables between calls, and the cell's output (text, errors, a displayed plot) is written back into the notebook. Cells are addressed by id (stable) or index. Plots are saved under .colab-mcp/images/.
colab_exec with a .ipynb file runs the whole notebook and the CLI saves <name>_output.ipynb beside it.
Known unknowns (to confirm against live Colab)
These come from reading the CLI's source and docs. The live run described under Status did not cover them:
- Kernel variables persisting across
execcalls (the source reuses the same kernel id, so it should). - Cell success/failure detection relies on
get_ipython().run_cellbeing available in the Colab kernel. - Whether
--output-imagesaves every image form (it handles PNG/JPEG display data). - The real upload size limit (the CLI sends a file in a single request; the 100 MB cap is a conservative guess).
- Whether Colab Secrets (
userdata) are readable in the kernel when running through the CLI — undocumented. Usesecrets=[...]instead. - Google Drive (opt-in, see below): the Colab MIME type
application/vnd.google.colaboratorywas not found in Google's Drive documentation. The server checks what Drive stored after each creation and undoes it if it differs, but this has not been run against real Drive yet. - Whether a Google Cloud app that stays unverified can be used by its owner without the 7-day refresh-token expiry of "Testing" mode (Google's docs say refresh tokens of external apps in Testing expire after 7 days; the rules for unverified apps "In production" were not confirmed).
Develop
The SDK pin mcp<2 is intentional: 2.x renamed FastMCP to MCPServer.
Terms of use and privacy
See TERMS.md: no server and no data collection by the maintainer, what is stored locally, user responsibilities, who answers to Google under each sign-in option, and the no-warranty clause.
License
Apache License 2.0 — see LICENSE. Copyright 2026 the Colab-MCP contributors (amgallego8). The official Colab CLI this project wraps is a separate work, also Apache-2.0, and is not included here.
Resumen en español
Servidor MCP para que un agente use Google Colab de punta a punta: crear y detener runtimes con GPU/TPU, ejecutar código, trabajar en cuadernos celda por celda, lanzar trabajos largos en segundo plano y mover archivos y carpetas hacia y desde la VM. Envuelve el Colab CLI oficial de Google.
- Estado: probado con un CLI simulado (292 comprobaciones: 118 + 129 + 28 + 17). Validado una vez en vivo en una sesión real de Colab (macOS y Claude): crear runtime, ejecutar código, un trabajo largo con logs y montar Drive desde el chat. Sin validar en vivo: las herramientas
drive_*, cuadernos celda por celda, carpetas, otros clientes (ver «Known unknowns»). - Seguridad: las rutas locales quedan confinadas a
COLAB_MCP_WORKDIR; las claves viven en un archivo local y nunca se devuelven al modelo; no hay shell; los borrados de cuadernos van a una papelera recuperable. - Instalación: desde PyPI con
uvx colab-cli-mcp(o desde el código coninstall.sh); cada persona repite los pasos de «Install» con su propia cuenta de Google. El token de sesión es personal. - Google Drive (opcional): carpetas de proyecto y cuadernos de Colab en
Colab-MCP/<proyecto>/de tu Drive (crear, abrir, guardar, borrar a la papelera), nada más. Creas una sola vez tu propio cliente de Google (todavía no se publica un cliente compartido); después el propio servidor abre el navegador cuando haga falta y tú solo pulsas «Permitir» (el código y el token nunca pasan por el chat). El permiso esdrive.file: solo ve lo que esta herramienta crea. Tu computador queda casi vacío: los temporales se limpian solos y lo pesado va al disco de la VM o a Drive. Hay una skill (skills/colab-drive-notebooks) que limita al agente a eso. Ver «Google Drive» y el modelo de amenazas, con sus riesgos residuales. Aún sin probar contra la API de Drive real. - Costo: lo que ejecutes consume tus unidades de cómputo de Colab. Detén las sesiones que no uses.
来源:README.md,提交 084b8b9
工具
0版本历史
1- v0.1.0最新Oct 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分