# MariaDB MCP Server (SSE) — upstream: https://github.com/MariaDB/mcp
# Build clones MariaDB/mcp at MARIADB_MCP_GIT_REF (branch or tag).

FROM python:3.11-slim AS builder

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential curl ca-certificates git \
    && rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"

WORKDIR /app

ARG MARIADB_MCP_GIT_REF=main
RUN git clone --depth 1 --branch "${MARIADB_MCP_GIT_REF}" https://github.com/MariaDB/mcp.git . \
    || (git clone --depth 1 https://github.com/MariaDB/mcp.git . && git fetch --depth 1 origin "${MARIADB_MCP_GIT_REF}" && git checkout FETCH_HEAD)

RUN uv sync --no-dev

FROM python:3.11-slim

WORKDIR /app
ENV PATH="/app/.venv/bin:${PATH}"

COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/src /app/src

EXPOSE 9001

CMD ["python", "src/server.py", "--host", "0.0.0.0", "--transport", "sse"]
