Skip to content

Commit c7d8d8f

Browse files
committed
Implemented Transport-Translation Bridge (mcpgateway.translate)
1 parent 2ae96ad commit c7d8d8f

File tree

10 files changed

+2514
-0
lines changed

10 files changed

+2514
-0
lines changed

docker/translate.Dockerfile

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# -*- coding: utf-8 -*-
2+
# MCP Gateway Transport-Translation Bridge Docker Image
3+
# Multi-stage build for production deployment
4+
5+
# ================================================================
6+
# Stage 1: Base Python environment with UV package manager
7+
# ================================================================
8+
FROM python:3.12-slim as base
9+
10+
# Install system dependencies and UV package manager
11+
RUN apt-get update && apt-get install -y \
12+
--no-install-recommends \
13+
build-essential \
14+
curl \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Install uv for fast Python package management
18+
RUN pip install uv
19+
20+
# Set working directory
21+
WORKDIR /app
22+
23+
# ================================================================
24+
# Stage 2: Build dependencies and install packages
25+
# ================================================================
26+
FROM base as builder
27+
28+
# Copy dependency files
29+
COPY pyproject.toml uv.lock ./
30+
31+
# Install dependencies using uv (much faster than pip)
32+
RUN uv sync --frozen --no-dev
33+
34+
# ================================================================
35+
# Stage 3: Production runtime image
36+
# ================================================================
37+
FROM python:3.12-slim as runtime
38+
39+
# Install minimal runtime dependencies
40+
RUN apt-get update && apt-get install -y \
41+
--no-install-recommends \
42+
tini \
43+
&& rm -rf /var/lib/apt/lists/* \
44+
&& apt-get clean
45+
46+
# Create non-root user for security
47+
RUN groupadd -r mcpuser && useradd -r -g mcpuser mcpuser
48+
49+
# Set working directory
50+
WORKDIR /app
51+
52+
# Copy virtual environment from builder stage
53+
COPY --from=builder /app/.venv /app/.venv
54+
55+
# Copy application source code
56+
COPY mcpgateway/ ./mcpgateway/
57+
COPY README.md LICENSE ./
58+
59+
# Set up Python path and activate virtual environment
60+
ENV PATH="/app/.venv/bin:$PATH"
61+
ENV PYTHONPATH="/app:$PYTHONPATH"
62+
63+
# Create directories for logs and data
64+
RUN mkdir -p /app/logs /app/data && \
65+
chown -R mcpuser:mcpuser /app
66+
67+
# Switch to non-root user
68+
USER mcpuser
69+
70+
# Health check
71+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
72+
CMD python -c "import mcpgateway.translate" || exit 1
73+
74+
# Set default environment variables
75+
ENV MCP_TRANSLATE_LOG_LEVEL=info
76+
ENV MCP_TOOL_CALL_TIMEOUT=90
77+
78+
# Expose default port
79+
EXPOSE 8000
80+
81+
# Use tini as init process for proper signal handling
82+
ENTRYPOINT ["/usr/bin/tini", "--"]
83+
84+
# Default command runs the translate bridge
85+
CMD ["python", "-m", "mcpgateway.translate", "--help"]
86+
87+
# ================================================================
88+
# Stage 4: UVX variant (for running arbitrary MCP servers)
89+
# ================================================================
90+
FROM runtime as uvx
91+
92+
USER root
93+
94+
# Install Node.js and npm for uvx support
95+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
96+
apt-get install -y nodejs && \
97+
npm install -g @modelcontextprotocol/server-* || true && \
98+
rm -rf /var/lib/apt/lists/*
99+
100+
# Install uvx
101+
RUN pip install uvx
102+
103+
USER mcpuser
104+
105+
# ================================================================
106+
# Stage 5: Deno variant (for Deno-based MCP servers)
107+
# ================================================================
108+
FROM runtime as deno
109+
110+
USER root
111+
112+
# Install Deno
113+
RUN curl -fsSL https://deno.land/install.sh | sh
114+
ENV PATH="/root/.deno/bin:$PATH"
115+
116+
USER mcpuser
117+
118+
# Labels for metadata
119+
LABEL org.opencontainers.image.title="MCP Gateway Transport-Translation Bridge"
120+
LABEL org.opencontainers.image.description="Transport bridge for MCP protocols"
121+
LABEL org.opencontainers.image.version="0.1.0"
122+
LABEL org.opencontainers.image.authors="Mihai Criveti <[email protected]>"
123+
LABEL org.opencontainers.image.source="https://github.com/IBM/mcp-context-forge"
124+
LABEL org.opencontainers.image.licenses="Apache-2.0"

0 commit comments

Comments
 (0)