-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
123 lines (98 loc) · 4.15 KB
/
Dockerfile
File metadata and controls
123 lines (98 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Tooltrim — Linux container image
#
# Default behavior: starts the Tooltrim proxy on 0.0.0.0:8799 (MCP Streamable HTTP)
# and 0.0.0.0:9464 (Prometheus). It fans out to five upstream MCP servers via
# `npx`, so we warm the npm cache for those packages during build to make the
# first call fast and self-contained.
#
# Override CMD to run the bench harness instead, e.g.:
# docker run --rm tooltrim:dev pnpm bench --skip-agent
#
# Multi-stage layout:
# 1. deps — install ALL dependencies (incl. dev) for build + bench
# 2. build — compile TypeScript -> dist
# 3. runtime — slim final image with deps + dist + bench harness
ARG NODE_VERSION=20.18.0
ARG PNPM_VERSION=10.26.0
# -----------------------------------------------------------------------------
# Stage 1: deps — pnpm install with frozen lockfile
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-bookworm-slim AS deps
ARG PNPM_VERSION
ENV PNPM_HOME=/pnpm \
PATH="/pnpm:$PATH" \
CI=true
# Install a pinned pnpm without corepack (corepack hits npmjs.org for "latest"
# even when packageManager isn't pinned, which fails on flaky networks).
RUN npm install -g pnpm@${PNPM_VERSION} \
|| (sleep 5 && npm install -g pnpm@${PNPM_VERSION})
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile
# -----------------------------------------------------------------------------
# Stage 2: build — produce dist/
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-bookworm-slim AS build
ARG PNPM_VERSION
ENV PNPM_HOME=/pnpm \
PATH="/pnpm:$PATH"
RUN npm install -g pnpm@${PNPM_VERSION} \
|| (sleep 5 && npm install -g pnpm@${PNPM_VERSION})
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
# -----------------------------------------------------------------------------
# Stage 3: runtime — slim image we actually ship/run
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-bookworm-slim AS runtime
ARG PNPM_VERSION
ENV PNPM_HOME=/pnpm \
PATH="/pnpm:$PATH" \
NODE_ENV=production \
NPM_CONFIG_UPDATE_NOTIFIER=false \
NPM_CONFIG_FUND=false
# Native deps that some npx-resolved MCP servers may pull in (sqlite3, sharp,
# etc.). Cheap and rare, but keeps `npx -y <server>` from breaking on first call.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
dumb-init \
git \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g pnpm@${PNPM_VERSION} \
|| (sleep 5 && npm install -g pnpm@${PNPM_VERSION})
WORKDIR /app
# Copy built artifacts and the dependency tree from earlier stages.
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
# Source files the bench harness still needs at runtime (it imports from src/
# via tsx and uses bench/*.ts directly).
COPY package.json pnpm-lock.yaml tsconfig.json ./
COPY bin ./bin
COPY src ./src
COPY bench ./bench
COPY examples ./examples
COPY README.md LICENSE ./
# Warm the npm cache so the five upstream MCP servers don't pay a fresh
# download on the first proxy/bench run inside a container.
RUN set -eux; \
for pkg in \
@modelcontextprotocol/server-everything \
@modelcontextprotocol/server-filesystem \
@modelcontextprotocol/server-memory \
@modelcontextprotocol/server-sequential-thinking \
@modelcontextprotocol/server-github ; do \
npm pack --silent "$pkg" --pack-destination=/tmp >/dev/null 2>&1 || true; \
done; \
rm -f /tmp/*.tgz
# Filesystem upstream needs a sandbox dir; the bench config defaults to
# /app/bench/sandbox via BENCH_FS_ROOT.
RUN mkdir -p /app/bench/sandbox /app/bench/results /app/.tooltrim
EXPOSE 8799 9464
# dumb-init reaps zombie children spawned by the upstream stdio servers.
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# Default: start the proxy. Override with `pnpm bench [...]` etc.
CMD ["node", "bin/tooltrim", "start", "--config", "examples/benchmark.docker.config.yaml"]