Mcp Server Colab Exec

io.github.pdwi2020由 GitHub 账号 pdwi2020 发布v0.1.0更新于 Oct 24, 2026

Execute Python code on Google Colab GPU runtimes (T4/L4) from any MCP client

概览

AI 生成的概览

一个本地 MCP 服务器,可分配 Google Colab GPU 运行时并在其上执行 Python 代码,让助手无需本地 GPU 硬件即可获得 GPU 算力。

可以做什么
在 Colab GPU 运行时上执行内联 Python 代码,可选择 T4 或 L4 加速器和超时时间,并以 JSON 返回每个单元的输出、错误和 stderr。在当前工作区内执行本地 .py 文件于 Colab GPU 运行时。执行代码并把生成的图片、CSV、模型权重等产物下载到本地输出目录。
适用场景
适合助手需要运行 GPU 加速的 Python(CUDA、PyTorch、TensorFlow)或训练并导出模型,而本机没有 GPU 的情况。也适合在 Colab 运行时上快速检查 GPU 是否可用或查看 nvidia-smi 输出。
运行要求
以 Python 包形式本地运行(Python 3.10+),可通过 pip 或 uvx 安装,并在 MCP 客户端中配置为 stdio 服务器。需要一个可访问 Colab 的 Google 账号,首次运行需在浏览器中完成 Google OAuth2 授权;令牌会缓存在本地并自动刷新。需要访问 Colab 的网络连接。
安装前请注意
代码在远程 Google Colab 运行时上执行,代码或文件内容会发送给 Google。OAuth 访问令牌和刷新令牌会缓存到磁盘,应将该文件视为凭据。L4 加速器被描述为付费(premium),Colab 会限制使用配额。下载产物会向本地输出目录写入文件。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp Server Colab Exec,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mcp-server-colab-exec

MCP server that allocates Google Colab GPU runtimes (T4/L4) and executes Python code on them. Lets any MCP-compatible AI assistant — Claude Code, Claude Desktop, Gemini CLI, Cline, and others — run GPU-accelerated code (CUDA, PyTorch, TensorFlow) without local GPU hardware.

Prerequisites

  • Python 3.10+
  • A Google account with access to Google Colab
  • On first run, a browser window opens for OAuth2 consent. The token is cached at ~/.config/colab-exec/token.json for subsequent runs.

Installation

bash
pip install mcp-server-colab-exec

Or run directly with uvx:

bash
uvx mcp-server-colab-exec

Configuration

Claude Code

Add to your project's .mcp.json or ~/.claude/.mcp.json:

json
{  "mcpServers": {    "colab-exec": {      "command": "mcp-server-colab-exec"    }  }}

Or via the CLI:

bash
claude mcp add colab-exec mcp-server-colab-exec

Claude Desktop

Add to claude_desktop_config.json:

json
{  "mcpServers": {    "colab-exec": {      "command": "mcp-server-colab-exec"    }  }}

Gemini CLI

bash
gemini mcp add colab-exec -- mcp-server-colab-exec

Tools

colab_execute

Execute inline Python code on a Colab GPU runtime.

ParameterTypeDefaultDescription
codestring—Python code to execute (required)
acceleratorstring"T4"GPU type: "T4" (free) or "L4" (premium)
timeoutint300Max execution time in seconds

Returns JSON with per-cell output, errors, and stderr.

colab_execute_file

Execute a local .py file on a Colab GPU runtime.

ParameterTypeDefaultDescription
file_pathstring—Path to a local .py file (required)
acceleratorstring"T4"GPU type: "T4" (free) or "L4" (premium)
timeoutint300Max execution time in seconds

Security policy: file_path must be a .py file inside the current workspace (cwd).

colab_execute_notebook

Execute code and collect all generated artifacts (images, CSVs, models, etc.).

ParameterTypeDefaultDescription
codestring—Python code to execute (required)
output_dirstring—Local directory for downloaded artifacts (required)
acceleratorstring"T4"GPU type: "T4" (free) or "L4" (premium)
timeoutint300Max execution time in seconds

Artifacts are downloaded as a zip and extracted into output_dir. Zip members are validated before extraction to prevent path traversal and special-file writes.

Examples

Check GPU availability:

colab_execute(code="import torch; print(torch.cuda.is_available()); print(torch.cuda.get_device_name(0))")

Run nvidia-smi:

colab_execute(code="import subprocess; print(subprocess.run(['nvidia-smi'], capture_output=True, text=True).stdout)")

Train a model and download weights:

colab_execute_notebook(    code="import torch; model = torch.nn.Linear(10, 1); torch.save(model.state_dict(), '/tmp/model.pt')",    output_dir="./outputs")

Authentication

On first use, the server opens a browser window for Google OAuth2 consent. The access token and refresh token are cached at ~/.config/colab-exec/token.json. Subsequent runs use the cached token and refresh it automatically.

The OAuth2 client credentials are the same ones used by the official Google Colab VS Code extension ([email protected]). They are intentionally public.

Troubleshooting

"GPU quota exceeded" — Colab has usage limits. Wait and retry, or use a different Google account.

"Timed out creating kernel session" — The runtime took too long to start. Retry — Colab sometimes has delays during peak usage.

"Authentication failed" — Delete ~/.config/colab-exec/token.json and re-authenticate.

OAuth browser window doesn't open — Ensure you're running in an environment with a browser. For headless servers, authenticate on a machine with a browser first and copy the token file.

License

MIT

来源:README.md,提交 b67d0d7

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分