Pre-install packages at build time for network isolation #1601
+271
−72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #1597 by modifying container templates to pre-install packages at build time rather than runtime, enabling MCP servers to run in network-isolated environments.
Problem
MCP servers currently require network access at runtime to download packages, which prevents them from running in network-isolated environments. This poses security concerns and limits deployment options in restricted environments.
Solution
Implemented multi-stage Docker builds for all three package managers (NPX, UVX, Go) to pre-install packages and their dependencies during the build phase.
Changes
NPX Template
FROM node:22-alpine AS builder
npm install --save
in builder stagenpx --no-install
to prevent network accessnode_modules
to runtime stageUVX Template
FROM python:3.13-slim AS builder
uv tool install
to properly install Python tools with their executablesGo Template
FROM golang:1.25-alpine AS builder
go install
handling version specifiersTests
templates_test.go
to match new multi-stage build structureTesting
Tested all three templates with real MCP servers using the
--isolate-network
flag:@upstash/context7-mcp
mcp-server-browser-use
github.com/StacklokLabs/osv-mcp/cmd/server
All servers started successfully and responded to MCP protocol messages without network access.
Impact
--isolate-network
flagChecklist