Location>code7788 >text

Containerized MCP Server!

Popularity:794 ℃/2025-04-24 20:46:34

Hello everyone! I am Teacher Han.

This article is the fifth article in the MCP series, and the previous four articles are:

  • Code Runner MCP Server, here!
  • Develop an MCP Server from scratch!
  • Install MCP Server with one click!
  • Goodbye, SSE! Hello, Streamable HTTP!

Written first:Containerized MCP Server, useful. But, you don't necessarily need it.

WHY

If you are developing a local MCP Server and you have any of the following situations:

  • Multiple toolchains are required to be installed to run local MCP Server
  • Language for developing local MCP Server, there is no tool for running programs in one click like npx or uv

Then, containerized MCP Server is useful for your users.

On the contrary, if you have used mainstream or Python to develop local MCP Server and have no other additional dependencies.

Then, you may not need to containerize.

WHAT

local MCP Server is actually a Console App developed by /Python/PHP/Go/Java/.... It interacts with the MCP Client through stdin/stdout, and there is nothing special about it.

So, generally speaking, you only need a Dockerfile.

HOW

Since it is a containerized ordinary Console App, everything becomes very simple.

The following is the Dockerfile for Code Runner MCP Server:

 1 ## Stage 1: Builder
 2 FROM node:lts-alpine AS builder
 3 
 4 # Set working directory
 5 WORKDIR /app
 6 
 7 # Copy all files into the container
 8 COPY . .
 9 
10 # Install dependencies without running scripts
11 RUN npm install --ignore-scripts
12 
13 # Build the TypeScript source code
14 RUN npm run build
15 
16 ## Stage 2: Runtime
17 FROM node:lts-alpine
18 
19 WORKDIR /app
20 
21 # Install Python and other programming languages
22 RUN apk add --no-cache \
23     python3 \
24     go \
25     php \
26     ruby
27 
28 # Copy only the necessary files from the builder stage
29 COPY --from=builder /app/dist ./dist
30 COPY package*.json ./
31 
32 # Install only production dependencies
33 RUN npm install --production --ignore-scripts
34 
35 # Use a non-root user for security (optional)
36 RUN adduser -D mcpuser
37 USER mcpuser
38 
39 # Set the entrypoint command
40 CMD ["node", "./dist/"]

 

This is a standard multi-stage builds Dockerfile.

Since Code Runner MCP Server needs to support the operation of multiple programming languages, I preinstalled the interpreters/compilers of several commonly used programming languages ​​in the Dockerfile.

In this way, the only thing users need to install when using it is Docker:

 1 {
 2   "mcp": {
 3     "inputs": [],
 4     "servers": {
 5       "mcp-server-code-runner": {
 6         "command": "docker",
 7         "args": [
 8           "run",
 9           "--rm",
10           "-i",
11           "formulahendry/mcp-server-code-runner"
12         ]
13       }
14     }
15   }
16 }

 

For the complete code, you can refer to the repo of Code Runner MCP Server, which is completely open source:

/formulahendry/mcp-server-code-runner