Major refactoring from monolithic server.py to modular MCPMixin pattern: Architecture: - src/esxi_mcp_server/ package with proper src-layout - FastMCP MCPMixin pattern for tool organization - Separate mixins for each functional area - Shared VMwareConnection class with lazy datastore/network lookup New Mixins Added: - DiskManagementMixin: add_disk, remove_disk, extend_disk, list_disks, attach_iso, detach_iso - NICManagementMixin: add_nic, remove_nic, change_nic_network, connect_nic, set_nic_mac, list_nics - HostManagementMixin: get_host_info, enter/exit_maintenance_mode, list_services, start/stop_service, set_service_policy, get/configure_ntp, reboot_host, shutdown_host, get_host_hardware, get_host_networking - OVFManagementMixin: deploy_ovf, export_vm_ovf, list_ovf_networks - ResourcesMixin: Added move_datastore_file, copy_datastore_file Streaming Support: - Generator-based streaming for datastore downloads - Memory-efficient large file handling with save_to parameter - Chunked uploads from disk Testing: - test_client.py: MCP SDK-based test client - Validates all 74 tools against real ESXi host Build System: - pyproject.toml with uv, ruff configuration - Docker dev/prod modes with hot-reload - Updated Makefile for uv-based workflow
68 lines
1.7 KiB
Docker
68 lines
1.7 KiB
Docker
# ESXi MCP Server - Modern Python with uv
|
|
# Multi-stage build for optimal image size
|
|
|
|
# Build stage
|
|
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Enable bytecode compilation for production
|
|
ENV UV_COMPILE_BYTECODE=1
|
|
ENV UV_LINK_MODE=copy
|
|
|
|
# Install dependencies first (cached layer)
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
|
uv sync --frozen --no-install-project --no-dev
|
|
|
|
# Install project
|
|
COPY pyproject.toml uv.lock ./
|
|
COPY src ./src
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv sync --frozen --no-dev --no-editable
|
|
|
|
# Production stage
|
|
FROM python:3.11-slim-bookworm AS production
|
|
|
|
# Create non-root user
|
|
RUN groupadd -r mcpuser && useradd -r -g mcpuser mcpuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies only
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& apt-get clean
|
|
|
|
# Copy virtual environment from builder
|
|
COPY --from=builder /app/.venv /app/.venv
|
|
|
|
# Create directories
|
|
RUN mkdir -p /app/logs /app/config \
|
|
&& chown -R mcpuser:mcpuser /app
|
|
|
|
# Environment configuration
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
|
|
# Default to SSE transport for Docker
|
|
ENV MCP_TRANSPORT=sse
|
|
ENV MCP_HOST=0.0.0.0
|
|
ENV MCP_PORT=8080
|
|
|
|
# Switch to non-root user
|
|
USER mcpuser
|
|
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080')" || exit 1
|
|
|
|
# Run the MCP server
|
|
ENTRYPOINT ["esxi-mcp-server"]
|
|
CMD ["--transport", "sse"]
|