FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy source
COPY . .

# Install nifty-mcp in production mode
RUN pip install --no-cache-dir -e .

# Pre-install the DuckDB httpfs extension so it's cached in the image.
# Without this, the first tool call triggers a network download of the extension binary.
RUN python3 -c "import duckdb; conn = duckdb.connect(':memory:'); conn.execute('INSTALL httpfs'); conn.close()"

# Create data directory
RUN mkdir -p /data/.nifty-mcp

# Expose port for MCP server (if using SSE transport)
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# Default: start server with streamable-http transport (POST /mcp)
ENV NIFTY_MCP_DATA_DIR=/data/.nifty-mcp
CMD ["nifty-mcp", "serve", "--transport", "streamable-http"]
