VPS-Guardian-MCP
VPS-Guardian-MCP š”ļø
A secure, open-source Model Context Protocol (MCP) server written in Python. It empowers AI agents (Claude Desktop, Antigravity, Cursor, etc.) to safely monitor Linux VPS health metrics, inspect Docker container states, retrieve service logs, and execute isolated recovery commands without giving full shell or root access.
⨠Features
š Comprehensive System Monitoring (
get_system_health):Real-time CPU load (%), physical & logical core count, and system load averages.
RAM & Swap usage (used/free/available both in human-readable and raw bytes).
Root disk filesystem capacity and utilization.
Docker container health check: detects exited, dead, restarting, or unhealthy containers.
š Safe Service Log Inspection (
read_service_logs):Reads the last $N$ lines of logs for systemd units and Nginx.
Supports container-specific logs (
docker:<container_name>).Injection Prevention: Input validation with strict regex patterns and non-shell execution (
shell=False).
š§ Isolated Emergency Recovery (
execute_recovery):Strict whitelist-only execution policy.
clean_docker_cache: Cleans stopped containers, unused networks, and dangling images.restart_nginx: Restarts the Nginx web server service via systemctl or Docker.Rejects any unauthorized action with a
forbiddenstatus.
š”ļø Robust Error Handling & Permissions:
All operations wrapped in safe exception boundaries.
Clear, informative diagnostic messages for permission issues (e.g. missing access to
/var/run/docker.sockor sudo privileges) without crashing the MCP connection.
š Project Structure
vps-guardian-mcp/
āāā src/
ā āāā __init__.py # Package initialization
ā āāā server.py # FastMCP server & tool definitions
ā āāā monitor.py # System & Docker metrics collector
ā āāā recover.py # Whitelisted recovery & log inspection
āāā pyproject.toml # Package definition and dependencies
āāā LICENSE # MIT License
āāā .gitignore # Git exclusion rules
āāā README.md # Documentationš Installation & Setup
1. Requirements
Python 3.10+
Linux VPS (Ubuntu/Debian/CentOS/Fedora) with systemd and Docker (optional)
2. Install dependencies
Create a virtual environment and install the package:
git clone https://github.com/murzirius/VPS-Guardian-MCP.git
cd vps-guardian-mcp
python3 -m venv .venv
source .venv/bin/activate
pip install -e .3. Grant Required VPS Permissions (Optional but Recommended)
To allow the server to inspect Docker and restart Nginx without full root:
# Allow Docker socket access without sudo
sudo usermod -aG docker $USER
# Allow reading systemd logs
sudo usermod -aG systemd-journal $USER
# Allow passwordless Nginx restart via sudoers (optional for restart_nginx)
echo "$USER ALL=(ALL) NOPASSWD: /bin/systemctl restart nginx" | sudo tee /etc/sudoers.d/vps-guardian-nginx
sudo chmod 0440 /etc/sudoers.d/vps-guardian-nginxāļø MCP Client Configuration
Add VPS-Guardian-MCP to your client configuration file (e.g. claude_desktop_config.json or Antigravity MCP settings):
{
"mcpServers": {
"vps-guardian": {
"command": "/path/to/vps-guardian-mcp/.venv/bin/python",
"args": [
"-m",
"src.server"
]
}
}
}Or when running via uvx / pipx:
{
"mcpServers": {
"vps-guardian": {
"command": "uv",
"args": [
"--directory",
"/path/to/vps-guardian-mcp",
"run",
"vps-guardian-mcp"
]
}
}
}š ļø Available MCP Tools
1. get_system_health
Retrieves CPU, RAM, root disk usage, and unhealthy/failed Docker containers.
Example Agent Output:
{
"system": { "os": "Linux", "platform": "Linux-5.15.0-generic-x86_64", "architecture": "x86_64" },
"cpu": { "status": "ok", "cpu_usage_percent": 18.4, "logical_cores": 4 },
"memory": {
"status": "ok",
"ram": { "total": "15.62 GB", "used": "4.20 GB", "available": "11.42 GB", "used_percent": 26.9 }
},
"disk": {
"status": "ok",
"mount_point": "/",
"total": "98.24 GB",
"free": "64.12 GB",
"used_percent": 34.7
},
"docker": {
"status": "connected",
"total_containers": 5,
"running_containers": 4,
"failed_containers": [
{
"id": "a1b2c3d4e5f6",
"name": "payment-api",
"status": "exited",
"exit_code": 137,
"error": "OOMKilled"
}
]
}
}2. read_service_logs
Fetches the last $N$ lines of logs for Nginx, systemd services, or Docker containers.
Parameters:
service_name(string, required): e.g."nginx","docker:payment-api", or"systemd:redis".lines_count(integer, optional, default: 50): clamped between 1 and 1000.
3. execute_recovery
Executes an isolated, predefined recovery operation.
Parameters:
action_name(string, required):"clean_docker_cache": Runs Docker prune for containers, images, and networks."restart_nginx": Safely restarts Nginx via systemctl or Docker.
š Security Principles
No Arbitrary Command Execution: We deliberately avoid exposing a raw terminal or generic
exectool.Strict Whitelisting: Actions are hard-coded in an immutable lookup table.
No Shell Invocations: All subprocess executions use explicit list arguments (
shell=False), preventing shell meta-character evaluation and command injections.Least Privilege: Designed to run as an unprivileged user with narrowly scoped group memberships (
docker,systemd-journal).
š License
This project is licensed under the MIT License - see the LICENSE file for details.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/murzirius/VPS-Guardian-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server