homelab-mcp

homelab-mcp

MCP server for homelab diagnostics + auto-update pipeline, managing Docker hosts via SSH with read-only diagnostics, image-drift visibility, and automated update execution with rollback.

Category
访问服务器

README

homelab-mcp

MCP server for homelab diagnostics + auto-update pipeline. Runs on TrueNAS (or anywhere) as the central control plane; talks to one or more downstream Docker hosts (Unraid, QNAP, etc.) over SSH.

What it does

  • Read-only diagnostics (MCP tools, safe to call any time):

    • list_stacks_tool — every compose project + single container on a host
    • stack_status_tool — full state of one stack (containers, digests)
    • recent_events_tool — docker events from the last N seconds
    • get_logs_tool — last N log lines of a container (capped at 5000)
    • check_nfs_shares_tool — mounted NFS exports
    • check_dns_tool — name resolution against the host's resolver
    • check_vpn_health_tool — gluetun container health
  • Image-drift visibility (MCP tools, populates pending_updates):

    • trigger_scan_tool — on-demand scan of one or all hosts
    • list_pending_updates_tool — rows from the latest scan / cron
    • pending_update_dismiss_tool — drop a row after deciding not to apply
  • Auto-update pipeline (cron-style; one cycle at a time):

    • Fetch release notes — image → GitHub repo heuristic (ghcr.io / quay.io / lscr.io/linuxserver → GitHub Releases API, then CHANGELOG.md fallback). 8KB cap.
    • Classify via LLM — OpenAI-compatible chat-completions endpoint (works with Ollama, vLLM, MiniMax M3). Returns SAFE / CAUTION / BREAKING plus migration steps, compose changes, env changes. Any LLM error falls back to CAUTION (better to over-apply than under-classify).
    • Apply policy:
      • default safe-and-caution — auto-apply SAFE + CAUTION, notify on BREAKING
      • safe-only — auto-apply SAFE only, notify on CAUTION + BREAKING
    • Apply — docker compose pull && docker compose up -d from the resolved stack directory. Stack-dir resolution: 4-tier (label override > compose working_dir > Dockge path > CA compose.manager). Probes container health post-restart.
    • Auto-rollback on apply failure (pull old digest, up -d).
    • Notify — ntfy by default (configurable); BREAKING alerts go to the ntfy topic with high priority.

Quick start

# 1. Sync deps (the project is configured to use .venv/)
uv sync --extra dev
source .venv/bin/activate

# 2. Configure
cp .env.example .env
# ... edit .env (set HOMELAB_MCP_HOSTS, ntfy topic, LLM endpoint, etc.)

# 3. Test
pytest

# 4. Run the MCP server (SSE on :18790)
python -m homelab_mcp

# 5. Run one cycle of the auto-apply pipeline (dry-run)
python -m homelab_mcp.auto_apply_main --dry-run

If uv sync puts the venv in a venv/ directory instead of .venv/, set UV_PROJECT_ENVIRONMENT=.venv once or use uv venv .venv && uv sync --extra dev to force the location.

Install on Unraid

# On Unraid:
bash scripts/install-on-unraid.sh
# (pulls the GHCR image, starts the daemon, registers a 6h cron)

Install on TrueNAS (the "main hub" config)

# On TrueNAS, in a Dockge stack directory:
git clone https://github.com/<owner>/homelab-mcp.git
cd homelab-mcp
cp scripts/dockge-stack/.env.example .env
# ... edit .env (set HOMELAB_MCP_HOSTS=["truenas","unraid"],
#     HOMELAB_MCP_LOCAL_HOST_ALIAS=truenas, etc.)
docker compose -f scripts/dockge-stack/compose.yaml up -d
bash scripts/deploy-on-truenas.sh
# (runs 5 in-the-field smoke tests)

Configuration

All configuration is via environment variables. See .env.example.

