kaggle-shell-mcp 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kaggle_shell_mcp-0.2.0/LICENSE +21 -0
- kaggle_shell_mcp-0.2.0/PKG-INFO +215 -0
- kaggle_shell_mcp-0.2.0/README.md +180 -0
- kaggle_shell_mcp-0.2.0/pyproject.toml +79 -0
- kaggle_shell_mcp-0.2.0/setup.cfg +4 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/__init__.py +4 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/accelerators.py +124 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/batch.py +554 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/client.py +190 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/config.py +328 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/launcher.py +459 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/remote/__init__.py +1 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/remote/worker_template.py +925 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/server.py +537 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_mcp/sync.py +76 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/PKG-INFO +215 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/SOURCES.txt +25 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/dependency_links.txt +1 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/entry_points.txt +4 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/requires.txt +11 -0
- kaggle_shell_mcp-0.2.0/src/kaggle_shell_mcp.egg-info/top_level.txt +1 -0
- kaggle_shell_mcp-0.2.0/tests/test_accelerators.py +49 -0
- kaggle_shell_mcp-0.2.0/tests/test_batch.py +86 -0
- kaggle_shell_mcp-0.2.0/tests/test_mcp_stdio.py +40 -0
- kaggle_shell_mcp-0.2.0/tests/test_slots.py +96 -0
- kaggle_shell_mcp-0.2.0/tests/test_sync.py +54 -0
- kaggle_shell_mcp-0.2.0/tests/test_worker_utils.py +106 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dat Nguyen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kaggle-shell-mcp
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Turn free 12h Kaggle Dual-T4 GPUs into live remote terminals & detached job runners for AI Agents via MCP.
|
|
5
|
+
Author-email: Dat Nguyen <nquocdat06.work@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp
|
|
9
|
+
Project-URL: Issues, https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp/issues
|
|
10
|
+
Keywords: mcp,model-context-protocol,kaggle,gpu,ai-agent,remote-terminal,claude-code,cursor,pytorch
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: mcp>=1.2.0
|
|
25
|
+
Requires-Dist: httpx>=0.27.0
|
|
26
|
+
Requires-Dist: kaggle>=2.0.0
|
|
27
|
+
Requires-Dist: six>=1.16.0
|
|
28
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# kaggle-shell-mcp (`kgsh`) ⚡
|
|
37
|
+
|
|
38
|
+
**Turn free 12h Kaggle GPUs into multi-slot live remote terminals & offline competition runners for AI Agents via MCP.**
|
|
39
|
+
|
|
40
|
+
[](https://pypi.org/project/kaggle-shell-mcp/)
|
|
41
|
+
[](https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp/actions/workflows/ci.yml)
|
|
42
|
+
[](./LICENSE)
|
|
43
|
+
[](https://www.python.org/)
|
|
44
|
+
[](https://modelcontextprotocol.io/)
|
|
45
|
+
|
|
46
|
+
[**Tiếng Việt (Vietnamese Guide)**](./docs/README.vi.md) · [**Architecture**](./ARCHITECTURE.md) · [**Changelog**](./CHANGELOG.md) · [**Contributing**](./CONTRIBUTING.md)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Why `kaggle-shell-mcp`?
|
|
51
|
+
|
|
52
|
+
Kaggle provides ~30 hours/week of free GPU compute, yet its official API (`kaggle kernels push`) only runs fire-and-forget batch scripts, while community SSH notebooks require manual browser clicks, `ngrok` accounts, and manual `CUDA` environment repairs.
|
|
53
|
+
|
|
54
|
+
**`kaggle-shell-mcp`** (CLI: **`kgsh`**) gives AI Agents and developers a unified compute bridge:
|
|
55
|
+
|
|
56
|
+
- **One-Line Zero-Setup**: Install directly from PyPI (`pip install kaggle-shell-mcp` or `uvx`). Uses **only** `KAGGLE_USERNAME` and `KAGGLE_KEY` (`KGAT_...` bearer token, legacy key, or existing `~/.kaggle/kaggle.json`). No `ngrok` account or local VPN client needed.
|
|
57
|
+
- **Dual Concurrent GPU VMs (`4 × Tesla T4 = 60 GB VRAM`)**: Provision up to **2 parallel Kaggle GPU sessions** (`slot="1,2"`) and pin individual jobs via `gpu_ids="0"` / `"1"` to run **4 isolated GPU experiments simultaneously**.
|
|
58
|
+
- **Full Hardware & Hub Support**: Target `NvidiaTeslaT4` (`2×15 GB`), `NvidiaL4`, `NvidiaL4x4` (`96 GB`), `NvidiaRtxPro6000` (`96 GB`), `NvidiaH100`, `TpuV5E8` / `TpuV6E8`, or `cpu`, with native `competition_sources` and zero-copy Kaggle Hub `model_sources` mounts.
|
|
59
|
+
- **Offline Competition Mode + Live Host SSE Logs**: When high-end competition hardware (`L4x4`, `RTX Pro 6000`) forces `enable_internet=False`, `kgsh` bundles Linux wheels (`kaggle_wheelhouse`) + local code (`kaggle_batch_run`) and streams real-time logs via Kaggle's Host SSE feed (`kaggle_batch_logs`) without opening a browser.
|
|
60
|
+
- **100% Native CUDA + Safe-Drain Watchdogs**:
|
|
61
|
+
- Pure-stdlib Python PTY & job daemon runs inside the Kernel runtime—preserving Conda, PyTorch, `PATH`, and `LD_LIBRARY_PATH` automatically, while compacting `\r` `tqdm` progress bars.
|
|
62
|
+
- Sends `SIGTERM` at `11h35m` (`8h35m` on TPU) to flush checkpoints and exits cleanly (`exit 0`) at `11h40m` (`8h40m` on TPU) so Kaggle commits your `/kaggle/working` (20 GB) output snapshot before the hard reaper hits.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Architecture Overview
|
|
67
|
+
|
|
68
|
+
```mermaid
|
|
69
|
+
flowchart LR
|
|
70
|
+
subgraph Local["Local Machine"]
|
|
71
|
+
Agent["AI Agent / Developer"]
|
|
72
|
+
MCP["kgsh (MCP Server & CLI)\nFile-Locked Multi-Slot Store"]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
subgraph LiveMode["Mode 1: Live Interactive Slots (slot='1', '2' — Internet ON)"]
|
|
76
|
+
Tunnel["Auto-Healing Cloudflared\n(or Userspace Tailscale)"]
|
|
77
|
+
Daemon["Stdlib RPC Daemon\nStateful PTY + GPU-Pinned Jobs"]
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
subgraph OfflineMode["Mode 2: Competition Batch Slots (L4x4 / RTX Pro 6000 — Internet OFF)"]
|
|
81
|
+
Batch["Offline Runner\nWheelhouse + Atomic Code Bundle"]
|
|
82
|
+
SSE["Kaggle Host SSE Feed\n(Real-Time Logs w/o Internet)"]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
Agent <-->|"MCP stdio / CLI"| MCP
|
|
86
|
+
MCP <-->|"256-bit Bearer HTTPS"| Tunnel
|
|
87
|
+
Tunnel --> Daemon
|
|
88
|
+
MCP -->|"kernels_push"| Batch
|
|
89
|
+
SSE -->|"Windowed Stream"| MCP
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See [**ARCHITECTURE.md**](./ARCHITECTURE.md) for deep-dive internals on slot isolation, PTY sentinel framing, and bounded SSE streaming.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Quickstart (30 Seconds)
|
|
97
|
+
|
|
98
|
+
### Option A: Zero-Install MCP via `uvx` (Recommended for Agents)
|
|
99
|
+
|
|
100
|
+
Add directly to your **Claude Desktop / Cursor / Windsurf / Antigravity** `mcp_config.json`—no manual virtual environment required:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"mcpServers": {
|
|
105
|
+
"kgsh": {
|
|
106
|
+
"command": "uvx",
|
|
107
|
+
"args": ["--from", "kaggle-shell-mcp", "kgsh"],
|
|
108
|
+
"env": {
|
|
109
|
+
"KAGGLE_USERNAME": "your_kaggle_username",
|
|
110
|
+
"KAGGLE_KEY": "KGAT_your_api_token_here"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Or register in **Claude Code CLI** in one line:
|
|
118
|
+
```bash
|
|
119
|
+
claude mcp add kgsh -e KAGGLE_USERNAME=your_user -e KAGGLE_KEY=KGAT_your_token -- uvx --from kaggle-shell-mcp kgsh
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Option B: Install `kgsh` Globally via `pip` / `uv`
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
pip install kaggle-shell-mcp
|
|
126
|
+
# or isolated CLI install:
|
|
127
|
+
uv tool install kaggle-shell-mcp
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Credentials are discovered automatically from any of:
|
|
131
|
+
1. `KAGGLE_USERNAME` + `KAGGLE_KEY` environment variables,
|
|
132
|
+
2. `.env` in your current working directory or `~/.kaggle_mcp/.env`, or
|
|
133
|
+
3. Your existing `~/.kaggle/kaggle.json` file.
|
|
134
|
+
|
|
135
|
+
*(Generate an API token at [kaggle.com/settings](https://www.kaggle.com/settings) → **API** → **Generate New Token**. Phone verification is required on Kaggle to unlock GPU accelerators.)*
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## MCP Tools Reference (12 Tools)
|
|
140
|
+
|
|
141
|
+
| Tool | Purpose |
|
|
142
|
+
| :--- | :--- |
|
|
143
|
+
| `kaggle_up` | Boot 1 or 2 parallel headless workers (`slot="1"`, `"2"`, or `"1,2"`, `accelerator`, `competition`, `mount_datasets`, `mount_models`, opt-in `idle_timeout_min`) |
|
|
144
|
+
| `kaggle_status` | Inspect live GPU/VRAM telemetry, RAM, disk, and kernel states across `slot="all"` or a specific slot (auto-cleans stale sessions) |
|
|
145
|
+
| `kaggle_down` | Gracefully stop `slot="1"`, `"2"`, or `"all"` (`exit 0`) immediately to save GPU quota; optionally pull `/kaggle/working` |
|
|
146
|
+
| `term_exec` | Run bash commands in a persistent stateful PTY on `slot` (`cwd`, exports, and virtualenvs persist across calls) |
|
|
147
|
+
| `job_spawn` | Launch detached background jobs on `slot` with optional `gpu_ids` (`CUDA_VISIBLE_DEVICES="0"` or `"1"`) |
|
|
148
|
+
| `job_list` | List active and finished background jobs on `slot` with PID, GPU assignment, runtime, and log size |
|
|
149
|
+
| `job_logs` | Read tail lines of a background job log on `slot` (with regex `grep` and automatic `tqdm` `\r` cleanup) |
|
|
150
|
+
| `job_kill` | Send `SIGTERM` or `SIGKILL` to a background job's process group on `slot` and release VRAM |
|
|
151
|
+
| `fs_sync` | `push` local folders (auto-skipping `.git`, `.venv`, `__pycache__`) or `pull` remote checkpoints/logs on `slot` |
|
|
152
|
+
| `kaggle_wheelhouse` | Download Linux `manylinux_x86_64` binary `.whl` packages and publish a private Dataset for no-internet runs |
|
|
153
|
+
| `kaggle_batch_run` | Submit an offline/competition batch job (`NvidiaL4x4`, `NvidiaRtxPro6000`, `TpuV5E8`, `enable_internet=False`) with automatic code bundling |
|
|
154
|
+
| `kaggle_batch_logs` | Stream live or completed logs via Kaggle's Host SSE endpoint—even when container internet is disabled |
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Standalone CLI Usage (`kgsh`)
|
|
159
|
+
|
|
160
|
+
### Workflow 1: Single or Dual-VM Interactive GPU Shell
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Boot BOTH Kaggle Dual-T4 VMs in parallel (4x T4 = 60 GB total VRAM)
|
|
164
|
+
kgsh up -s 1,2
|
|
165
|
+
|
|
166
|
+
# Interactive shell commands on specific slots
|
|
167
|
+
kgsh exec -s 1 "nvidia-smi"
|
|
168
|
+
kgsh push ./my_project /kaggle/working -s 1
|
|
169
|
+
kgsh push ./my_project /kaggle/working -s 2
|
|
170
|
+
|
|
171
|
+
# Run 4 independent GPU experiments simultaneously across 2 VMs x 2 GPUs
|
|
172
|
+
kgsh spawn -s 1 --gpus 0 "python my_project/train.py --lr 1e-4" --name exp1
|
|
173
|
+
kgsh spawn -s 1 --gpus 1 "python my_project/train.py --lr 3e-4" --name exp2
|
|
174
|
+
kgsh spawn -s 2 --gpus 0 "python my_project/train.py --lr 5e-4" --name exp3
|
|
175
|
+
kgsh spawn -s 2 --gpus 1 "python my_project/train.py --lr 1e-3" --name exp4
|
|
176
|
+
|
|
177
|
+
# Monitor status & shut down all GPU VMs when finished
|
|
178
|
+
kgsh status
|
|
179
|
+
kgsh down -s all
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Workflow 2: Offline Kaggle Competition (`L4x4` / `RTX Pro 6000` with Internet OFF)
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# 1. (Once) Build an offline Linux wheelhouse dataset
|
|
186
|
+
kgsh wheels peft accelerate bitsandbytes --slug lora-deps --py 312
|
|
187
|
+
|
|
188
|
+
# 2. Bundle local project & launch offline on competition hardware
|
|
189
|
+
kgsh batch-run "torchrun --nproc_per_node=4 solve.py" \
|
|
190
|
+
--path ./comp_solution \
|
|
191
|
+
-a l4x4 \
|
|
192
|
+
--comp arc-prize-2026 \
|
|
193
|
+
--wheels your_username/kgsh-wheels-lora-deps \
|
|
194
|
+
--model qwen-lm/qwen2.5/transformers/7b-instruct/1
|
|
195
|
+
|
|
196
|
+
# 3. Stream live logs from Host SSE without opening a browser
|
|
197
|
+
kgsh batch-logs -s batch-1 --tail 80
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Chaining Runs Longer Than 12 Hours
|
|
203
|
+
|
|
204
|
+
1. Save periodic checkpoints into `/kaggle/working/checkpoints/` inside your training script (and handle `SIGTERM` for the `11h35m` drain signal).
|
|
205
|
+
2. After Session 1 exits cleanly at `11h40m`, start Session 2 with `chain_previous_output=True` (`kgsh up --chain`). Kaggle mounts Session 1's output directly under `/kaggle/input/` at internal datacenter speeds.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Responsible Use
|
|
210
|
+
|
|
211
|
+
`kaggle-shell-mcp` is built for legitimate machine learning experimentation, model training, and competition workflows on your own Kaggle account. Respect [Kaggle's Terms of Service](https://www.kaggle.com/terms): do not use Kaggle notebooks for crypto-mining, public web hosting, or network proxying, and shut down active slots (`kgsh down -s all`) when finished. Note that running 2 concurrent GPU slots deducts 2 hours of GPU quota per wall-clock hour.
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
Released under the [MIT License](./LICENSE).
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# kaggle-shell-mcp (`kgsh`) ⚡
|
|
2
|
+
|
|
3
|
+
**Turn free 12h Kaggle GPUs into multi-slot live remote terminals & offline competition runners for AI Agents via MCP.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/kaggle-shell-mcp/)
|
|
6
|
+
[](https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp/actions/workflows/ci.yml)
|
|
7
|
+
[](./LICENSE)
|
|
8
|
+
[](https://www.python.org/)
|
|
9
|
+
[](https://modelcontextprotocol.io/)
|
|
10
|
+
|
|
11
|
+
[**Tiếng Việt (Vietnamese Guide)**](./docs/README.vi.md) · [**Architecture**](./ARCHITECTURE.md) · [**Changelog**](./CHANGELOG.md) · [**Contributing**](./CONTRIBUTING.md)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Why `kaggle-shell-mcp`?
|
|
16
|
+
|
|
17
|
+
Kaggle provides ~30 hours/week of free GPU compute, yet its official API (`kaggle kernels push`) only runs fire-and-forget batch scripts, while community SSH notebooks require manual browser clicks, `ngrok` accounts, and manual `CUDA` environment repairs.
|
|
18
|
+
|
|
19
|
+
**`kaggle-shell-mcp`** (CLI: **`kgsh`**) gives AI Agents and developers a unified compute bridge:
|
|
20
|
+
|
|
21
|
+
- **One-Line Zero-Setup**: Install directly from PyPI (`pip install kaggle-shell-mcp` or `uvx`). Uses **only** `KAGGLE_USERNAME` and `KAGGLE_KEY` (`KGAT_...` bearer token, legacy key, or existing `~/.kaggle/kaggle.json`). No `ngrok` account or local VPN client needed.
|
|
22
|
+
- **Dual Concurrent GPU VMs (`4 × Tesla T4 = 60 GB VRAM`)**: Provision up to **2 parallel Kaggle GPU sessions** (`slot="1,2"`) and pin individual jobs via `gpu_ids="0"` / `"1"` to run **4 isolated GPU experiments simultaneously**.
|
|
23
|
+
- **Full Hardware & Hub Support**: Target `NvidiaTeslaT4` (`2×15 GB`), `NvidiaL4`, `NvidiaL4x4` (`96 GB`), `NvidiaRtxPro6000` (`96 GB`), `NvidiaH100`, `TpuV5E8` / `TpuV6E8`, or `cpu`, with native `competition_sources` and zero-copy Kaggle Hub `model_sources` mounts.
|
|
24
|
+
- **Offline Competition Mode + Live Host SSE Logs**: When high-end competition hardware (`L4x4`, `RTX Pro 6000`) forces `enable_internet=False`, `kgsh` bundles Linux wheels (`kaggle_wheelhouse`) + local code (`kaggle_batch_run`) and streams real-time logs via Kaggle's Host SSE feed (`kaggle_batch_logs`) without opening a browser.
|
|
25
|
+
- **100% Native CUDA + Safe-Drain Watchdogs**:
|
|
26
|
+
- Pure-stdlib Python PTY & job daemon runs inside the Kernel runtime—preserving Conda, PyTorch, `PATH`, and `LD_LIBRARY_PATH` automatically, while compacting `\r` `tqdm` progress bars.
|
|
27
|
+
- Sends `SIGTERM` at `11h35m` (`8h35m` on TPU) to flush checkpoints and exits cleanly (`exit 0`) at `11h40m` (`8h40m` on TPU) so Kaggle commits your `/kaggle/working` (20 GB) output snapshot before the hard reaper hits.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Architecture Overview
|
|
32
|
+
|
|
33
|
+
```mermaid
|
|
34
|
+
flowchart LR
|
|
35
|
+
subgraph Local["Local Machine"]
|
|
36
|
+
Agent["AI Agent / Developer"]
|
|
37
|
+
MCP["kgsh (MCP Server & CLI)\nFile-Locked Multi-Slot Store"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
subgraph LiveMode["Mode 1: Live Interactive Slots (slot='1', '2' — Internet ON)"]
|
|
41
|
+
Tunnel["Auto-Healing Cloudflared\n(or Userspace Tailscale)"]
|
|
42
|
+
Daemon["Stdlib RPC Daemon\nStateful PTY + GPU-Pinned Jobs"]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
subgraph OfflineMode["Mode 2: Competition Batch Slots (L4x4 / RTX Pro 6000 — Internet OFF)"]
|
|
46
|
+
Batch["Offline Runner\nWheelhouse + Atomic Code Bundle"]
|
|
47
|
+
SSE["Kaggle Host SSE Feed\n(Real-Time Logs w/o Internet)"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
Agent <-->|"MCP stdio / CLI"| MCP
|
|
51
|
+
MCP <-->|"256-bit Bearer HTTPS"| Tunnel
|
|
52
|
+
Tunnel --> Daemon
|
|
53
|
+
MCP -->|"kernels_push"| Batch
|
|
54
|
+
SSE -->|"Windowed Stream"| MCP
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
See [**ARCHITECTURE.md**](./ARCHITECTURE.md) for deep-dive internals on slot isolation, PTY sentinel framing, and bounded SSE streaming.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quickstart (30 Seconds)
|
|
62
|
+
|
|
63
|
+
### Option A: Zero-Install MCP via `uvx` (Recommended for Agents)
|
|
64
|
+
|
|
65
|
+
Add directly to your **Claude Desktop / Cursor / Windsurf / Antigravity** `mcp_config.json`—no manual virtual environment required:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"mcpServers": {
|
|
70
|
+
"kgsh": {
|
|
71
|
+
"command": "uvx",
|
|
72
|
+
"args": ["--from", "kaggle-shell-mcp", "kgsh"],
|
|
73
|
+
"env": {
|
|
74
|
+
"KAGGLE_USERNAME": "your_kaggle_username",
|
|
75
|
+
"KAGGLE_KEY": "KGAT_your_api_token_here"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or register in **Claude Code CLI** in one line:
|
|
83
|
+
```bash
|
|
84
|
+
claude mcp add kgsh -e KAGGLE_USERNAME=your_user -e KAGGLE_KEY=KGAT_your_token -- uvx --from kaggle-shell-mcp kgsh
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Option B: Install `kgsh` Globally via `pip` / `uv`
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install kaggle-shell-mcp
|
|
91
|
+
# or isolated CLI install:
|
|
92
|
+
uv tool install kaggle-shell-mcp
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Credentials are discovered automatically from any of:
|
|
96
|
+
1. `KAGGLE_USERNAME` + `KAGGLE_KEY` environment variables,
|
|
97
|
+
2. `.env` in your current working directory or `~/.kaggle_mcp/.env`, or
|
|
98
|
+
3. Your existing `~/.kaggle/kaggle.json` file.
|
|
99
|
+
|
|
100
|
+
*(Generate an API token at [kaggle.com/settings](https://www.kaggle.com/settings) → **API** → **Generate New Token**. Phone verification is required on Kaggle to unlock GPU accelerators.)*
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## MCP Tools Reference (12 Tools)
|
|
105
|
+
|
|
106
|
+
| Tool | Purpose |
|
|
107
|
+
| :--- | :--- |
|
|
108
|
+
| `kaggle_up` | Boot 1 or 2 parallel headless workers (`slot="1"`, `"2"`, or `"1,2"`, `accelerator`, `competition`, `mount_datasets`, `mount_models`, opt-in `idle_timeout_min`) |
|
|
109
|
+
| `kaggle_status` | Inspect live GPU/VRAM telemetry, RAM, disk, and kernel states across `slot="all"` or a specific slot (auto-cleans stale sessions) |
|
|
110
|
+
| `kaggle_down` | Gracefully stop `slot="1"`, `"2"`, or `"all"` (`exit 0`) immediately to save GPU quota; optionally pull `/kaggle/working` |
|
|
111
|
+
| `term_exec` | Run bash commands in a persistent stateful PTY on `slot` (`cwd`, exports, and virtualenvs persist across calls) |
|
|
112
|
+
| `job_spawn` | Launch detached background jobs on `slot` with optional `gpu_ids` (`CUDA_VISIBLE_DEVICES="0"` or `"1"`) |
|
|
113
|
+
| `job_list` | List active and finished background jobs on `slot` with PID, GPU assignment, runtime, and log size |
|
|
114
|
+
| `job_logs` | Read tail lines of a background job log on `slot` (with regex `grep` and automatic `tqdm` `\r` cleanup) |
|
|
115
|
+
| `job_kill` | Send `SIGTERM` or `SIGKILL` to a background job's process group on `slot` and release VRAM |
|
|
116
|
+
| `fs_sync` | `push` local folders (auto-skipping `.git`, `.venv`, `__pycache__`) or `pull` remote checkpoints/logs on `slot` |
|
|
117
|
+
| `kaggle_wheelhouse` | Download Linux `manylinux_x86_64` binary `.whl` packages and publish a private Dataset for no-internet runs |
|
|
118
|
+
| `kaggle_batch_run` | Submit an offline/competition batch job (`NvidiaL4x4`, `NvidiaRtxPro6000`, `TpuV5E8`, `enable_internet=False`) with automatic code bundling |
|
|
119
|
+
| `kaggle_batch_logs` | Stream live or completed logs via Kaggle's Host SSE endpoint—even when container internet is disabled |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Standalone CLI Usage (`kgsh`)
|
|
124
|
+
|
|
125
|
+
### Workflow 1: Single or Dual-VM Interactive GPU Shell
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Boot BOTH Kaggle Dual-T4 VMs in parallel (4x T4 = 60 GB total VRAM)
|
|
129
|
+
kgsh up -s 1,2
|
|
130
|
+
|
|
131
|
+
# Interactive shell commands on specific slots
|
|
132
|
+
kgsh exec -s 1 "nvidia-smi"
|
|
133
|
+
kgsh push ./my_project /kaggle/working -s 1
|
|
134
|
+
kgsh push ./my_project /kaggle/working -s 2
|
|
135
|
+
|
|
136
|
+
# Run 4 independent GPU experiments simultaneously across 2 VMs x 2 GPUs
|
|
137
|
+
kgsh spawn -s 1 --gpus 0 "python my_project/train.py --lr 1e-4" --name exp1
|
|
138
|
+
kgsh spawn -s 1 --gpus 1 "python my_project/train.py --lr 3e-4" --name exp2
|
|
139
|
+
kgsh spawn -s 2 --gpus 0 "python my_project/train.py --lr 5e-4" --name exp3
|
|
140
|
+
kgsh spawn -s 2 --gpus 1 "python my_project/train.py --lr 1e-3" --name exp4
|
|
141
|
+
|
|
142
|
+
# Monitor status & shut down all GPU VMs when finished
|
|
143
|
+
kgsh status
|
|
144
|
+
kgsh down -s all
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Workflow 2: Offline Kaggle Competition (`L4x4` / `RTX Pro 6000` with Internet OFF)
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# 1. (Once) Build an offline Linux wheelhouse dataset
|
|
151
|
+
kgsh wheels peft accelerate bitsandbytes --slug lora-deps --py 312
|
|
152
|
+
|
|
153
|
+
# 2. Bundle local project & launch offline on competition hardware
|
|
154
|
+
kgsh batch-run "torchrun --nproc_per_node=4 solve.py" \
|
|
155
|
+
--path ./comp_solution \
|
|
156
|
+
-a l4x4 \
|
|
157
|
+
--comp arc-prize-2026 \
|
|
158
|
+
--wheels your_username/kgsh-wheels-lora-deps \
|
|
159
|
+
--model qwen-lm/qwen2.5/transformers/7b-instruct/1
|
|
160
|
+
|
|
161
|
+
# 3. Stream live logs from Host SSE without opening a browser
|
|
162
|
+
kgsh batch-logs -s batch-1 --tail 80
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Chaining Runs Longer Than 12 Hours
|
|
168
|
+
|
|
169
|
+
1. Save periodic checkpoints into `/kaggle/working/checkpoints/` inside your training script (and handle `SIGTERM` for the `11h35m` drain signal).
|
|
170
|
+
2. After Session 1 exits cleanly at `11h40m`, start Session 2 with `chain_previous_output=True` (`kgsh up --chain`). Kaggle mounts Session 1's output directly under `/kaggle/input/` at internal datacenter speeds.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Responsible Use
|
|
175
|
+
|
|
176
|
+
`kaggle-shell-mcp` is built for legitimate machine learning experimentation, model training, and competition workflows on your own Kaggle account. Respect [Kaggle's Terms of Service](https://www.kaggle.com/terms): do not use Kaggle notebooks for crypto-mining, public web hosting, or network proxying, and shut down active slots (`kgsh down -s all`) when finished. Note that running 2 concurrent GPU slots deducts 2 hours of GPU quota per wall-clock hour.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
Released under the [MIT License](./LICENSE).
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "kaggle-shell-mcp"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Turn free 12h Kaggle Dual-T4 GPUs into live remote terminals & detached job runners for AI Agents via MCP."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Dat Nguyen", email = "nquocdat06.work@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"mcp",
|
|
18
|
+
"model-context-protocol",
|
|
19
|
+
"kaggle",
|
|
20
|
+
"gpu",
|
|
21
|
+
"ai-agent",
|
|
22
|
+
"remote-terminal",
|
|
23
|
+
"claude-code",
|
|
24
|
+
"cursor",
|
|
25
|
+
"pytorch",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Intended Audience :: Science/Research",
|
|
31
|
+
"Operating System :: OS Independent",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
37
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
38
|
+
]
|
|
39
|
+
dependencies = [
|
|
40
|
+
"mcp>=1.2.0",
|
|
41
|
+
"httpx>=0.27.0",
|
|
42
|
+
"kaggle>=2.0.0",
|
|
43
|
+
"six>=1.16.0",
|
|
44
|
+
"python-dotenv>=1.0.0",
|
|
45
|
+
"pydantic>=2.0.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
dev = [
|
|
50
|
+
"pytest>=8.0.0",
|
|
51
|
+
"pytest-asyncio>=0.23.0",
|
|
52
|
+
"ruff>=0.6.0",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[project.urls]
|
|
56
|
+
Homepage = "https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp"
|
|
57
|
+
Repository = "https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp"
|
|
58
|
+
Issues = "https://github.com/NguyenQuocDat06-AI/kaggle-shell-mcp/issues"
|
|
59
|
+
|
|
60
|
+
[project.scripts]
|
|
61
|
+
kgsh = "kaggle_mcp.server:main"
|
|
62
|
+
kaggle-shell-mcp = "kaggle_mcp.server:main"
|
|
63
|
+
kaggle-mcp = "kaggle_mcp.server:main"
|
|
64
|
+
|
|
65
|
+
[tool.setuptools.packages.find]
|
|
66
|
+
where = ["src"]
|
|
67
|
+
|
|
68
|
+
[tool.pytest.ini_options]
|
|
69
|
+
testpaths = ["tests"]
|
|
70
|
+
asyncio_mode = "auto"
|
|
71
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
72
|
+
|
|
73
|
+
[tool.ruff]
|
|
74
|
+
line-length = 105
|
|
75
|
+
target-version = "py311"
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint]
|
|
78
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
79
|
+
ignore = ["E501"]
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""Hardware accelerator resolution and Kaggle runtime lifetime caps."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
MAX_GPU_LIFETIME_SEC = 42000 # 11h 40m safe exit before Kaggle 12h GPU/CPU reaper
|
|
9
|
+
GPU_DRAIN_AT_SEC = 41700 # 11h 35m SIGTERM checkpoint window
|
|
10
|
+
|
|
11
|
+
MAX_TPU_LIFETIME_SEC = 31200 # 8h 40m safe exit before Kaggle 9h TPU reaper
|
|
12
|
+
TPU_DRAIN_AT_SEC = 30900 # 8h 35m SIGTERM checkpoint window
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class AcceleratorSpec:
|
|
17
|
+
enable_gpu: bool
|
|
18
|
+
enable_tpu: bool
|
|
19
|
+
machine_shape: str | None
|
|
20
|
+
max_lifetime_sec: int = MAX_GPU_LIFETIME_SEC
|
|
21
|
+
drain_at_sec: int = GPU_DRAIN_AT_SEC
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def label(self) -> str:
|
|
25
|
+
if self.machine_shape:
|
|
26
|
+
return self.machine_shape
|
|
27
|
+
if self.enable_tpu:
|
|
28
|
+
return "TPU"
|
|
29
|
+
if self.enable_gpu:
|
|
30
|
+
return "GPU"
|
|
31
|
+
return "CPU"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_GPU_ALIASES: dict[str, str] = {
|
|
35
|
+
"t4": "NvidiaTeslaT4",
|
|
36
|
+
"t4x2": "NvidiaTeslaT4",
|
|
37
|
+
"teslat4": "NvidiaTeslaT4",
|
|
38
|
+
"nvidiateslat4": "NvidiaTeslaT4",
|
|
39
|
+
"l4": "NvidiaL4",
|
|
40
|
+
"l4x1": "NvidiaL4",
|
|
41
|
+
"nvidial4": "NvidiaL4",
|
|
42
|
+
"nvidial4x1": "NvidiaL4",
|
|
43
|
+
"l4x4": "NvidiaL4x4",
|
|
44
|
+
"nvidial4x4": "NvidiaL4x4",
|
|
45
|
+
"rtx6000": "NvidiaRtxPro6000",
|
|
46
|
+
"rtxpro6000": "NvidiaRtxPro6000",
|
|
47
|
+
"pro6000": "NvidiaRtxPro6000",
|
|
48
|
+
"nvidiartxpro6000": "NvidiaRtxPro6000",
|
|
49
|
+
"h100": "NvidiaH100",
|
|
50
|
+
"nvidiah100": "NvidiaH100",
|
|
51
|
+
"p100": "NvidiaTeslaP100",
|
|
52
|
+
"nvidiateslap100": "NvidiaTeslaP100",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
_TPU_ALIASES: dict[str, str] = {
|
|
56
|
+
"tpu": "TpuV5E8",
|
|
57
|
+
"tpuv5e8": "TpuV5E8",
|
|
58
|
+
"v5e8": "TpuV5E8",
|
|
59
|
+
"tpuvmv5e8": "TpuV5E8",
|
|
60
|
+
"tpuv6e8": "TpuV6E8",
|
|
61
|
+
"v6e8": "TpuV6E8",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_CPU_ALIASES = {"none", "cpu", "off", "false", "no"}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def resolve_accelerator(accelerator: str | None = None, gpu: bool = True) -> AcceleratorSpec:
|
|
68
|
+
"""Normalize user/agent accelerator aliases into Kaggle kernel metadata flags."""
|
|
69
|
+
raw = (accelerator or "").strip()
|
|
70
|
+
norm = re.sub(r"[\s_-]+", "", raw.lower())
|
|
71
|
+
|
|
72
|
+
if norm in _CPU_ALIASES or (not raw and not gpu):
|
|
73
|
+
return AcceleratorSpec(
|
|
74
|
+
enable_gpu=False,
|
|
75
|
+
enable_tpu=False,
|
|
76
|
+
machine_shape=None,
|
|
77
|
+
max_lifetime_sec=MAX_GPU_LIFETIME_SEC,
|
|
78
|
+
drain_at_sec=GPU_DRAIN_AT_SEC,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if not raw and gpu:
|
|
82
|
+
return AcceleratorSpec(
|
|
83
|
+
enable_gpu=True,
|
|
84
|
+
enable_tpu=False,
|
|
85
|
+
machine_shape="NvidiaTeslaT4",
|
|
86
|
+
max_lifetime_sec=MAX_GPU_LIFETIME_SEC,
|
|
87
|
+
drain_at_sec=GPU_DRAIN_AT_SEC,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if norm in _TPU_ALIASES:
|
|
91
|
+
return AcceleratorSpec(
|
|
92
|
+
enable_gpu=False,
|
|
93
|
+
enable_tpu=True,
|
|
94
|
+
machine_shape=_TPU_ALIASES[norm],
|
|
95
|
+
max_lifetime_sec=MAX_TPU_LIFETIME_SEC,
|
|
96
|
+
drain_at_sec=TPU_DRAIN_AT_SEC,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if norm in _GPU_ALIASES:
|
|
100
|
+
return AcceleratorSpec(
|
|
101
|
+
enable_gpu=True,
|
|
102
|
+
enable_tpu=False,
|
|
103
|
+
machine_shape=_GPU_ALIASES[norm],
|
|
104
|
+
max_lifetime_sec=MAX_GPU_LIFETIME_SEC,
|
|
105
|
+
drain_at_sec=GPU_DRAIN_AT_SEC,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if norm.startswith("tpu"):
|
|
109
|
+
return AcceleratorSpec(
|
|
110
|
+
enable_gpu=False,
|
|
111
|
+
enable_tpu=True,
|
|
112
|
+
machine_shape=raw,
|
|
113
|
+
max_lifetime_sec=MAX_TPU_LIFETIME_SEC,
|
|
114
|
+
drain_at_sec=TPU_DRAIN_AT_SEC,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Passthrough unknown future GPU shapes (e.g. NvidiaB200) without requiring code updates
|
|
118
|
+
return AcceleratorSpec(
|
|
119
|
+
enable_gpu=True,
|
|
120
|
+
enable_tpu=False,
|
|
121
|
+
machine_shape=raw,
|
|
122
|
+
max_lifetime_sec=MAX_GPU_LIFETIME_SEC,
|
|
123
|
+
drain_at_sec=GPU_DRAIN_AT_SEC,
|
|
124
|
+
)
|