# consult-mcp-server — multi-model panel orchestration MCP server.
#
# stdio transport. The container expects API keys via env (ANTHROPIC_API_KEY,
# OPENAI_API_KEY, GEMINI_API_KEY, OPENROUTER_API_KEY). Mount a volume at
# /root/.consult to persist runs across container starts.
FROM python:3.12-slim AS build

WORKDIR /app

# Copy the package metadata + sources. We keep tests + workflows out of the
# image — they're not needed at runtime and only pad the layer.
COPY pyproject.toml README.md ./
COPY consult/ ./consult/

# Install the engine + MCP adapter. `--no-cache-dir` shrinks the layer.
RUN pip install --no-cache-dir ".[mcp]"

FROM python:3.12-slim AS runtime
WORKDIR /app

# Copy the installed site-packages and console scripts from the build stage.
# This keeps the runtime image free of pip's caches and intermediate state.
COPY --from=build /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
# All consult-* console scripts (consult-mcp, -ledger, -view, -doctor, -gc).
# Glob keeps this correct as scripts are added or renamed in pyproject.toml.
COPY --from=build /usr/local/bin/consult-* /usr/local/bin/

# Drop root: the server needs nothing privileged — it talks stdio and
# writes run artifacts under its own home.
RUN useradd --create-home --uid 1000 consult
USER consult

# Run directory: per-run artifacts land under /home/consult/.consult/runs/.
# Mount a host volume here if you want runs to survive container restarts.
# The mkdir runs as the consult user so the volume mountpoint exists in the
# image with the right owner — Docker would otherwise create it root-owned
# at runtime and the server couldn't write its first run.
RUN mkdir -p /home/consult/.consult
VOLUME ["/home/consult/.consult"]

ENTRYPOINT ["consult-mcp"]
