jlab-mcp
An MCP server that enables LLMs to execute Python code on GPU-accelerated compute nodes within SLURM-managed HPC environments. It bridges local clients to remote clusters by launching JupyterLab sessions via SLURM jobs to facilitate high-performance notebook-based computation.
README
jlab-mcp
A Model Context Protocol (MCP) server that enables Claude Code to execute Python code on GPU compute nodes via JupyterLab running on a SLURM cluster.
Inspired by and adapted from goodfire-ai/scribe, which provides notebook-based code execution for Claude. This project adapts that approach for HPC/SLURM environments where GPU resources are allocated via job schedulers.
Architecture
Claude Code (login node)
↕ stdio
MCP Server (login node)
↕ HTTP/WebSocket
JupyterLab (compute node, via sbatch) ← one SLURM job, many kernels
↕
IPython Kernels (GPU access)
Login and compute nodes share a filesystem. The SLURM job is managed separately from the MCP server — you start it with jlab-mcp start and it keeps running across Claude Code sessions. All sessions create separate kernels on this shared server.
Setup
# Install (no git clone needed)
uv tool install git+https://github.com/kdkyum/jlab-mcp.git
The SLURM job activates .venv in the current working directory. Set up your project's venv on the shared filesystem with the compute dependencies:
cd /shared/fs/my-project
uv venv
uv pip install jupyterlab ipykernel matplotlib numpy
uv pip install torch --index-url https://download.pytorch.org/whl/cu126 # GPU support
Usage
1. Start the compute node
In a separate terminal, start the SLURM job:
jlab-mcp start
This submits the job and waits until JupyterLab is ready:
SLURM job 24215408 submitted, waiting in queue...
Job running on ravg1011, JupyterLab starting...
JupyterLab ready at http://ravg1011:18432
2. Use Claude Code
In another terminal, start Claude Code. The MCP server connects to the running JupyterLab automatically.
3. Stop when done
jlab-mcp stop
CLI Commands
| Command | Description |
|---|---|
jlab-mcp start |
Submit SLURM job and wait until JupyterLab is ready |
jlab-mcp stop |
Cancel the SLURM job |
jlab-mcp wait |
Poll status (check from another terminal) |
jlab-mcp status |
Print server state, active kernels, and GPU memory |
jlab-mcp |
Run MCP server (used by Claude Code, not run manually) |
The SLURM job survives Claude Code restarts. You only need to run jlab-mcp start once per work session.
Configuration
All settings are configurable via environment variables. No values are hardcoded for a specific cluster.
| Environment Variable | Default | Description |
|---|---|---|
JLAB_MCP_DIR |
~/.jlab-mcp |
Base working directory |
JLAB_MCP_NOTEBOOK_DIR |
./notebooks |
Notebook storage (relative to cwd) |
JLAB_MCP_LOG_DIR |
~/.jlab-mcp/logs |
SLURM job logs |
JLAB_MCP_CONNECTION_DIR |
~/.jlab-mcp/connections |
Connection info files |
JLAB_MCP_SLURM_PARTITION |
gpu |
SLURM partition |
JLAB_MCP_SLURM_GRES |
gpu:1 |
SLURM generic resource |
JLAB_MCP_SLURM_CPUS |
4 |
CPUs per task |
JLAB_MCP_SLURM_MEM |
32000 |
Memory in MB |
JLAB_MCP_SLURM_TIME |
4:00:00 |
Wall clock time limit |
JLAB_MCP_SLURM_MODULES |
(empty) | Space-separated modules to load (e.g. cuda/12.6) |
JLAB_MCP_PORT_MIN |
18000 |
Port range lower bound |
JLAB_MCP_PORT_MAX |
19000 |
Port range upper bound |
Example: Cluster with A100 GPUs and CUDA module
export JLAB_MCP_SLURM_PARTITION=gpu1
export JLAB_MCP_SLURM_GRES=gpu:a100:1
export JLAB_MCP_SLURM_CPUS=18
export JLAB_MCP_SLURM_MEM=125000
export JLAB_MCP_SLURM_TIME=1-00:00:00
export JLAB_MCP_SLURM_MODULES="cuda/12.6"
Claude Code Integration
Add to ~/.claude.json or project .mcp.json:
{
"mcpServers": {
"jlab-mcp": {
"command": "jlab-mcp",
"env": {
"JLAB_MCP_SLURM_PARTITION": "gpu1",
"JLAB_MCP_SLURM_GRES": "gpu:a100:1",
"JLAB_MCP_SLURM_MODULES": "cuda/12.6"
}
}
}
}
The MCP server uses the working directory to find .venv for the compute node. Claude Code launches from your project directory, so it picks up the right venv automatically.
MCP Tools
| Tool | Description |
|---|---|
start_new_session |
Start kernel on shared server, create empty notebook |
start_session_resume_notebook |
Resume existing notebook (re-executes all cells to restore state) |
start_session_continue_notebook |
Fork notebook with fresh kernel (no re-execution) |
execute_code |
Run Python code, append cell to notebook (returns text + images) |
edit_cell |
Edit and re-execute a cell (supports negative indexing) |
add_markdown |
Add markdown cell to notebook |
execute_scratch |
Run code on a utility kernel (no notebook save, no session state) |
shutdown_session |
Stop kernel (SLURM job stays alive for other sessions) |
Resource: jlab-mcp://server/status — returns shared server info and active sessions.
Session Lifecycle
start_new_session: Creates a new kernel on the shared JupyterLabshutdown_session: Kills the kernel only. The SLURM job keeps running.- SLURM job dies: Next tool call returns an error. Run
jlab-mcp startto restart.
Testing
# Unit tests (no SLURM needed)
uv run python -m pytest tests/test_slurm.py tests/test_notebook.py tests/test_image_utils.py -v
# Integration tests (requires running `jlab-mcp start` first)
uv run python -m pytest tests/test_tools.py -v -s --timeout=600
Acknowledgments
This project is inspired by goodfire-ai/scribe, which provides MCP-based notebook code execution for Claude. The tool interface design, image resizing approach, and notebook management patterns are adapted from scribe for use on HPC/SLURM clusters.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。