FROM python:3.12-slim

WORKDIR /app

# The server imports switchboard_mcp.events, so the client package is
# installed alongside it. One definition of the protocol, running in both
# places, is the point of the layout.
COPY pyproject.toml README.md ./
COPY src ./src
COPY server ./server
RUN pip install --no-cache-dir . && \
    pip install --no-cache-dir -r server/requirements.txt

ENV PYTHONUNBUFFERED=1
WORKDIR /app/server

# gthread, not the default sync worker: /api/wait holds a request open for up
# to five minutes, and sync workers would block the whole process.
CMD gunicorn --bind 0.0.0.0:${PORT:-8099} \
    --worker-class gthread --workers 2 --threads 16 \
    --timeout 360 --graceful-timeout 30 \
    "app:create_app()"
