Homelab MCP Server

Homelab MCP Server

Enables Claude to monitor and manage homelab infrastructure including Docker containers, OPNsense firewall, and TrueNAS storage with configurable capability levels from read-only monitoring to full management control.

Category
访问服务器

README

Homelab MCP Server

A remote MCP (Model Context Protocol) server for managing homelab infrastructure. Provides Claude with tools to monitor and manage Docker containers, OPNsense firewall, and TrueNAS storage.

Features

  • 4 Capability Levels: From read-only monitoring to full management control
  • Docker Management: List, monitor, control containers and Dockge stacks
  • OPNsense Integration: Monitor firewall status and restart services
  • TrueNAS Integration: Check pool health, manage datasets, create snapshots
  • System Monitoring: CPU, memory, disk usage on the host

Quick Start

1. Prerequisites

  • Docker and Docker Compose installed on target host (Wharf)
  • OPNsense API credentials (optional)
  • TrueNAS API key (optional)
  • Node.js 20+ (for local development)

2. Setup

# Clone or copy the project to your host
cd homelab-mcp

# Copy example environment file
cp .env.example .env

# Generate a secure API key
openssl rand -hex 32

# Edit .env and add your credentials
nano .env

3. Configuration

Edit .env with your settings:

CAPABILITY_LEVEL=1        # Start with level 1 (read-only)
API_KEY=your-api-key-here # Use the generated key
PORT=3005

# OPNsense (optional)
OPNSENSE_HOST=10.0.0.1
OPNSENSE_API_KEY=your-key
OPNSENSE_API_SECRET=your-secret

# TrueNAS (optional)
TRUENAS_HOST=10.0.0.105
TRUENAS_API_KEY=your-key

4. Build and Deploy

# Build TypeScript
npm install
npm run build

# Build Docker image
docker compose build

# Start the server
docker compose up -d

# Check logs
docker compose logs -f

5. Configure Claude Desktop

Add to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "homelab": {
      "command": "node",
      "args": ["/path/to/homelab-mcp/dist/index.js"],
      "env": {
        "CAPABILITY_LEVEL": "1",
        "API_KEY": "your-api-key-here",
        "OPNSENSE_HOST": "10.0.0.1",
        "OPNSENSE_API_KEY": "your-key",
        "OPNSENSE_API_SECRET": "your-secret",
        "TRUENAS_HOST": "10.0.0.105",
        "TRUENAS_API_KEY": "your-key"
      }
    }
  }
}

Remote Access (Claude Chat)

For accessing the MCP server from Claude Chat (web interface), deploy with HTTP transport:

  1. Set environment variables in .env:

    PORT=3000
    API_KEY=your-generated-key
    CAPABILITY_LEVEL=1
    
  2. Deploy the container:

    docker compose up -d
    
  3. Configure reverse proxy (e.g., Traefik, Pangolin, nginx) to route mcp.handley.io to http://localhost:3000

  4. Add DNS record pointing mcp.handley.io to your server

  5. In Claude Chat, add the MCP server:

    • URL: https://mcp.handley.io/mcp
    • Authentication: Bearer token
    • Token: Your API_KEY value

OAuth 2.0 Authentication (for Claude Chat)

Claude Chat requires OAuth 2.0 for custom connectors. This server supports the Client Credentials flow.

  1. Generate OAuth credentials:

    # Generate client ID
    openssl rand -hex 32
    
    # Generate client secret
    openssl rand -hex 32
    
  2. Add to .env:

    OAUTH_CLIENT_ID=your-generated-client-id
    OAUTH_CLIENT_SECRET=your-generated-client-secret
    
  3. In Claude Chat, add the connector:

    • Name: Homelab
    • Remote MCP server URL: https://mcp.handley.io/mcp
    • OAuth Client ID: Your generated client ID
    • OAuth Client Secret: Your generated client secret

The server will issue access tokens valid for 1 hour. Claude Chat handles token refresh automatically.

Endpoints

When running in HTTP mode:

Endpoint Method Auth Description
/health GET No Health check, returns status and capability level
/oauth/token POST No OAuth 2.0 token endpoint
/mcp POST Yes MCP protocol endpoint
/ POST Yes Alias for /mcp

Testing

# Test health endpoint
curl https://mcp.handley.io/health

# Get an access token
curl -X POST https://mcp.handley.io/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"

# Use the token
curl https://mcp.handley.io/mcp \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

Capability Levels

Level Name Capabilities
1 Monitor Read-only: container status, logs, stats, system info, service health
2 Operate Level 1 + start/stop/restart containers and services
3 Configure Level 2 + read compose files, configs, volumes, networks
4 Manage Level 3 + write configs, create/remove containers, exec commands

Recommendation: Start with Level 1 and increase as needed.

Available Tools

Level 1 - Monitor

  • docker_list_containers - List all containers
  • docker_container_logs - Get container logs
  • docker_container_stats - Get container CPU/memory stats
  • system_info - Get host system info
  • opnsense_status - Get OPNsense status
  • truenas_status - Get TrueNAS pool status
  • truenas_alerts - Get TrueNAS alerts

Level 2 - Operate

  • docker_restart_container - Restart a container
  • docker_start_container - Start a container
  • docker_stop_container - Stop a container
  • opnsense_service_restart - Restart OPNsense service

Level 3 - Configure

  • docker_read_compose - Read docker-compose.yml
  • docker_list_volumes - List Docker volumes
  • docker_list_networks - List Docker networks
  • docker_inspect_container - Inspect container details
  • truenas_list_datasets - List ZFS datasets
  • truenas_dataset_info - Get dataset details

Level 4 - Manage

  • docker_write_compose - Write docker-compose.yml
  • docker_compose_up - Deploy a stack
  • docker_compose_down - Remove a stack
  • docker_exec - Execute command in container
  • truenas_create_snapshot - Create ZFS snapshot

Development

# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Type check
npx tsc --noEmit

Security Notes

  • The API key should be kept secret and rotated periodically
  • Start with the lowest capability level you need
  • For Level 4, the /opt/stacks mount must be :rw instead of :ro
  • The container requires access to the Docker socket for container management
  • OPNsense and TrueNAS APIs use self-signed certificates by default

Troubleshooting

Container won't start

# Check logs
docker compose logs homelab-mcp

# Common issues:
# - Missing API_KEY in .env
# - Invalid CAPABILITY_LEVEL (must be 1-4)
# - Docker socket not accessible

Tools failing

# Test OPNsense API
curl -k -u "key:secret" https://10.0.0.1/api/core/system/status

# Test TrueNAS API
curl -k -H "Authorization: Bearer YOUR_KEY" https://10.0.0.105/api/v2.0/system/info

# Check network connectivity from container
docker exec homelab-mcp ping 10.0.0.1

Permission issues

If you need Level 4 (write access to stacks), update the volume mount:

volumes:
  - /opt/stacks:/opt/stacks:rw  # Change from :ro to :rw

License

MIT

Contributing

Issues and pull requests welcome!

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选