Smart Colab MCP Bridge
Allows execution of Python code on a Google Colab runtime, including resource probing, file management, and support for libraries like PyTorch, scikit-learn, and pandas.
Click on "Deploy 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., "@Smart Colab MCP BridgeRun Python code to train a model on Colab GPU"
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.
Smart Colab MCP Bridge (Experimental)
This repository contains an experimental setup that connects Claude Desktop to a Google Colab runtime using a lightweight Flask server exposed via ngrok. The goal is to enable controlled, resource-aware remote execution of Python code on Colab (CPU/GPU) while orchestrating tasks locally via Claude Desktop.
This repository reflects the system as originally built, without later hardening or refactoring.
๐ System Architecture
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
โ Claude Desktop โ โ Google Colab โ
โ (Reasoning) โ โ (Compute) โ
โโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโ
โ โ
JSON-RPC (Stdio) Flask Server
โ โ
โโโโโโโโโผโโโโโโโโโ โโโโโโโโโโโผโโโโโโโโโโ
โ Local MCP Agentโโโโโโโโโโโบโ ngrok Tunnel โ
โ (State/Config) โ HTTP โ (Public URL) โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโHow it works:
Local MCP Agent: Lightweight Python script runs on your PC via Claude Desktop. Handles timeouts, checkpointing, and file management.
Remote Executor: Colab notebook exposes a Flask API via ngrok tunnel.
The Bridge: Claude sends code โ Local Agent โ Colab executes โ Results return to Claude.
Important: Claude Desktop automatically launches MCP servers. The Colab notebook must be started manually to provide the ngrok endpoint.
Related MCP server: JupyterMCP
โจ Features
Remote Execution: Run Pandas, PyTorch, Scikit-Learn on Colab GPU/CPU
Smart Timeouts:
Quick Mode (2 min): Variable checks, light computation
Long Mode (10 min): Model training, dataset downloads
Chunked Operations: Break massive loops into safe batches to avoid timeouts
Local Persistence:
Checkpoint resumability for long-running tasks
Automatic file downloads from Colab
/contentto local machine
Environment Probing: Query RAM, GPU, and installed packages before execution
Memory Management: Cleanup endpoint to free RAM without restarting runtime
๐ Repository Structure
smart-colab-mcp/
โโโ agent/
โ โโโ mcp_smart_colab_v2.py # Local MCP bridge (reads from env vars)
โโโ colab/
โ โโโ smart_colab_executor.ipynb # Colab backend (Flask + ngrok)
โโโ config/
โ โโโ claude_desktop_config.example.json
โโโ requirements.txt
โโโ README.md๐ Setup Instructions
Phase 1: Colab Setup
Open
colab/smart_colab_executor.ipynbin Google ColabSet your ngrok auth token:
!ngrok authtoken YOUR_TOKEN_HEREGet a free token at ngrok.com/dashboard
Run all cells in the notebook
Copy the public HTTPS URL printed (e.g.,
https://xxxx-xx-xx.ngrok-free.app)Keep the notebook running - closing it kills the server
Phase 2: Local Setup
git clone https://github.com/G-karthick0501/Smart-colab-MCP.git
cd Smart-colab-MCP
pip install -r requirements.txtRequired packages:
mcp- Model Context Protocolrequests- HTTP clientflask- Web framework (Colab-side)pyngrok- ngrok Python wrapper (Colab-side)
Phase 3: Configure Claude Desktop
Location: %APPDATA%\Claude\claude_desktop_config.json (Windows)
Example configuration:
{
"mcpServers": {
"smart-colab": {
"command": "C:\\Path\\To\\Python.exe",
"args": ["C:\\Path\\To\\agent\\mcp_smart_colab_v2.py"],
"env": {
"COLAB_URL": "https://your-ngrok-url.ngrok-free.app",
"LOCAL_SAVE_DIR": "C:\\Path\\To\\results",
"CHECKPOINT_DIR": "C:\\Path\\To\\checkpoints"
}
}
}
}Important:
Use double backslashes (
\\) in Windows pathsReplace
COLAB_URLwith your actual ngrok URL from Phase 1Create
LOCAL_SAVE_DIRandCHECKPOINT_DIRfolders beforehandRestart Claude Desktop after editing config
๐ ๏ธ Available Tools
Tool | Description | Timeout |
| Verify ngrok tunnel is active | 10s |
| Get GPU/RAM/packages info | 30s |
| Execute short Python snippets | 2 min |
| Execute heavy tasks (training/downloads) | 10 min |
| Process loops in batches with resume support | 5 min/batch |
| List files in Colab | 30s |
| Download file to | 5 min |
| Free RAM/GPU memory | 30s |
| Show runtime variables and shapes | 15s |
| Retrieve saved checkpoint data | Instant |
๐ Verification & Troubleshooting
Check Running Processes
Windows:
tasklist /fi "imagename eq python.exe"Expected output:
Image Name PID Session Mem Usage
Claude.exe 1234 Console 450,000 K
python.exe 5678 Console 80,000 K โ Memory MCP (if configured)
python.exe 9012 Console 60,000 K โ Colab MCPTest Colab Health Endpoint
curl https://your-ngrok-url/healthExpected response:
{
"status": "ok",
"uptime_minutes": 15,
"memory_available_gb": 10.5,
"memory_used_pct": 15.2
}Common Issues
Problem | Cause | Solution |
| Colab notebook not running | Re-run notebook cells |
| Missing env variable | Check Claude Desktop config |
ngrok URL changed | Notebook restarted | Update config with new URL |
| Wrong endpoint path | Verify URL includes |
Timeout on execution | Code takes >10 min | Use |
Memory errors | Colab RAM full | Call |
Files not found | Wrong Colab path | Check |
๐ Security Considerations
Known Risks (Not Hardened)
Arbitrary Code Execution: The
/executeendpoint runs any Python code without validationNo Authentication: ngrok URL is publicly accessible while notebook runs
No Sandboxing: Code executes with full Colab runtime permissions
Single-Threaded: No execution locking; concurrent requests may conflict
Public Exposure: ngrok tunnel can be discovered if URL leaks
Recommended Practices
For Users:
Never share ngrok URLs publicly
Review all code before execution
Use dedicated Google account for Colab experiments
Terminate sessions immediately after use
Monitor Colab activity dashboard
Not Implemented (Future Work):
Request signing / HMAC authentication
IP whitelisting
Execution locks (
threading.Lock)Dangerous operation restrictions
Rate limiting
๐ Known Limitations
These are intentionally documented and tracked for future work:
Execution Model: Synchronous, blocks Flask worker thread
No Concurrency Control: Parallel requests may cause race conditions
Output Size Limits: Very large outputs may exceed transport limits
Chunked Execution: Assumes simple loop bodies; complex indentation may break
No Persistence: Session state lost when Colab runtime disconnects
Session Lifetime: Depends on Colab's idle timeout (~90 minutes)
ngrok Rotation: URL changes every session (unless paid plan)
Flask Host Binding: Should use
host="0.0.0.0"for reliability
๐ฎ Future Work
Planned improvements (tracked as GitHub Issues):
Security & Auth:
Add request signing / API key authentication
Implement IP whitelisting
Restrict dangerous Python operations (
os.system,subprocess, etc.)Add structured logging with execution IDs
Reliability:
Add execution locking mechanism (
threading.Lock)Implement job queueing for concurrent requests
Improve chunked execution robustness (handle complex indentation)
Add
/shutdownendpoint for clean server termination
Features:
Persist remote state externally (Google Drive sync)
Replace ngrok with self-hosted tunnel (Tailscale, Cloudflare)
Support multiple runtimes (Kaggle, VM, local Docker)
Add streaming stdout for long operations
Implement auto-reconnect on Colab disconnect
๐ How MCP Communication Works
โโโโโโโโโโโโโโโโโโโ
โ Claude Desktop โ Reads config.json
โ โ Spawns MCP servers as subprocesses
โโโโโโโโโโฌโโโโโโโโโ
โ
โ JSON-RPC via stdin/stdout
โ
โโโโโโโโโโผโโโโโโโโโ
โ MCP Server โ Python process on your PC
โ (mcp_smart_ โ Reads COLAB_URL from environment
โ colab_v2.py) โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โ HTTP POST/GET
โ
โโโโโโโโโโผโโโโโโโโโ
โ ngrok Tunnel โ Public HTTPS โ Colab VM
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ Flask Server โ Running in Colab notebook
โ (Colab Runtime) โ Executes Python via exec()
โโโโโโโโโโโโโโโโโโโExample JSON-RPC message:
// Request from Claude
{
"jsonrpc": "2.0",
"method": "run_code_quick",
"params": {"code": "print(2 + 2)"},
"id": 1
}
// Response from MCP
{
"jsonrpc": "2.0",
"result": {
"success": true,
"stdout": "4\n",
"execution_time_sec": 0.12
},
"id": 1
}Key Points:
MCP servers start automatically when Claude Desktop launches
Communication between Claude and MCP is local (stdin/stdout)
Communication between MCP and Colab is HTTP (via ngrok)
Colab notebook must be manually started and kept running
๐ Recommended .gitignore
# Python
venv/
__pycache__/
*.pyc
*.pyo
# Local storage
results/
checkpoints/
memory_db/
memory_backups/
# IDE
.vscode/
.idea/
*.swp
*.swo
# Secrets
*.token
.env๐ฏ Status & Motivation
Current Status:
โ Experimental proof-of-concept
โ Single-user, local use only
โ Not hardened for security
โ Not production-ready
Why This Exists: This project was built to explore:
Practical MCP orchestration patterns
Remote execution without SSH complexity
Managing Colab's transient runtime constraints
Long-running ML workflows with checkpointing
Separation of concerns: reasoning (Claude) vs compute (Colab)
What Makes This Different:
Execution Taxonomy: Explicit quick/long/chunked modes
Local Checkpointing: Resume after crashes or disconnects
Probe-First Discipline: Check resources before execution
Failure Containment: Proper timeout handling and error surfaces
๐ Additional Resources
๐ค Contributing
Contributions welcome via Issues and Pull Requests!
Before submitting:
Remove personal paths and tokens
Test with fresh Colab session
Document any new endpoints or tools
Update this README if architecture changes
Good First Issues:
Add execution locks to prevent concurrent runs
Implement basic request authentication
Improve error messages and logging
Add unit tests for MCP tools
โ ๏ธ Disclaimer
This code executes arbitrary Python remotely. It is not safe for multi-user or public deployment. Use only in trusted environments with trusted code.
The user is responsible for:
Reviewing all code before execution
Managing ngrok URL privacy
Understanding execution permissions
Monitoring Colab usage and costs
The authors provide:
Educational example code
Documentation of known risks
No warranties or guarantees
Use at your own risk. Not recommended for production use.
๐ Acknowledgments
Inspired by doobidoo/mcp-memory-service patterns
Thanks to the Anthropic team for the MCP protocol
๐ License
MIT License - free to use with attribution
Maintained by: G-karthick0501
Repository: github.com/G-karthick0501/Smart-colab-MCP
Last Updated: January 2026
This server cannot be deployed
Maintenance
Related MCP Connectors
Build and supervise fleets of agents from Claude Code, Codex or Cursor. Connects over OAuth.
- mcp-serverOAuthai.cdbx
Build Apps and run code in 30 languages โ sandboxed, with persistent sessions for agent loops.
Connect Claude to Fathom meeting recordings, transcripts, and summaries
Persistent memory for Claude Code and Cursor. Stop re-explaining your project every session.
Related MCP Servers
- 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.103MIT
- AlicenseAqualityFmaintenanceConnects Jupyter Notebook to Claude AI for direct notebook control and code execution.11130MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to autonomously manage Google Colab GPU sessions, submit and monitor training jobs, and debug/fix issues via an encrypted tunnel without requiring a browser tab.MIT
- AlicenseNot gradedqualityFmaintenanceEnables 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