Cloud & KubernetesJA · Japanese

Architecting a Local AI Model Runtime with MCP and Docker for Claude Code

An architecture combining Docker, the MCP protocol, and FastAPI integrates local image generation models into Claude Code, optimizing performance across containers and local workstations.

Curated by Vibe DevOps · approx. 532 words

Key Takeaways

  • FastAPI acts as the core service, exposing a unified API for both CLI tools and the MCP server.
  • On Apple Silicon Macs, bare-metal execution with MPS delivers significantly better performance than CPU-bound containers.
  • The system implements an LRU (least recently used) cache eviction mechanism to conserve system memory.

From Original Source

Service Architecture and Execution Optimization

The image generation engine is built around a centralized FastAPI server that handles all core business logic. Both the CLI utility and the MCP server act as clients interacting with this endpoint. Instead of baking large weight files directly into container images, the system fetches and caches them on first launch.

Because macOS containers cannot leverage Apple Silicon hardware acceleration, running directly on the host Mac provides optimal performance, while Docker Compose profiles are maintained for dedicated Linux or Windows GPU hosts.

  • The cache automatically evicts the least recently used models based on a predefined policy.
  • A hardware diagnostic utility automatically inspects available RAM to recommend an optimal runtime profile.

From Original Source

Resolving Network Bottlenecks and Protocol Compatibility

When downloading model weights from the repository, network throughput stalled at 0 B/s due to a new concurrent download mechanism. This was resolved by disabling the experimental transfer feature via environment variables to fall back to the standard protocol.

Additionally, MCP integration encountered breaking API changes between v1 and v2 of the Python SDK. Conditional branching was implemented to maintain backward compatibility across both method naming conventions.

Vibe DevOps Editorial Commentary

Vibe DevOps Perspective

Vibe DevOps Perspective: When integrating local AI models into automated engineering workflows, balancing container encapsulation with hardware acceleration is critical. While containers standardize deployment on Linux servers, running natively on workstations with integrated GPUs avoids resource waste and driver abstraction overhead. Decoupling the core API service from the MCP protocol layer also allows the architecture to scale flexibly without introducing unnecessary infrastructure bloat.

Commands & Configuration Snippets

Verbatim extract for quick lookup. Verify against your infrastructure before running.

docker compose -f compose.yml -f compose.gpu.yml up -d

Launch container with GPU support on Linux or Windows

docker compose up -d

Launch container in CPU mode

claude mcp add imagegen -- "$PWD/.venv/bin/python" "$PWD/mcp_server.py"

Register MCP server with Claude Code

HF_HUB_DISABLE_XET=1

Environment variable to disable parallel downloads causing network congestion

⚠️ Operational Caveats & Limitations

  • Actual performance depends heavily on the workstation's hardware specifications and available memory.
  • Published container images do not bundle model weights; weights must be downloaded on initial run.

Read original post at Zenn — Topic Docker ↗


Explore Next on Vibe DevOps

More Global DevOps News