ComfyUI-GPU-Optimizer
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., "@ComfyUI-GPU-Optimizershow GPU status and optimize VRAM"
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.
ComfyUI GPU Optimizer
AI-controlled GPU VRAM management for ComfyUI. Run LTX 2.3 video, SDXL, AnimateDiff, and FLUX on an 8GB GPU without running out of memory.
What It Does
Two components that work together:
ComfyUI custom node -- runs inside ComfyUI, monitors VRAM every 3 seconds, and automatically offloads models to CPU when memory pressure hits your threshold (default 82%). No more OOM crashes mid-workflow.
MCP server -- lets Claude Code (or any MCP client) see your GPU state and control it in real time. Ask Claude to free up VRAM, start/stop ComfyUI, or check what models are loaded.
Claude Code ComfyUI
| |
|--- MCP (stdio) ---> MCP Server (mcp_server.py)
|
|--- HTTP ---> GPU Optimizer (port 9111)
|
|--- comfy.model_management
|--- torch.cudaRelated MCP server: kje-mcp
Why This Exists
ComfyUI's built-in Dynamic VRAM handles basic auto-offloading. This project adds:
Configurable thresholds -- set exactly when offloading kicks in (50-95%)
Model-level visibility -- see every loaded model, its size, and device
Selective offloading -- unload specific models by index, not just the largest
AI control via MCP -- Claude can manage your GPU while you work
ComfyUI lifecycle management -- start, stop, restart with tuned flags for 8GB cards
Process visibility -- see everything using your GPU, not just ComfyUI
Quick Start
Option A: Full setup (custom node + MCP for Claude)
# Clone into ComfyUI custom_nodes
git clone https://github.com/WaightTech/ComfyUI-GPU-Optimizer \
~/ComfyUI/custom_nodes/ComfyUI-GPU-Optimizer
# Install and register with Claude Code
cd ~/ComfyUI/custom_nodes/ComfyUI-GPU-Optimizer
bash setup.shRestart ComfyUI. Open Claude Code. Your GPU tools are ready.
Option B: Custom node only (no MCP)
git clone https://github.com/WaightTech/ComfyUI-GPU-Optimizer \
~/ComfyUI/custom_nodes/ComfyUI-GPU-OptimizerRestart ComfyUI. The optimizer loads automatically and manages VRAM in the background. The HTTP API is available on http://127.0.0.1:9111 for custom integrations.
Option C: MCP server only (already have the node)
pip install comfyui-gpu-optimizerThen add to your Claude Code MCP config:
{
"mcpServers": {
"gpu-manager": {
"command": "comfyui-gpu-optimizer"
}
}
}MCP Tools
Tool | What it does |
| VRAM usage, utilization, temperature, power draw |
| List all processes using the GPU |
| Show loaded models with sizes and devices |
| Auto-offload models to free VRAM (largest first) |
| Offload a specific model by index |
| Set auto-offload threshold (50-95%) |
| Enable/disable automatic VRAM management |
| Unload ALL models and empty CUDA cache |
| Check if ComfyUI is running and responding |
| Start ComfyUI with optimized flags for your GPU |
| Graceful shutdown |
| Stop, flush, restart |
| Kill all GPU compute processes (nuclear option) |
| Tail the ComfyUI log |
Configuration
All settings are optional environment variables with sensible defaults:
Variable | Default | Description |
|
| ComfyUI install path |
|
| ComfyUI API endpoint |
|
| Log file location |
|
| GB to reserve for OS stability |
|
| Optimizer HTTP API port |
|
| Optimizer API URL (MCP server side) |
|
| Auto-offload threshold (%) |
|
| Monitor check interval (seconds) |
How It Works
The custom node loads when ComfyUI starts. It spins up two daemon threads:
Monitor thread -- checks VRAM usage every 3 seconds. When usage exceeds the threshold, it offloads the largest loaded model to CPU via
comfy.model_management, then clears the CUDA cache. Repeats until usage is below threshold.API server -- HTTP server on port 9111 (localhost only). Exposes endpoints for status, model listing, offloading, flushing, and threshold adjustment.
The MCP server runs as a separate process. It queries the GPU directly via pynvml (NVML) for hardware stats, and calls the optimizer's HTTP API for model-level operations. If ComfyUI isn't running, hardware-level tools (status, processes) still work; model-level tools return a clear error.
Tested On
NVIDIA GeForce RTX 4060 Ti 8GB
WSL2 (Ubuntu) on Windows
Python 3.10+
Verified workloads on 8GB:
Workload | VRAM Usage | Notes |
LTX 2.3 Video (22B Q4 GGUF) | 52-70% | 10-sec video in ~6 min. Add |
AnimateDiff + Realistic Vision | 54% | 5-sec video in ~5 min |
SDXL (epiCRealismXL) | 60% | Image generation |
FLUX (GGUF quantized) | varies | Works with auto-offloading |
System RAM matters. When the optimizer offloads models from GPU to CPU, they live in system RAM. LTX 2.3 keeps its 10.8GB Gemma text encoder on CPU full-time, and offloaded SDXL/FLUX models add to that. 32GB RAM recommended for video workloads, 16GB minimum for image generation.
Should work on any NVIDIA GPU with CUDA support. The 8GB defaults are tuned for low-VRAM cards but the thresholds are configurable for any card size.
License
MIT. See LICENSE.
Built by Waight Tech, LLC.
Available Tools
14 toolscomfyui_logA
Read the last N lines of the ComfyUI log.
Inputs: lines. Returns: result
comfyui_restartC
Restart ComfyUI: stop, flush VRAM, start fresh with GPU optimizer.
Inputs: lowvram, novram.
comfyui_startC
Start ComfyUI with GPU optimizer. Automatically reserves VRAM headroom for system stability.
Inputs: lowvram, novram.
comfyui_statusA
Check if ComfyUI is running, responding, and whether the GPU optimizer is active.
Inputs: no named parameters.
comfyui_stopA
Stop ComfyUI and free VRAM.
Inputs: no named parameters.
gpu_auto_manageA
Enable or disable automatic VRAM management. When enabled, the optimizer automatically offloads models when VRAM exceeds the threshold.
Inputs: enabled.
gpu_flush_modelsA
Unload ALL models from VRAM inside ComfyUI and empty the CUDA cache. More thorough than vram_flush.
Inputs: no named parameters.
gpu_memory_mapA
See exactly which models are loaded on the GPU, their sizes, and devices. Requires the GPU optimizer inside ComfyUI.
Inputs: no named parameters.
gpu_offload_modelA
Move a specific model from GPU to CPU by index. Use gpu_memory_map to see model indices. Pass -1 to offload the largest model.
Inputs: model_index.
gpu_optimizeA
Automatically free VRAM by offloading models to CPU. Offloads largest models first until threshold is met. Set target_free_mb to specify how much VRAM to free, or 0 for auto.
Inputs: target_free_mb.
gpu_processesA
List all processes currently using the GPU (compute and graphics).
Inputs: no named parameters.
gpu_set_thresholdA
Set the VRAM auto-management threshold (50-95%). When VRAM exceeds this, models are automatically offloaded to CPU.
Inputs: threshold_pct.
gpu_statusA
Get current GPU status: VRAM usage, utilization, temperature, and power draw.
Inputs: no named parameters.
vram_flushA
Kill ALL GPU compute processes and free VRAM. Use with caution.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
TDQS
Scored across 14 tools
Most tools have distinct purposes (ComfyUI lifecycle vs GPU management), but gpu_flush_models and vram_flush both free VRAM with slightly different scopes, causing minor overlap. Overall clear separation.
Tools follow a verb_noun pattern with prefixes (comfyui_, gpu_), but vram_flush breaks the pattern by using a different style. The naming is mostly predictable but has one inconsistency.
14 tools is reasonable for managing a GPU-optimizer server. It covers ComfyUI operations and GPU/VRAM management without being excessive, though slightly above the ideal 3-15 range.
The tool set covers core workflows: start/stop/restart ComfyUI, VRAM monitoring and management, and GPU status. Missing advanced features (e.g., configuring GPU device) but no critical gaps.
Related MCP Connectors
MCP server for Wan AI video generation
Remote MCP for RunComfy: ComfyUI deployments, hosted models, LoRA training. 31 tools.
MCP server for Google Veo AI video generation
MCP server for Luma Dream Machine AI video generation
Related MCP Servers
- AlicenseAqualityDmaintenanceMCP server for ComfyUI — text-to-image, variations, img2img refine, upscale, image proxy, and workflow runner.15120 npm2MIT
- FlicenseNot gradedqualityCmaintenanceMCP server that enables Claude.ai to interact with Jim Brain's persistent memory, project state, and vault, and to dispatch headless Claude Code build sessions on a VPS.-
- AlicenseAqualityAmaintenanceMCP server + Claude Code plugin for ComfyUI: execute workflows, generate images, visualize pipelines as Mermaid diagrams, compose/validate workflows, manage and download models, control VRAM, and explore custom nodes. 36 tools, cross-platform, installs via npx -y comfyui-mcp.4112,131 npm906MIT
- FlicenseNot gradedqualityDmaintenanceMCP server that connects local ComfyUI to AI agents, enabling natural language control of ComfyUI for creating workflows, generating images, and managing the queue.1-