AI & Agents

How to Deploy Containerized MCP Servers

Containerized MCP servers package tools for scalable, portable AI agent integrations. This guide walks through Docker deployment, Kubernetes orchestration, and scaling for multi-agent systems. According to the CNCF Annual Survey 2023, 92% of organizations use containers in production or evaluation, making Docker and Kubernetes the standard for MCP servers. Learn Dockerfile creation, local testing, cluster deployment, and how Fastio's hosted MCP server complements self-hosted setups for agent workspaces.

Fastio Editorial Team 6 min read
Dockerized MCP server for reliable AI agent tool access

What Are Containerized MCP Servers?

MCP (Model Context Protocol) servers let AI agents connect to external data sources and tools through a standard interface. Containerizing them with Docker packages the server, dependencies, and config into a portable unit.

This approach solves common issues like environment mismatches and manual setup. Containers run consistently from laptop to production cluster. Kubernetes then orchestrates multiple instances for high availability and scaling.

For AI agents, containerized MCP servers handle concurrent tool calls from multiple LLMs without downtime. Fastio provides a hosted MCP server at mcp.fast.io with multiple tools, but self-hosting gives custom control.

Helpful references: Fastio Workspaces, Fastio Collaboration, and Fastio AI.

AI agent accessing tools via MCP server

Prerequisites for Deployment

Before starting, install these tools:

  1. Docker Desktop or Docker Engine
  2. kubectl and Helm (for Kubernetes)
  3. A Kubernetes cluster (Minikube for local, EKS/GKE/AKS for prod)
  4. Your MCP server code (Node.js, Python, Go examples available)

Basic MCP server knowledge from modelcontextprotocol.io. Test locally first.

Ensure ports multiple (HTTP) and multiple (TLS) are open. Use secrets for API keys and DB creds.

Step 1: Create a Dockerfile for Your MCP Server

Start with a minimal Dockerfile. Here's a Node.js example for a basic MCP server:

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
EXPOSE 8080
CMD ["npm", "start"]

Build and test:

docker build -t mcp-server .
docker run -p 8080:8080 mcp-server

Verify with curl /health or MCP client.

Step 2: Local Testing with Docker Compose

Use Docker Compose for multi-container setups (MCP + DB + Redis):

version: '3.8'
services:
  mcp:
    image: mcp-server
    ports:
      - "8080:8080"
    environment:
      - DB_URL=postgres://user:pass@db:5432/mcp
    depends_on:
      - db
  db:
    image: postgres:15
    environment:
      POSTGRES_DB: mcp
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass

Run docker compose up. Access at localhost:multiple.

Docker vs Kubernetes for MCP Deployment

Choose based on scale:

Feature Docker Kubernetes
Setup Simple, local Complex, cluster
Scaling Manual Auto-scaling
Orchestration Basic Full HPA, rolling updates
Best for Dev/test Production agents

Docker suits prototyping. Kubernetes for prod MCP serving 100s of agents.

Kubernetes deployment of scaled MCP servers
Fastio features

Give Your AI Agents Persistent Storage

50GB free storage, 251 MCP tools, no credit card. Scale agent workflows with Fastio workspaces.

Step 3: Kubernetes Deployment and Scaling

Create Deployment and Service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mcp-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mcp
  template:
    metadata:
      labels:
        app: mcp
    spec:
      containers:
      - name: mcp
        image: your-repo/mcp-server:latest
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: "100m"
            memory: "128Mi"
---
apiVersion: v1
kind: Service
metadata:
  name: mcp-service
spec:
  selector:
    app: mcp
  ports:
  - port: 80
    targetPort: 8080
  type: LoadBalancer

Apply: kubectl apply -f mcp-k8s.yaml

Scale: kubectl scale deployment mcp-server --replicas=5

Use Horizontal Pod Autoscaler for agent load.

Scaling MCP for Agent Workspaces with Fastio

For production, self-hosted MCP pairs with Fastio workspaces. Store agent artifacts in Fastio (multiple free), use your MCP for custom tools.

Example: K8s MCP cluster reads/writes to Fastio via API. Scale MCP pods based on agent requests, use Fastio RAG for file queries.

Fastio MCP at mcp.fast.io offers multiple tools out-of-box, no infra needed. Hybrid: self-host custom, use hosted for storage.

Troubleshoot: Monitor logs with Prometheus, secure with Istio, persist state in PVCs.

Define clear tool contracts and fallback behavior so agents fail safely when dependencies are unavailable. This improves reliability in production workflows.

Frequently Asked Questions

How to containerize MCP servers?

Create a Dockerfile copying your MCP code, install deps, expose port multiple. Build, run with docker run -p multiple:multiple image. Use multi-stage for smaller images.

Docker vs Kubernetes for MCP?

Docker for simple/local deploys. Kubernetes for prod scaling, rolling updates, HPA. Start Docker, migrate to K8s as agents grow.

What ports does MCP server use?

Typically multiple for HTTP, multiple for TLS. Configure via env vars. Expose Streamable HTTP /mcp and SSE /sse endpoints.

How to scale MCP servers?

Use K8s HPA on CPU/memory. Add Redis for sessions, Postgres for state. Monitor with Prometheus/Grafana.

Integrate self-hosted MCP with Fastio?

Use Fastio API/MCP for storage/RAG. Self-host custom tools, point agents to both endpoints.

Related Resources

Fastio features

Give Your AI Agents Persistent Storage

50GB free storage, 251 MCP tools, no credit card. Scale agent workflows with Fastio workspaces.