# syntax=docker/dockerfile:1

# Pinned revision of https://code.aneur.in/mirrors/webfetch-mcp (mirror of
# https://github.com/manooll/webfetch-mcp). Bump by updating this SHA once
# the mirror has synced past it; verify server.mjs still only reads
# SEARXNG_BASE / DEBUG / DETAILED_LOG from its environment before bumping.
ARG WEBFETCH_MCP_COMMIT=28135553531780c2a35c65e7c972f114f5e1baa4

# Pinned mcpo release (PyPI). Bump by checking the new version's CLI flags
# still match what entrypoint.sh assumes (--host/--port/--api-key/--).
ARG MCPO_VERSION=0.0.20

# mcpo's own pyproject.toml only requires "mcp>=1.17.0" (unbounded), but its
# lockfile shows it's built/tested against exactly this version. Pinning it
# ourselves avoids pip resolving a newer mcp SDK release whose API mcpo
# doesn't yet support (observed: mcp 2.2.0 renamed an import mcpo 0.0.20
# depends on, breaking startup). When bumping MCPO_VERSION, check the new
# release's uv.lock for its actual tested "mcp" version and update this too.
ARG MCP_SDK_VERSION=1.17.0

FROM python:3.12-slim-bookworm AS vendor
ARG WEBFETCH_MCP_COMMIT
RUN apt-get update && apt-get install -y --no-install-recommends git \
    && rm -rf /var/lib/apt/lists/*
RUN git clone https://code.aneur.in/mirrors/webfetch-mcp.git /src \
    && cd /src \
    && git checkout "${WEBFETCH_MCP_COMMIT}"
RUN mkdir /vendored \
    && cp /src/server.mjs /src/package.json /src/package-lock.json /src/LICENSE /vendored/

FROM python:3.12-slim-bookworm
ARG MCPO_VERSION
ARG MCP_SDK_VERSION

# Node.js 22, matching the version mcpo's own official image is built and
# tested against (webfetch-mcp only requires >=18).
RUN apt-get update && apt-get install -y --no-install-recommends \
        curl \
        ca-certificates \
        gnupg \
    && curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir "mcpo==${MCPO_VERSION}" "mcp==${MCP_SDK_VERSION}"

COPY --from=vendor /vendored /app/webfetch-mcp
WORKDIR /app/webfetch-mcp
RUN npm ci --omit=dev

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 8000
ENTRYPOINT ["/entrypoint.sh"]
