VPS Docker MCP (Advanced)
VPS Docker MCP — 高级版
为 Claude Code 提供的 MCP 服务器,支持安全的 VPS 诊断和 Docker/Docker Compose 管理。
架构
Claude Code
|
| MCP / stdio
v
Local Python MCP server
|
| SSH / AsyncSSH
v
VPS
|
+-- systemd
+-- Docker
+-- Docker ComposeMCP 服务器在本地运行。VPS 上无需监听任何内容。
模块布局
src/vps_docker_mcp/
├── server.py # MCP instance, wires modules together
├── ssh.py # SSH config, run_ssh/run_many helpers
├── docker.py # Docker and Docker Compose tools
└── infrastructure.py # VPS diagnostics toolsRelated MCP server: dokku-mcp
安全模型
本项目有意不暴露任意 shell 执行。
没有:
ssh(command)
execute(command)
bash(command)相反,每个操作都是一个预定义的 MCP 工具。
诸如容器和服务名称等参数会通过严格的允许列表模式进行验证,并在插入命令前进行 shell 引用转义。
通过 VPS_KNOWN_HOSTS 启用 SSH 主机密钥检查。
使用专用的非 root SSH 账户(例如 deploy),并赋予其 Docker 访问权限。
要求
Python 3.11+
uvSSH 访问
VPS 上安装 Docker
如果使用 Compose 工具,需要 Docker Compose v2
具有 Docker 运行权限的
deploy用户
安装
uv sync配置:
cp .env.example .env示例:
VPS_HOST=YOUR_VPS_IP
VPS_PORT=22
VPS_USER=deploy
VPS_SSH_KEY=~/.ssh/vps_mcp
VPS_KNOWN_HOSTS=~/.ssh/known_hosts
DOCKER_COMPOSE_DIR=/opt/news-bot
MAX_OUTPUT_CHARS=20000独立测试 SSH:
ssh -i ~/.ssh/vps_mcp deploy@YOUR_VPS_IP docker ps测试 MCP:
uv run vps-docker-mcp它会等待 MCP stdio 输入。这是预期行为。
Claude Code 配置
将 .mcp.json.example 复制到 Claude Code 使用的项目级 .mcp.json,并替换绝对路径。
示例:
{
"mcpServers": {
"vps-docker": {
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"/home/me/projects/vps-docker-mcp-advanced",
"run",
"vps-docker-mcp"
]
}
}
}然后启动/重启 Claude Code,并使用以下命令检查 MCP 状态:
/mcp根据 Claude Code 版本的不同,MCP 服务器也可以通过 Claude Code CLI 进行管理。
工具组
VPS 诊断
system_infodisk_usagetop_processesnetwork_infosystemd_failedjournal_errorsdiagnose_vps
Docker 只读
docker_psdocker_logsdocker_inspectdocker_statsdocker_healthdocker_imagesdocker_volumesdocker_networksdocker_disk_usage
Docker 变更操作
docker_restartdocker_startdocker_stop
Docker Compose
只读:
docker_compose_psdocker_compose_configdocker_compose_logs
变更操作:
docker_compose_restartdocker_compose_pulldocker_compose_up
受限诊断
diagnostic_command 仅允许固定列表:
pwd
whoami
date
df
free
uptime
docker_version
docker_info
它不接受任意 shell 语法。
Claude Code 请求示例
Check the VPS health.Claude 可以使用:
diagnose_vps对于故障容器:
Find out why news-bot is unhealthy.一个有用的诊断序列是:
docker_health
docker_ps
docker_logs
docker_stats
docker_inspect对于一般资源问题:
Check whether the VPS is running out of RAM or disk space.Claude 可以检查:
system_info
disk_usage
top_processes
docker_stats
docker_disk_usage然后:
Restart news-bot if the diagnosis indicates that a restart is appropriate.重启操作是一个独立的变更工具。
重要生产建议
对于变更操作,请保持启用 Claude Code 自身的权限/批准机制。
MCP 服务器有意在其描述中标记变更工具,但 MCP 本身不应被视为授权边界。
对于生产 VPS,除非您有意接受风险,否则不要添加任意 shell 执行功能。
未来改进
下一步好的改进包括:
特定应用的健康检查
Docker 容器重启循环检测
OOM 检测
磁盘增长检测
systemd 服务重启工具
可配置的 Compose 项目允许列表
审计日志
每个工具的命令执行超时
独立的只读和写入 SSH 凭据
Available Tools
26 toolsdiagnose_vpsA
Run a compact VPS health check covering resources, disk, systemd and Docker.
Inputs: no named parameters. Returns: result
diagnostic_commandB
Run one of a small predefined set of read-only diagnostic commands.
Inputs: command (required). Returns: result
disk_usageB
Show filesystem space and inode usage.
Inputs: no named parameters. Returns: result
docker_compose_configB
Render and validate the Docker Compose configuration.
Inputs: no named parameters. Returns: result
docker_compose_logsB
Show Docker Compose logs, optionally for one service.
Inputs: tail, service. Returns: result
docker_compose_psC
Show Docker Compose services.
Inputs: no named parameters. Returns: result
docker_compose_pullB
Pull Docker Compose images. This changes local Docker image state.
Inputs: no named parameters. Returns: result
docker_compose_restartB
Restart Docker Compose services. This changes server state.
Inputs: service. Returns: result
docker_compose_upA
Start/update the Docker Compose stack with detached mode. This changes server state.
Inputs: no named parameters. Returns: result
docker_disk_usageB
Show Docker disk usage.
Inputs: no named parameters. Returns: result
docker_healthB
Show container state, restart count and health status.
Inputs: container (required). Returns: result
docker_imagesB
List Docker images.
Inputs: no named parameters. Returns: result
docker_inspectC
Inspect a Docker container.
Inputs: container (required). Returns: result
docker_logsC
Show recent logs from a Docker container.
Inputs: container (required), tail. Returns: result
docker_networksB
List Docker networks.
Inputs: no named parameters. Returns: result
docker_psA
List Docker containers. Set all_containers=true to include stopped containers.
Inputs: all_containers. Returns: result
docker_restartB
Restart a Docker container. This changes server state.
Inputs: container (required). Returns: result
docker_startB
Start a Docker container. This changes server state.
Inputs: container (required). Returns: result
docker_statsA
Show current CPU, memory, network and block I/O usage of containers.
Inputs: no named parameters. Returns: result
docker_stopC
Stop a Docker container. This changes server state.
Inputs: container (required). Returns: result
docker_volumesB
List Docker volumes.
Inputs: no named parameters. Returns: result
journal_errorsC
Show recent system journal errors.
Inputs: hours, lines. Returns: result
network_infoB
Show network interfaces, routes and listening TCP/UDP ports.
Inputs: no named parameters. Returns: result
systemd_failedA
Show failed systemd services.
Inputs: no named parameters. Returns: result
system_infoA
Show VPS uptime, OS, CPU, memory, swap, load and kernel information.
Inputs: no named parameters. Returns: result
top_processesC
Show processes consuming the most CPU and memory.
Inputs: limit. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 26 tools
Most tools have clearly distinct purposes (e.g., docker_ps vs docker_inspect, system_info vs disk_usage). However, diagnose_vps overlaps with several individual system tools, and diagnostic_command is vague, creating some ambiguity.
Tools follow snake_case with clear prefixes (docker_, docker_compose_, system_, etc.). Docker tools use verb_noun pattern, but system tools are mostly noun_noun (e.g., system_info, disk_usage). This mix is not fully consistent but still readable.
26 tools is on the higher side but appropriate for the 'Advanced' scope covering Docker, Docker Compose, and VPS diagnostics. The set is well-scoped, though a few tools could be merged (e.g., diagnose_vps and individual checks).
The tool surface covers monitoring and basic state changes for Docker and VPS, but lacks container creation/removal, Docker Compose down, and deeper system management. The diagnostic_command is undefined. Notable gaps exist for a truly 'Advanced' server.
Related MCP Connectors
Linux server administration over OAuth MCP: shell, Docker, systemd, files and monitoring.
- browser-sshDeprecatedcom.browserssh
Scoped, audited SSH exec, sessions, and SFTP on your saved servers without exposing credentials
Manage remote servers, SSH terminals, files, databases and proxies with scoped access and approvals.
Let AI operate servers without SSH. Choose actions, approve risky changes, and audit every step.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables secure, read-only inspection of a VPS over SSH through approved operations such as system health, disk usage, container logs, and service status, without giving the AI unrestricted shell access.81MIT
- AlicenseAqualityCmaintenanceEnables MCP clients to inspect and manage a Dokku host over SSH with structured tools, read-only defaults, and explicit guardrails for safe operations.10MIT
- FlicenseNot gradedqualityBmaintenanceEnables controlled diagnostics and limited actions on a VPS through safe, auditable tools instead of an unrestricted root terminal, including read-only checks, basic Docker status, allowed-path file reading/searching, and YAML/JSON validation.-
- AlicenseNot gradedqualityBmaintenanceEnables read-only inspection and confirmed mutation operations on a single VPS over SSH, including host health, Docker, Compose, Swarm, firewall, and system debugging tools.36 npm1MIT