Env var Default Notes
HOMELAB_MCP_HOSTS ["unraid"] JSON list of host aliases
HOMELAB_MCP_PORT 18790 MCP SSE transport port
HOMELAB_MCP_STATE_DIR ~/.local/share/homelab-mcp sqlite + last_scan.txt
HOMELAB_MCP_SSH_CONFIG ~/.ssh/config for RemoteSSH
HOMELAB_MCP_POLL_ENABLED true visibility cron on/off
HOMELAB_MCP_POLL_INTERVAL 21600 seconds between scans (6h)
HOMELAB_MCP_NTFY_URL https://ntfy.sh/ notifier base
HOMELAB_MCP_NTFY_TOPIC "" required for alerts
HOMELAB_MCP_NTFY_PRIORITY default default priority
HOMELAB_MCP_LLM_ENDPOINT http://localhost:11434/v1/chat/completions OpenAI-compatible
HOMELAB_MCP_LLM_API_KEY "" Bearer token (optional)
HOMELAB_MCP_LLM_MODEL "" model name (required)
HOMELAB_MCP_LLM_TIMEOUT 30 seconds
HOMELAB_MCP_AUTO_APPLY_POLICY safe-and-caution or safe-only
HOMELAB_MCP_LOCAL_HOST_ALIAS unraid set to truenas for TrueNAS deploys
HOMELAB_MCP_DOCKGE_STACKS_ROOT /mnt/Data/appdata/dockge/stacks Dockge stacks path

Architecture

                 +------------+
                 |  TrueNAS   |  <-- MCP daemon here (LocalDocker)
                 | (main hub) |
                 +-----+------+
                       |
                  SSH  |  (RemoteSSH for unraid + qnap)
                       |
        +--------------+--------------+
        |                             |
   +----+-----+                +------+----+
   |  Unraid  |                |   QNAP    |
   | (117 ct) |                | (60+ ct)  |
   +----------+                +-----------+
  • LocalDocker backend: the daemon host's docker socket (unix:///var/run/docker.sock).
  • RemoteSSH backend: SSH config alias → ssh <alias> docker ps. Each host alias in HOMELAB_MCP_HOSTS must have a corresponding Host block in HOMELAB_MCP_SSH_CONFIG.
  • Stack-dir resolution (in order):
    1. auto-update.stack-dir label on the container (override)
    2. com.docker.compose.project.working_dir (the standard compose label)
    3. If com.dockge.owner or auto-update.dockge=true is set → <HOMELAB_MCP_DOCKGE_STACKS_ROOT>/<project>
    4. Otherwise → <compose_manager_root>/<project> (CA compose.manager style; compose_manager_root is auto-detected for the local host)

Tests

uv run pytest -q

Currently 112 tests across:

  • config (env-var loading, validation)
  • state (SQLite CRUD, idempotent writes, busy_timeout)
  • hosts (LocalDocker + RemoteSSH, structural conformance to HostClient)
  • updater.registry (image-ref parsing, registry result kinds)
  • updater.scanner (drift detection, transient errors, digests)
  • updater.pipeline (snapshot, apply+probe, rollback, run_pipeline)
  • updater.release_notes (image→GitHub, GH Releases API, CHANGELOG fallback, truncation)
  • updater.risk (SAFE/CAUTION/BREAKING classification, error fallbacks)
  • updater.notifier (ntfy POST, multi-fan-out, console)
  • updater.auto_apply (policy decisions, classifier-fail CAUTION fallback)
  • auto_apply_main (cron arg parsing, per-row exception isolation, summary)
  • server (FastMCP singleton, tool registration, build_hosts wiring)

Live tests (skipped unless HOMELAB_MCP_LIVE=1) cover SSH connections to a real host.

Security

  • The MCP server runs in SSE mode and is bound to 0.0.0.0:18790 by default. Put a reverse proxy in front of it (npmplus, Traefik, Caddy) with OIDC or HTTP basic auth — don't expose 18790 directly.
  • ntfy topics should be unique and unguessable. Add a token in the URL (HOMELAB_MCP_NTFY_URL=https://ntfy.sh/?token=...) for private topics.
  • LLM API keys never appear in logs or state. The state DB at HOMELAB_MCP_STATE_DIR/state.db is not encrypted — host-level ACLs apply.
  • The auto-update machinery touches docker. Run as a dedicated user with docker-socket access; do not run as root if you can avoid it.

License

MIT.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选