Manages Docker containers across multiple homelab hosts, providing tools for container lifecycle management (start, stop, restart, pause/unpause), log retrieval, resource monitoring (CPU, memory, network, I/O), container search and inspection, and Docker system operations including disk usage analysis and resource pruning.
homelab-mcp-server
MCP (Model Context Protocol) server for managing Docker infrastructure across multiple homelab hosts. Designed for use with Claude Code and other MCP-compatible clients.
Features
Multi-host support: Manage containers across Unraid, Proxmox, bare metal servers, and more
Auto-detect local Docker: Automatically adds local Docker socket if available
Container lifecycle: Start, stop, restart, pause/unpause, pull, recreate containers
Docker Compose: Full project management (up, down, restart, logs, build, pull, recreate)
Image operations: List, pull, build, and remove Docker images
Log retrieval: Fetch logs with time filters, grep, and stream selection
Resource monitoring: Real-time CPU, memory, network, and I/O statistics
Smart search: Find containers by name, image, or labels across all hosts
Detailed inspection: Full container configuration and state information (with summary mode)
Pagination & filtering: All list operations support limits, offsets, and filtering
Dual transport: stdio for Claude Code, HTTP for remote access
SSH support: Execute commands on remote hosts for resource monitoring
Tool
The server provides a single unified tool homelab with multiple actions and subactions:
Container Operations (action: "container")
Subaction | Description |
| List containers with filtering by state, name, image, labels |
| Start a stopped container |
| Stop a running container |
| Restart a container |
| Pause a running container |
| Unpause a paused container |
| Retrieve container logs with time and grep filters |
| Get real-time CPU, memory, network, I/O statistics |
| Detailed container configuration and state (with summary mode) |
| Search containers by name, image, or labels |
| Pull latest image for a container |
| Recreate container with latest image |
Docker Compose Operations (action: "compose")
Subaction | Description |
| List Docker Compose projects on a host |
| Get status of services in a project |
| Start a compose project |
| Stop a compose project |
| Restart a compose project |
| Get logs from compose project services |
| Build images for a compose project |
| Pull images for a compose project |
| Force recreate containers in a project |
Host Operations (action: "host")
Subaction | Description |
| Check connectivity and container counts per host |
| Get CPU, memory, disk usage via SSH |
Docker System Operations (action: "docker")
Subaction | Description |
| Get Docker version, resources, and system info |
| Get Docker disk usage (images, containers, volumes, cache) |
| Remove unused Docker resources (requires
) |
Image Operations (action: "image")
Subaction | Description |
| List Docker images on a host |
| Pull a Docker image |
| Build a Docker image from a Dockerfile |
| Remove a Docker image (requires
if in use) |
Example Usage
Installation
Configuration
Create a config file at one of these locations (checked in order):
Path in
HOMELAB_CONFIG_FILEenv var./homelab.config.json(current directory)~/.config/homelab-mcp/config.json~/.homelab-mcp.json
Example Config
Copy homelab.config.example.json as a starting point:
Note: If
/var/run/docker.sockexists and isn't already in your config, it will be automatically added as a host using your machine's hostname. This means the server works out-of-the-box for local Docker without any configuration.
Host Configuration Options
Field | Type | Description |
| string | Unique identifier for the host |
| string | Hostname or IP address |
| number | Docker API port (default: 2375) |
| "http" | "https" | "ssh" | Connection protocol |
| string | Path to Docker socket (for local connections) |
| string | SSH username for remote connections (protocol: "ssh") |
| string | Path to SSH private key for authentication |
| string[] | Optional tags for filtering |
Resource Limits & Defaults
Setting | Value | Description |
| 40,000 | Maximum response size (~12.5k tokens) |
| 20 | Default pagination limit for list operations |
| 100 | Maximum pagination limit |
| 50 | Default number of log lines to fetch |
| 500 | Maximum log lines allowed |
| 30s | Docker API operation timeout |
| 5s | Stats collection timeout |
Enabling Docker API on Hosts
Unraid
Docker API is typically available at port 2375 by default.
Standard Docker (systemd)
Edit /etc/docker/daemon.json:
Or override the systemd service:
ā ļø Security Note: Exposing Docker API without TLS is insecure. Use on trusted networks only, or set up TLS certificates.
Usage
With Claude Code
Add to ~/.claude/claude_code_config.json:
Or if your config is in one of the default locations, you can skip the env entirely:
Then in Claude Code:
HTTP Mode
For remote access or multi-client scenarios:
Environment variables for HTTP mode:
PORT: Server port (default: 3000)HOST: Bind address (default: 127.0.0.1)
CLI Help
Example Interactions
List containers
Check logs
Resource monitoring
Compose operations
Image management
Security
Path Traversal Protection (CWE-22)
The image_build tool implements strict path validation to prevent directory traversal attacks:
Absolute paths required: All paths (context, dockerfile) must start with
/Traversal blocked: Paths containing
..or.components are rejectedCharacter validation: Only alphanumeric, dots (in filenames), hyphens, underscores, and forward slashes allowed
Pre-execution validation: Paths validated before SSH commands are executed
Example of rejected paths:
General Security Notes
Docker API on port 2375 is insecure without TLS
Always use execFile for shell commands (prevents injection)
Validate host config fields with regex
Require force=true for destructive operations
Development
Architecture
Key Architectural Changes
Unified Tool Pattern (Commit 07fccbd, 12/18/2025):
Consolidated 15 individual tools into a single
homelabtoolAction/subaction routing pattern for better organization
Single entry point with type-safe parameter validation
Formatting Module (Commit 147d563):
Extracted 40+ formatting helpers to dedicated
formatters/moduleMarkdown output for all tool responses
Consistent formatting across all operations
Docker Compose Support (Commit ec88df9):
Full compose project lifecycle management
Service-level operations and filtering
Build, pull, and recreate capabilities
Discriminated Union Optimization (Commit f8e6e27, 12/24/2025):
Migrated schema validation from O(n) sequential to O(1) discriminated union
Uses composite
action_subactiondiscriminator for instant schema lookupAchieved <0.005ms validation latency across all 30 operations
Zero performance degradation regardless of which operation is called
Test Coverage:
Unit tests for all services, schemas, and tools
Integration tests for end-to-end workflows
Performance benchmarks for schema validation
8 test files covering core functionality
Performance
Schema Validation
The unified tool uses Zod discriminated union for O(1) constant-time schema validation:
Validation latency: <0.005ms average across all 30 operations
Optimization: Discriminated union with
action_subactioncomposite keyConsistency: All operations perform identically fast (no worst-case scenarios)
All inputs are automatically preprocessed to inject the discriminator key, maintaining backward compatibility.
SSH Connection Pooling
All SSH operations use connection pooling for optimal performance:
50Ć faster for repeated operations
Connections reused across compose operations
Automatic idle timeout and health checks
Configurable via environment variables
See docs/ssh-connection-pooling.md for details.
Key Benefits:
Eliminate 250ms connection overhead per operation
Support high-concurrency scenarios (configurable pool size)
Automatic connection cleanup and health monitoring
Zero code changes required (transparent integration)
Benchmarks
Run performance benchmarks:
Expected results:
Worst-case validation: <0.005ms (0.003ms typical)
Average-case validation: <0.005ms (0.003ms typical)
Performance variance: <0.001ms (proves O(1) consistency)
License
MIT