Skip to content

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Aug 28, 2025

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

  • Added multi-stage build with FROM node:22-alpine AS builder
  • Pre-installs npm packages using npm install --save in builder stage
  • Runtime uses npx --no-install to prevent network access
  • Copies node_modules to runtime stage

UVX Template

  • Added multi-stage build with FROM python:3.13-slim AS builder
  • Uses uv tool install to properly install Python tools with their executables
  • Handles executable discovery automatically
  • Copies the tool installation to runtime stage

Go Template

  • Added multi-stage build with FROM golang:1.25-alpine AS builder
  • Pre-installs Go packages with go install handling version specifiers
  • Copies compiled binary to minimal Alpine runtime image

Tests

  • Updated templates_test.go to match new multi-stage build structure
  • All tests pass successfully

Testing

Tested all three templates with real MCP servers using the --isolate-network flag:

  • ✅ NPX: @upstash/context7-mcp
  • ✅ UVX: mcp-server-browser-use
  • ✅ Go: github.com/StacklokLabs/osv-mcp/cmd/server

All servers started successfully and responded to MCP protocol messages without network access.

Impact

  • Enables MCP servers to run in air-gapped environments
  • Improves security by eliminating runtime network dependencies
  • Maintains backward compatibility with existing configurations
  • All package managers now support the --isolate-network flag

Checklist

  • Code changes
  • Tests updated and passing
  • Manual testing with network isolation
  • Documentation (templates are self-documenting)

@JAORMX JAORMX force-pushed the fix-1597-preinstall-packages branch 2 times, most recently from 4b3a4bf to 8a4c34a Compare August 29, 2025 10:41
JAORMX added 2 commits August 29, 2025 14:00
This commit modifies the container templates to pre-install packages at
build time rather than runtime, enabling MCP servers to run in
network-isolated environments.

Changes:
- Modified NPX template to use multi-stage build with npm install --save
- Modified UVX template to use uv tool install for proper executable handling
- Modified Go template to use multi-stage build with go install
- Updated tests to match new multi-stage build structure

All three package managers now support the --isolate-network flag,
addressing security concerns and enabling MCP servers to run in
restricted environments.

Fixes #1597
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
@JAORMX JAORMX force-pushed the fix-1597-preinstall-packages branch from 8a4c34a to e817a16 Compare August 29, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Protocol handlers: package installs at runtime, not build-time
1 participant