# Hosting stack for the seed-mcp MCP server.
#
# This compose file is meant to live in Drawbar's deploy stack and is
# included here as the canonical reference. The seed-mcp image is
# self-contained — corpus + Chroma + BM25 are baked in by CI at build
# time — so the only host-side concerns are usage-log persistence and
# the shared reranker / Ollama sidecars.
#
# The reranker container (llama-rerank) is SHARED with crop-chem-docs.
# Drawbar's compose already has it from the crop-chem-docs deploy;
# don't duplicate it here when stacking the two MCPs together.
#
# Watchtower auto-pulls on :latest changes — but ONLY for containers
# labeled `com.centurylinklabs.watchtower.enable=true`.

services:

  # The seed-mcp server. Image is rebuilt nightly by .gitea/workflows/
  # refresh.yml; pulled via the public git.jpaul.io endpoint (CF
  # tunnels in front, so the 100 MB body cap doesn't matter on pulls).
  seed-mcp:
    image: git.jpaul.io/justin/seed-mcp:latest
    container_name: seed-mcp
    restart: unless-stopped
    ports:
      - "8001:8000"
    environment:
      PRODUCT_NAME: "crop_seed"
      PRODUCT_DOCS_URL: "https://git.jpaul.io/justin/seed-mcp"

      # Streamable-HTTP transport, stateless mode (every request gets
      # a fresh ephemeral session). Required for production: avoids
      # 404 storms when Watchtower recreates the container while
      # clients hold session IDs from the previous instance.
      MCP_TRANSPORT: streamable-http
      MCP_HOST: 0.0.0.0
      MCP_PORT: "8000"
      MCP_DISABLE_DNS_REBINDING_PROTECTION: "1"

      # Embedding pool. Drawbar's compose puts the seed-mcp on the
      # same docker network as Ollama; comma-separate multiple
      # endpoints (one per GPU) for indexing throughput. At runtime
      # only search_docs hits this (one embed per query, ~5ms).
      OLLAMA_URL: "http://ollama:11434"

      # Reranker. The llama.cpp sidecar serving jina-reranker-v2-base
      # is SHARED with crop-chem-docs. Drawbar's compose already
      # defines llama-rerank from the crop-chem-docs deploy; we just
      # point at the same DNS name. Falls back to dense-only on any
      # rerank error so MCP requests never block on the sidecar.
      RERANK_URL: "http://llama-rerank:8080"
      RERANK_POOL: "200"
      RERANK_TIMEOUT: "30"

      # Hybrid retrieval (BM25 + dense + RRF + exact-code prefilter).
      # Worth it for seed-mcp because farmer queries often contain
      # rare technical tokens — variety codes (DKC62-08RIB), trait
      # codes (XF/VT2PRIB), Rps gene names, disease abbreviations.
      HYBRID_SEARCH: "true"
      RRF_K: "60"

      # Usage telemetry. JSONL with daily rotation; 90-day retention.
      USAGE_LOG_DIR: /app/var/logs
      USAGE_LOG_KEEP_DAYS: "90"
    volumes:
      # Usage logs persist across container recreates. Mount point
      # creates host directory `./seed-mcp-logs/` on first run.
      - ./seed-mcp-logs:/app/var/logs
    labels:
      # Watchtower polls only containers with this label = true.
      com.centurylinklabs.watchtower.enable: "true"
    networks:
      - drawbar-mcp

  # NOTE: do NOT include llama-rerank or ollama here if you're stacking
  # this compose alongside crop-chem-docs. They're already defined in
  # the parent stack. The networks: external: true block below assumes
  # those services live on the drawbar-mcp shared network.

networks:
  drawbar-mcp:
    external: true
    name: drawbar-mcp
