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 分