Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions olive-mcp-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Multi-stage build for Olive MCP Server
# Produces a slim image (~120MB) that runs the MCP server over SSE/HTTP transport.
# Image size is dominated by CPU PyTorch + sentence-transformers + MiniLM
# (~1.5–3GB depending on platform wheels — not a slim ~120MB image).

# ── Stage 1: Install dependencies ────────────────────────────────────────────
FROM python:3.12-slim AS builder
Expand All @@ -9,7 +10,22 @@ WORKDIR /build
COPY pyproject.toml ./
COPY olive_mcp_server/ ./olive_mcp_server/

RUN pip install --no-cache-dir --prefix=/install . "mcp<2"
# Install torch from the CPU-only index first. --extra-index-url does not
# prioritize this index over PyPI, so a plain combined install can still
# resolve PyPI's CUDA-bundled torch wheel; installing torch alone against
# --index-url forces the CPU build, and PYTHONPATH makes it visible as
# "already satisfied" to the next install so it isn't pulled again from PyPI.
RUN pip install --no-cache-dir --prefix=/install \
--index-url https://download.pytorch.org/whl/cpu \
torch \
Comment thread
tonythethompson marked this conversation as resolved.
Resolved
&& PYTHONPATH="$(echo /install/lib/python*/site-packages)" \
pip install --no-cache-dir --prefix=/install \
. "mcp<2"

# Pre-cache the embedding model so the runtime image does not need network
# access on first semantic search. Cache lands under /root/.cache/huggingface.
RUN PYTHONPATH="$(echo /install/lib/python*/site-packages)" \
python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"

# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
FROM python:3.12-slim AS runtime
Expand All @@ -18,29 +34,28 @@ LABEL org.opencontainers.image.title="olive-mcp-server"
LABEL org.opencontainers.image.description="MCP server for Microsoft Olive model optimization guidance"
LABEL org.opencontainers.image.licenses="MIT"

# Create non-root user
RUN useradd --create-home --shell /bin/bash mcp

WORKDIR /app

# Copy installed packages from builder
COPY --from=builder /install /usr/local

# Copy source (needed for knowledge_base JSON files)
COPY --from=builder --chown=mcp:mcp /root/.cache/huggingface /home/mcp/.cache/huggingface

COPY olive_mcp_server/ ./olive_mcp_server/
COPY pyproject.toml ./

# Volume mount point for knowledge base hot-reload
VOLUME /app/olive_mcp_server/knowledge_base

USER mcp

# SSE transport listens on port 8000 by default
EXPOSE 8000

ENV MCP_TRANSPORT=sse
ENV MCP_HOST=0.0.0.0
ENV MCP_PORT=8000
ENV HF_HOME=/home/mcp/.cache/huggingface
ENV HF_HUB_OFFLINE=1

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; r=urllib.request.urlopen('http://localhost:8000/sse',timeout=3); r.close()" || exit 1
Expand Down
4 changes: 4 additions & 0 deletions olive-mcp-server/olive_mcp_server/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"olive_mcp_server.tools.tradeoff",
"evaluate_optimization_tradeoff",
),
"get_context_for_pipeline": (
"olive_mcp_server.tools.passive_context",
"get_context_for_pipeline",
),
}

_mcp_instance: Any | None = None
Expand Down
2 changes: 2 additions & 0 deletions olive-mcp-server/olive_mcp_server/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"troubleshoot_olive_error": (".troubleshooting", "troubleshoot_olive_error"),
"diagnose_error": (".troubleshooting", "diagnose_error"),
"get_error_frequency_summary": (".troubleshooting", "get_error_frequency_summary"),
"get_context_for_pipeline": (".passive_context", "get_context_for_pipeline"),
}


Expand Down Expand Up @@ -174,6 +175,7 @@ def __getattr__(name: str) -> Any:
"troubleshoot_olive_error",
"diagnose_error",
"get_error_frequency_summary",
"get_context_for_pipeline",
"KB_DIR",
"load_json",
"load_passes",
Expand Down
Loading
Loading