Skip to content

Fix Docker implementation for MCP protocol #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
79 changes: 44 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
FROM python:3.10-slim
FROM python:3.12-slim-bookworm AS builder

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Set working directory
WORKDIR /app

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
python3-dev \
bash \
&& rm -rf /var/lib/apt/lists/*

# Copy the project files
COPY . /app/

# Install uv
RUN pip install --upgrade pip && \
pip install uv

# Create a virtual environment, install dependencies
RUN uv venv /app/.venv && \
. /app/.venv/bin/activate && \
ENV UV_COMPILE_BYTECODE=1

COPY pyproject.toml ./
COPY uv.lock ./
COPY src ./src/

RUN uv venv && \
uv pip install -e .

# Make the entrypoint script executable
RUN chmod +x /app/docker-entrypoint.sh
FROM python:3.12-slim-bookworm

WORKDIR /app

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

RUN groupadd -r app && useradd -r -g app app

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

ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH="/app" \
PYTHONFAULTHANDLER=1

USER app

EXPOSE 8000

# Set the entrypoint
ENTRYPOINT ["/app/docker-entrypoint.sh"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1

# Label the image
LABEL maintainer="pab1it0" \
description="Prometheus MCP Server" \
version="1.0.0"
CMD ["/app/.venv/bin/prometheus-mcp-server"]

# Expose port if needed (but this is optional as the MCP server typically runs on stdio)
# EXPOSE 8000
# GitHub Container Registry Metadata
LABEL org.opencontainers.image.title="Prometheus MCP Server" \
org.opencontainers.image.description="Model Context Protocol server for Prometheus integration" \
org.opencontainers.image.version="1.0.0" \
org.opencontainers.image.authors="Pavel Shklovsky" \
org.opencontainers.image.source="https://github.com/pab1it0/prometheus-mcp-server" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/pab1it0/prometheus-mcp-server" \
org.opencontainers.image.documentation="https://github.com/pab1it0/prometheus-mcp-server#readme" \
org.opencontainers.image.vendor="Pavel Shklovsky"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ To use the containerized server with Claude Desktop, update the configuration to

This configuration passes the environment variables from Claude Desktop to the Docker container by using the `-e` flag with just the variable name, and providing the actual values in the `env` object.

> **Note about Docker implementation**: The Docker setup has been updated to match the structure of the chess-mcp project, which has been proven to work correctly with Claude. The new implementation uses a multi-stage build process and runs the entry point script directly without an intermediary shell script. This approach ensures proper handling of stdin/stdout for MCP communication.

## Development

Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
Expand Down Expand Up @@ -212,4 +214,4 @@ MIT

---

[mcp]: https://modelcontextprotocol.io
[mcp]: https://modelcontextprotocol.io