MCP server that operates a home AI lab — health checks, model management, free local inference, and a safety-gated remote shell (allowlist, no shell metacharacters, timeouts).
This MCP server operates a home AI lab by exposing tools for health checks, model management, free local inference via a LiteLLM gateway, and a safety...
17DEFAULT_ALLOWED_COMMANDS = [
18 "ls", "pwd", "cat", "head", "tail", "wc", "stat", "file",
19 "df", "du", "free", "uptime", "whoami", "hostname", "date", "uname", "sw_vers", "id", "sysctl",
20 "ps", "pgrep", "vm_stat",
21 "grep", "echo",
22 "nvidia-smi",
23 "ollama list", "ollama ps", "ollama show", "ollama pull",
24 "docker ps", "docker logs", "docker stats", "docker images", "docker inspect", "docker compose ls",
25 "systemctl status", "systemctl is-active", "journalctl",
26 "curl -s", "ping -c", "ip", "ifconfig", "ss", "netstat",
27 "git status", "git log", "git pull", "git fetch", "git branch", "git rev-parse",
28 "python --version", "python3 --version", "pip list",
29 "wsl --status", "wsl -l",
30]// Network-exposed MCP with bearer-token auth; token may be leaked or brute-forced, or LLM may be compromised.
23"ollama list", "ollama ps", "ollama show", "ollama pull",// Network-exposed MCP; allows pulling arbitrary models without validation.
85def gateway_generate(prompt: str, model: str = "chat", max_tokens: int = 512) -> dict:
86 """Run inference through the LiteLLM gateway (free local models by default)."""
87 if not cfg.master_key:
88 return {"error": "LITELLM_MASTER_KEY not set", "hint": "add it to .env (from /opt/ai-lab/.env on the Alienware)"}
89 try:
90 r = httpx.post(
91 f"{cfg.gateway_url}/v1/chat/completions",
92 headers={"Authorization": f"Bearer {cfg.master_key}"},
93 json={"model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": max_tokens},
94 timeout=120,
95 )// Network-exposed MCP; allows arbitrary model selection.
112if not any(cmd == p or cmd.startswith(p + " ") for p in allowed):
113 return False, "command is not in the allowlist; extend LABCTL_ALLOWED_COMMANDS to permit it"// Network-exposed MCP; allows unintended command execution via prefix matching.
90r = httpx.post(
91 f"{cfg.gateway_url}/v1/chat/completions",
92 headers={"Authorization": f"Bearer {cfg.master_key}"},
93 json={"model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": max_tokens},
94 timeout=120,
95)// Network-exposed MCP; traffic may be intercepted if not using HTTPS.
164def pull_model(host: str, name: str, timeout: int = 600) -> dict:
165 """Pull an Ollama model on 'm4' (local) or 'gtx' (Alienware)."""
166 if host not in ("m4", "gtx"):
167 return {"ok": False, "error": "host must be 'm4' or 'gtx'"}
168 if not _valid_model_name(name):
169 return {"ok": False, "error": "invalid model name"}
170 command = f"ollama pull {name}"
171 res = run_local(command, timeout) if host == "m4" else run_remote(command, timeout)// Network-exposed MCP; requires bypassing character validation.