Homelab MCP Server
Homelab MCP 服务器
通过模型上下文协议 (MCP) 实现 AI 驱动的家庭实验室基础设施管理
🏆 TestSprite 第二季黑客松参赛作品
分支: TestSprite_Hackathon | 最终通过率:10/10 (100%)
我构建了什么
homelab_mcp 是一个 MCP(模型上下文协议)服务器——它不使用 REST。TestSprite 用于测试 REST API。本次提交的核心挑战在于弥合这一协议差距。
解决方案: 一个 FastAPI 包装器,将所有 56 个 MCP 工具公开为标准的 REST 端点,并配有文档化的 HTTP 错误契约,因此 TestSprite 无需任何 MCP 协议知识即可测试完整的工具界面。
TestSprite Agent → FastAPI wrapper (port 8080) → homelab_mcp tools → Infrastructure错误契约设计
包装器没有返回通用的 500 错误,而是实现了三级 HTTP 错误契约:
状态码 | 含义 | 示例 |
422 | 请求字段缺失或格式错误 | 未提供必需的 |
412 | 基础设施前提条件未满足 | 设备 ID 未在站点地图中注册 |
424 | 外部依赖不可达 | SSH 目标 / Proxmox 主机宕机 |
424 失败依赖设计是最有趣的部分。与真实基础设施(SSH 主机、Proxmox API、TrueNAS)交互的工具在调用处理程序之前会运行 TCP 预检探测。如果目标不可达,包装器会返回带有结构化负载(status、host、port、protocol 和 requires 补救提示)的 424 错误,而无需触及处理程序。没有部分执行,也不会向不可达的主机泄露凭据。
一旦在 Swagger 规范中记录了此契约,TestSprite 就会自动为所有三种错误类型生成负面路径测试用例。
测试结果 — 五次运行周期
运行 | 通过率 | 关键变更 |
黑客松前基准 | ~40% | MCP 协议不匹配 — 全是测试工具故障,零服务器错误 |
运行 1 | 7/10 (70%) | FastAPI 包装器 + 424 规范 — 发现了真实错误 |
运行 2 | 9/10 (90%) | 逐路由 jsonschema 验证 — 修复了所有 56 个工具的 422 契约 |
运行 3 | 7/10 (70%) | 在修复 code_summary.yaml 后重新生成测试计划 — 更严格的测试暴露了新的差距 |
运行 4 | 8/10 (80%) | ResourceManager 生命周期连接 + 412 分类器模式 |
运行 5 | 10/10 (100%) | minItems 模式修复 + 一致的错误消息措辞 |
TestSprite 交付的修复
文件 | 变更 |
| 逐路由 jsonschema 验证器;带字段路径的 422;ResourceManager 的 FastAPI 生命周期;扩展错误分类器 |
| 当未注册漂移基准时短路至 412 |
|
|
| 用于分类器匹配的一致的“未找到设备”错误措辞 |
| 更正字段名称;记录每个工具的 412/422/424 契约 |
运行 TestSprite 测试套件
# Clone the hackathon branch
git clone -b TestSprite_Hackathon https://github.com/washyu/homelab_mcp.git
cd homelab_mcp
# Install dependencies
uv sync
# Start the FastAPI wrapper (no auth mode for testing)
uv run python run_server.py --openapi --port 8080 --no-auth
# TestSprite test cases are in testsprite_tests/
# Run via the TestSprite agent pointed at http://localhost:8080经验教训
MCP 服务器需要 REST 外观以适配传统的 API 测试工具
Swagger 规范就是你的测试计划 — 记录错误契约,TestSprite 就会为你生成测试
code_summary.yaml的准确性很重要 — 错误的字段名称会产生错误的测试在让 Claude Code 接近 TestSprite 之前添加 CLAUDE.md 防护栏 — 否则它会自动循环修复→重跑并耗尽额度
从 linter 和格式化程序中排除
testsprite_tests/— 像对待vendor/一样对待它每次运行后提交或复制报告 — 摘要每次都会被覆盖
认证和无认证模式需要单独运行 — 无法在一次 TestSprite 会话中覆盖两者
完整文章:shaunjackson.space
一个 Python MCP 服务器,使 AI 助手能够管理、部署和监控家庭实验室基础设施。工具涵盖 SSH 发现、虚拟机管理、服务安装、网络拓扑映射、Proxmox 操作和凭据管理。
Related MCP server: remote-admin-mcp
主要功能
SSH 发现 -- 从任何系统收集全面的硬件和软件信息
服务安装 -- 从模板部署 Jellyfin、Pi-hole、Ollama、Home Assistant 等
Proxmox 集成 -- 完全的 API 访问权限以及社区脚本发现
虚拟机/容器生命周期 -- 部署、控制和移除 Docker 和 LXD 工作负载
网络映射 -- 发现设备、分析拓扑并跟踪变更
Terraform 和 Ansible -- 具有漂移检测和剧本的状态管理部署
凭据管理 -- 注册服务器一次,无需重新输入凭据即可连接
快速入门
# Install from PyPI (recommended — no clone needed)
uvx homelab-mcp
# Or clone and run from source
git clone https://github.com/washyu/homelab_mcp.git
cd homelab_mcp
uv sync && uv run python run_server.py有关完整演练(环境变量、MCP 客户端配置、首次工具调用),请参阅 设置指南。
文档
指南 | 描述 |
从零到首次工具调用 | |
所有带有参数和示例的工具 | |
环境变量和 CLI 选项 | |
Claude Desktop 集成指南 |
工作原理
设置 -- 服务器在首次运行时生成 SSH 密钥对 (
~/.ssh/mcp_admin_rsa)接入主机 -- 使用
setup_mcp_admin在目标系统上创建受管用户验证 -- 使用
verify_mcp_admin确认无密码 SSH 访问管理 -- 发现硬件、安装服务、控制虚拟机并映射网络
服务器使用 MCP 协议通过 stdio 进行通信。将其连接到任何兼容 MCP 的客户端(Claude Desktop 等)并通过自然语言进行交互。
凭据管理
存储 SSH 和 Proxmox 凭据一次,以便服务器在每次连接时自动注入它们:
# Store an SSH credential
homelab-mcp credentials add 192.168.1.10 admin
# Store an SSH key-based credential (stores the key file path in the keyring, not the key)
homelab-mcp credentials add 192.168.1.10 admin --key-path ~/.ssh/id_ed25519
# Store a Proxmox API credential
homelab-mcp credentials add 192.168.1.200 root@pam --type proxmox
# Update an existing credential — `add` is upsert; re-running replaces the stored entry
homelab-mcp credentials add 192.168.1.10 admin
# List stored credentials
homelab-mcp credentials list
homelab-mcp credentials list --type proxmox
# Remove a credential
homelab-mcp credentials remove 192.168.1.10CLI 提供对凭据的完全 CRUD 操作:add(创建/更新 — upsert)、list(读取)、remove(删除)。没有单独的 update 子命令 — 重新运行 add 会替换密钥环密钥和注册条目的认证类型。
凭据存储在操作系统密钥环中(Linux 上为 libsecret,macOS 上为 Keychain)。当操作系统密钥环不可用(无头服务器)时,凭据会回退到环境变量。
有关完整文档,请参阅 凭据 CLI 参考。
MCP 客户端配置
从 PyPI (uvx) — 推荐:
{
"mcpServers": {
"homelab": {
"command": "uvx",
"args": ["homelab-mcp"]
}
}
}从源码克隆:
{
"mcpServers": {
"homelab": {
"command": "uv",
"args": ["run", "python", "run_server.py"],
"cwd": "/path/to/homelab_mcp"
}
}
}开发
# Install with dev dependencies
uv sync --group dev
# Run tests (unit only, no Docker required)
uv run pytest tests/ -m "not integration"
# Code quality
uv run ruff check src/ tests/
uv run mypy src/有关生产部署的详细信息,请参阅 DEPLOYMENT.md。
项目结构
src/homelab_mcp/
server.py # MCP server with JSON-RPC protocol
tool_schemas/ # Tool definitions (8 schema files)
tool_annotations.py # MCP annotation hints per tool
ssh_tools.py # SSH discovery and hardware detection
service_installer.py # Service installation framework
infrastructure_crud.py # Infrastructure lifecycle management
vm_operations.py # VM/container operations
sitemap.py # Network topology mapping
database.py # SQLite device tracking
error_handling.py # Centralized error handling
credential_store.py # OS keyring credential storage
log_filter.py # Credential redaction for log output
prompt_registry.py # MCP prompts registry
resource_readers.py # MCP resource read handlers
service_templates/ # YAML service definitions
testsprite_tests/ # TestSprite generated test suite (hackathon)
tests/ # Unit and integration tests
docs/ # Full documentation致谢
Proxmox 社区脚本集成由 community-scripts/ProxmoxVE (MIT 许可证) 提供支持。
贡献
Fork 本仓库
创建功能分支
为新功能编写测试
确保所有测试通过
提交 Pull Request
许可证
MIT 许可证 -- 详情请参阅 LICENSE 文件。
Available Tools
58 toolsanalyze_network_topologyBRead-onlyIdempotent
Analyze the network topology and provide insights about the discovered devices
Inputs: no named parameters.
bulk_discover_and_mapAIdempotent
Discover multiple devices via SSH and store them in the network site map database
Inputs: targets (required).
check_ansible_serviceBRead-onlyIdempotent
Check the status of an Ansible-managed service deployment
Inputs: hostname (required), service_name (required), password, username.
check_service_requirementsARead-onlyIdempotent
Check if a device meets the requirements for a service installation
Inputs: hostname (required), service_name (required), password, username.
clone_proxmox_vmB
Clone a VM or container to create a new one
Inputs: node (required), vmid (required), new_vmid (required), full, +3 more.
control_vmBIdempotent
Control VM state (start, stop, restart)
Inputs: action (required), vm_name (required), platform (required), device_id (required).
create_infrastructure_backupC
Create a backup of current infrastructure state
Inputs: device_ids, backup_name, backup_scope, include_data.
create_proxmox_lxcB
Create a new LXC container on Proxmox
Inputs: node (required), vmid (required), hostname (required), host, +10 more.
create_proxmox_vmB
Create a new VM (QEMU) on Proxmox
Inputs: host (required), name (required), node (required), vmid (required), +10 more.
decommission_deviceADestructiveIdempotent
Safely remove a device from the network infrastructure. Stops services, removes the device from clusters, optionally migrates services per migration_plan, then deletes the sitemap row. Use remove_device for inventory-only deletion of one row; use purge_devices for bulk filter-based inventory deletion; use decommission_device when host-side cleanup (stop services, remove from clusters) is required before deletion.
Inputs: device_id (required), dry_run, force_removal, validate_only, +1 more.
decommission_device_previewARead-onlyIdempotent
Preview what decommission_device would affect without executing. Returns a structured dry-run report. No infrastructure is modified.
Inputs: device_id (required), force_removal, validate_only, migration_plan.
delete_proxmox_vmBDestructiveIdempotent
Delete a VM or container from Proxmox
Inputs: node (required), vmid (required), host, purge, +2 more.
delete_proxmox_vm_previewARead-onlyIdempotent
Preview what delete_proxmox_vm would affect without executing. Returns a structured dry-run report. No VM is deleted.
Inputs: node (required), vmid (required), host, purge, +1 more.
deploy_infrastructureB
Deploy new infrastructure based on AI recommendations or user specifications
Inputs: deployment_plan (required), validate_only.
deploy_vmB
Deploy a new VM/container on a specific device
Inputs: vm_name (required), platform (required), device_id (required), vm_config.
destroy_terraform_serviceADestructiveIdempotent
Destroy a Terraform-managed service and clean up all resources
Inputs: hostname (required), service_name (required), dry_run, password, +1 more.
destroy_terraform_service_previewARead-onlyIdempotent
Preview what destroy_terraform_service would affect without executing. Returns a structured dry-run report. No resources are destroyed.
Inputs: hostname (required), service_name (required), password, username.
discover_and_mapAIdempotent
Discover a device via SSH and store it in the network site map database. Recommended follow-up: run the configure_host_fingerprint prompt to capture per-host capability signals for drift detection.
Inputs: hostname (required), port, key_path, username.
get_device_changesBRead-onlyIdempotent
Get change history for a specific device
Inputs: device_id (required), limit.
get_network_sitemapARead-onlyIdempotent
Get all discovered devices from the network site map database
Inputs: no named parameters.
get_proxmox_node_statusARead-onlyIdempotent
Get detailed status of a Proxmox node (CPU, memory, uptime, etc.)
Inputs: node (required), host.
get_proxmox_script_infoARead-onlyIdempotent
Get detailed information about a specific Proxmox community script
Inputs: script_name (required), category.
get_proxmox_vm_statusBRead-onlyIdempotent
Get status of a specific VM or container
Inputs: node (required), vmid (required), host, vm_type.
get_service_infoCRead-onlyIdempotent
Get detailed information about a specific service
Inputs: service_name (required).
get_service_statusCRead-onlyIdempotent
Get the current status of an installed service
Inputs: hostname (required), service_name (required), password, username.
get_vm_logsARead-onlyIdempotent
Get logs from a specific VM/container
Inputs: vm_name (required), platform (required), device_id (required), lines.
get_vm_statusARead-onlyIdempotent
Get detailed status of a specific VM
Inputs: vm_name (required), platform (required), device_id (required).
install_serviceC
Install a homelab service on a target device
Inputs: hostname (required), service_name (required), password, username, +1 more.
list_available_servicesARead-onlyIdempotent
List all available homelab services that can be installed
Inputs: no named parameters.
list_keyring_credentialsARead-onlyIdempotent
List hosts that have credentials stored in the OS keyring registry. Call this before ssh_discover or ssh_execute_command to check whether a host has stored credentials. Returns hostname and username per entry.
Inputs: credential_type.
list_proxmox_resourcesBRead-onlyIdempotent
List all Proxmox cluster resources (VMs, containers, nodes, storage).
Inputs: host, resource_type.
list_registered_serversARead-onlyIdempotent
List all registered servers with their SSH credentials and connection status
Inputs: active_only.
list_vmsARead-onlyIdempotent
List all VMs/containers on a device
Inputs: device_id (required), platforms.
manage_proxmox_vmCIdempotent
Manage a VM or container (start, stop, shutdown, reboot, reset, suspend, resume)
Inputs: node (required), vmid (required), action (required), host, +1 more.
plan_terraform_serviceAIdempotent
Generate a Terraform plan to preview changes without applying them
Inputs: hostname (required), service_name (required), password, username, +1 more.
purge_devicesADestructiveIdempotent
Bulk-delete sitemap rows by filter. Single mutually-exclusive filter per call selected by filter_type. Supported filter_types: 'hostname' (exact-match string, no glob/LIKE), 'last_seen_older_than_days' (integer N — rows where last_seen < now - N days, exclusive boundary; N=0 matches all rows older than this instant), 'status' (exact match string like 'error' or 'success'), 'ip_range' (CIDR string like '192.168.1.0/24' or '2001:db8::/32' — rows whose connection_ip is not a valid IP are silently skipped). Composite/ANDed filters are NOT supported (use two calls). Pass dry_run=true to preview the candidate set without deleting. Zero-match returns success with purged_count=0, never an error. Note: filter_type='status', value='error' covers ONLY status='error' rows; use purge_failed_discoveries for the broader failed-discovery filter (includes zombie hostnames). Use remove_device for inventory-only deletion of one row; use purge_devices for bulk filter-based inventory deletion; use decommission_device when host-side cleanup (stop services, remove from clusters) is required before deletion.
Inputs: value (required), filter_type (required), dry_run.
purge_devices_previewARead-onlyIdempotent
Preview the result of purge_devices without persisting. Returns the candidate set the bulk delete would touch. Read-only — no DB write. Phase 44 D-11.
Inputs: value (required), filter_type (required).
purge_failed_discoveriesADestructiveIdempotent
Remove sitemap rows for devices where discovery failed (status='error' or empty/null/'unknown' hostname). Pass dry_run=true to preview the removal candidates without deleting them. (Equivalent to purge_devices with the failed-discovery filter — preserves the 4-clause OR semantics; bare purge_devices(filter_type='status', value='error') matches ONLY status='error' rows, NOT zombie hostnames.) Use remove_device for inventory-only deletion of one row; use purge_devices for bulk filter-based inventory deletion; use decommission_device when host-side cleanup (stop services, remove from clusters) is required before deletion.
Inputs: dry_run.
refresh_terraform_serviceBIdempotent
Refresh Terraform state and detect configuration drift
Inputs: hostname (required), service_name (required), password, username.
register_serverAIdempotent
Verify SSH connectivity to a registered server using keyring credentials. Does not write any credentials — credentials must already be stored via homelab-mcp credentials add <hostname> <username> in the CLI. Returns a status object with verified=true on successful handshake.
Inputs: hostname (required), username (required), port, display_name.
remove_deviceADestructiveIdempotent
Delete a single sitemap row by device_id. Pure SQL DELETE on the sitemap row plus cascade DELETE on discovery_history rows for that device_id. No SSH dial, no Ansible runs, no Terraform plans on the handler call path. The keyring credential entry bound via ssh_credential_id is preserved — only the sitemap row is dropped, so a subsequent discover_and_map can re-bind without re-adding the credential. Pass dry_run=true to preview the would-delete row payload without writing. Use remove_device for inventory-only deletion of one row; use purge_devices for bulk filter-based inventory deletion; use decommission_device when host-side cleanup (stop services, remove from clusters) is required before deletion.
Inputs: device_id (required), dry_run.
remove_device_previewARead-onlyIdempotent
Preview the result of remove_device without persisting. Returns the would-delete row payload. Read-only — no DB write, no keyring touch. Phase 44 D-11.
Inputs: device_id (required).
remove_vmCDestructiveIdempotent
Remove a VM/container from a device
Inputs: vm_name (required), platform (required), device_id (required), force, +1 more.
remove_vm_previewARead-onlyIdempotent
Preview what remove_vm would affect without executing. Returns a structured dry-run report. No infrastructure is modified.
Inputs: vm_name (required), platform (required), device_id (required), force.
rollback_infrastructure_changesBDestructiveIdempotent
Rollback recent infrastructure changes
Inputs: backup_id (required), dry_run, device_ids, validate_only, +1 more.
rollback_infrastructure_changes_previewARead-onlyIdempotent
Preview what rollback_infrastructure_changes would affect without executing. Returns a structured dry-run report. No infrastructure is modified.
Inputs: backup_id (required), device_ids, validate_only, rollback_scope.
run_ansible_playbookB
Run an existing Ansible playbook for a service
Inputs: hostname (required), service_name (required), tags, password, +3 more.
scale_servicesB
Scale services up or down based on resource analysis
Inputs: scaling_plan (required), validate_only.
scan_infrastructure_driftARead-onlyIdempotent
Scan for infrastructure drift against the sitemap. Returns a four-bucket coverage report — probed_ok (sitemap host probed successfully), unreachable (sitemap host that did not respond), unknown (reserved for Phase 39 — infrastructure present on a Proxmox hypervisor but absent from sitemap), and changed (reserved for Phase 39 — fingerprint differs from stored). All four buckets are always present in the response (empty arrays for Phase-39-reserved buckets) so client code can iterate without defensive checks. Each scan also returns a counts sub-dict mirroring bucket sizes and, when zero hosts were scanned (empty sitemap or filter narrowed to zero), a top-level guidance field pointing to the sitemap CRUD tools (discover_and_map, get_network_sitemap, purge_failed_discoveries, decommission_device). Recovery from credential-resolution failure is handled via 'homelab-mcp credentials add --type proxmox'.
Inputs: node, vm_type.
search_proxmox_scriptsARead-onlyIdempotent
Search Proxmox community installation scripts from the community-scripts/ProxmoxVE repository
Inputs: query (required), category, include_metadata.
ssh_discoverARead-onlyIdempotent
SSH into a system and gather hardware/system information. If credentials were stored with credentials add, username and password are auto-injected from the keyring — omit them. If authentication fails with 'No credentials found', run homelab-mcp credentials add <hostname> <username> in the terminal or call list_keyring_credentials to see what is already stored. Recommended follow-up after onboarding: run the configure_host_fingerprint prompt to capture per-host capability signals for drift detection.
Inputs: hostname (required), port, key_path, password, +1 more.
ssh_execute_commandA
Execute a command on a remote system via SSH. If credentials were stored with credentials add, username and password are auto-injected from the keyring — omit them. If authentication fails with 'No credentials found', run homelab-mcp credentials add <hostname> <username> in the terminal or call list_keyring_credentials to see what is already stored.
Inputs: command (required), hostname (required), port, sudo, +2 more.
start_interactive_shellA
Start an interactive web-based shell session on a remote system. Opens a browser-based terminal with full TTY support for running interactive commands and scripts. Perfect for Proxmox community scripts or any interactive command-line tools. Requires HTTP server mode (--http flag). In stdio mode, this tool returns an error with setup instructions.
Inputs: hostname (required), port, password, username, +1 more.
suggest_deploymentsBRead-onlyIdempotent
Suggest optimal deployment locations based on current network topology and device capabilities
Inputs: no named parameters.
update_device_configA
Update configuration of an existing device
Inputs: device_id (required), config_changes (required), validate_only, backup_before_change.
update_device_fingerprintAIdempotent
Merge fingerprint data (kernel, OS, package digest, capabilities) into a device's sitemap row. Top-level keys overwrite (last-write-wins). The capabilities sub-dict updates one level deep — each incoming top-level capability key REPLACES its stored entry entirely (NOT a recursive merge); stored capability keys not present in the call are preserved. Callers updating any field within a capability must pass the full capability dict. Run discover_and_map first to populate the device. See the configure_host_fingerprint prompt for the conversational workflow. Persists to DB and bumps updated_at; last_seen is preserved (Phase 38 REVIEW-FIX WR-03).
Inputs: hostname (required), fingerprint (required).
update_device_fingerprint_previewARead-onlyIdempotent
Preview the merge result of update_device_fingerprint without persisting. Returns the would-be merged fingerprint dict using the same merge rules: top-level overwrite + capabilities one-level overwrite (incoming capability keys replace stored entries entirely; not recursive). Read-only — no DB write, no last_seen or updated_at mutation. Phase 38 D-05c.
Inputs: hostname (required), fingerprint (required).
validate_infrastructure_changesARead-onlyIdempotent
Validate infrastructure changes before applying them
Inputs: change_plan (required), validation_level.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 58 tools
While most tools target distinct actions, the abundance of deletion/removal variants (remove_device, purge_devices, decommission_device, etc.) and overlapping VM management tools create ambiguity. Agents may struggle to differentiate between subtly different tools like decommission_device and purge_failed_discoveries.
Tool names follow a consistent verb_noun pattern with snake_case (e.g., create_proxmox_vm, get_network_sitemap). Preview tools append '_preview' uniformly. Minor deviations like start_interactive_shell are clear but break the pattern slightly.
At 58 tools, the count is high for a single server. The broad scope (network discovery, Proxmox, services, Terraform) justifies many tools, but some could be consolidated (e.g., multiple deletion methods). The set feels slightly heavy but not extreme.
The tool set covers major lifecycle stages (create, read, update, delete, preview) across multiple domains. Notable gaps include lack of a direct sitemap update tool and limited service management beyond installation. However, the presence of preview tools for dangerous operations strengthens completeness.
Maintenance
Related MCP Connectors
Create, run and manage Homemade dev VMs and projects from your AI agent.
Let AI operate servers without SSH. Choose actions, approve risky changes, and audit every step.
- DNS-DATA RemoteDeprecatedcom.dns-data
Connect AI assistants to authorized Windows and macOS devices for files, commands, and management.
Provides capabilities that let LLM agents perform a range of infrastructure management tasks.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables management of homelab infrastructure, including Docker/Podman containers, Ollama AI models, Pi-hole DNS, Unifi networks, and Ansible inventory, with built-in security checks and automated pre-push validation.1MIT
- AlicenseAqualityBmaintenanceEnables AI assistants to manage remote servers via SSH with agentless command execution, file operations, and service management.9MIT
- AlicenseNot gradedqualityCmaintenanceEnables assistants to operate a home lab through one authenticated HTTPS endpoint, including managing Proxmox VMs and containers, Home Assistant and ESPHome devices, Docker, shell access over SSH, Fully Kiosk tablets, and network discovery.MIT
- AlicenseNot gradedqualityDmaintenanceConnects AI agents to self-hosted infrastructure such as Unifi, Proxmox, Plex, Radarr/Sonarr, SABnzbd, Portainer, OPNsense, Home Assistant, and Traefik through a single MCP endpoint. It exposes consolidated tools, resources, prompts, and a matching REST API so assistants and automation workflows can inspect, manage, and troubleshoot homelab services.3MIT