FROM python:3.11.13-slim-bookworm

# Install uv
COPY --from=ghcr.io/astral-sh/uv:0.8.17 /uv /bin/

WORKDIR /app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1
# Copy from the cache instead of linking
ENV UV_LINK_MODE=copy

# 1. Install dependencies first (Layer Caching)
COPY uv.lock pyproject.toml .python-version README.md /app/
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-install-project --no-dev

# 2. Copy the entire src directory (Matches hatchling config)
COPY ./src /app/src

# 3. Install the project itself
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-dev

# 4. Use the virtual env directly
ENV PATH="/app/.venv/bin:$PATH"

# MCP Config
ENV MCP_TRANSPORT=http
ENV MCP_HOST=0.0.0.0
ENV MCP_PORT=8000
EXPOSE 8000

# Execute the script defined in pyproject.toml directly
# This avoids 'uv run' and its runtime network checks
CMD ["run-mcp-server"]
