Sponsored by Deepsite.site

MCP Server Docker Execution and Client Setup Guide

Created By
ysys1436 months ago
Dockerized MCP server environments for seamless agent-tool integration.
Content

MCP Server Docker Execution and Client Setup Guide

How Docker Revolutionizes MCP

Korean Version (한국어 버전)

Docker Blog: How to build and deliver an MCP server for production

Problems with the Existing MCP (Model Context Protocol) Workflow

  • Complex Management: Each MCP client had to run its own copy of every MCP server at all times, which consumed excessive local resources. Clients had to directly configure their server sets, it was difficult to figure out which MCP servers to use, and some MCP servers had compatibility issues that prevented them from working on certain agents.
  • Dependency Hell: MCP servers only worked if all runtimes and dependencies were installed. Agents had direct access to host resources, which could pose security risks.
  • Security Issues: API keys had to be manually configured in plaintext configuration files, and authentication server management was cumbersome.

By isolating the MCP server execution environment with Docker,

  • Simplified Runtime: Using Docker standardizes the installation of MCP tools with a single runtime application, which can significantly reduce management overhead.
  • Isolation and Security: Docker containers are effective at sandboxing agents, preventing unnecessary access to host resources. Furthermore, API keys can be managed securely without being stored in plaintext configuration files, and OAuth-based server authentication can be considered to enhance security.
  • Easy Accessibility: Clients can access MCP services through a single endpoint, providing flexibility for agents to use suitable tools for a task even if the user hasn't explicitly installed them.

Setup Method

1. Prerequisites

2. Docker Container Execution

Launch the node20 image with Docker.

docker run -d --name mcp-server-docker -it node:20-slim bash

Note: The container name specified with the --name option (mcp-server-docker) must be unique within the Docker host. If a container with the same name is already running or stopped, a new container cannot be started. In this case, you must stop and remove the existing container or use a different name.

3. MCP Client Configuration (.cursor/mcp.json Example)

MCP clients (e.g., Cursor) configure how to connect to the Context7 Documentation MCP server via the mcp.json file. This file is typically located in the client's configuration directory (e.g., ~/.cursor/mcp.json) and is not copied into the Docker container.

This setup uses docker exec to directly call the MCP server script inside the container, so no separate port mapping (-p option) is required.

Verifying Command Execution Inside the Container (Optional): To check if the MCP server is properly ready for execution inside the container, you can access the container and try running the MCP server script directly with the following commands:

docker exec -it mcp-server-docker bash
# (Inside the container) npx -y @upstash/context7-mcp@latest
# Or for a Python-based server:
# docker exec -it mcp-uv-server-docker bash
# (Inside the container) uv run /app/custom_mcp_server.py

You can configure the mcp.json file as follows to connect to the Context7 MCP Server running within the Docker container:

{
    "mcpServers": {
        "Context7 MCP (Docker exec)": {
            "command": "docker",
            "args": [
                "exec",
                "-i",
                "mcp-server-docker",
                "npx",
                "-y",
                "@upstash/context7-mcp@latest"
            ]
        },
        "sequential-thinking (Docker exec)": {
            "command": "docker",
            "args": [
                "exec",
                "-i",
                "mcp-server-docker",
                "npx",
                "-y",
                "@modelcontextprotocol/server-sequential-thinking"
            ]
        }
    }
}

4. Stopping and Removing Containers (Optional)

To stop and remove containers, use the following commands:

docker stop mcp-server-docker
docker rm mcp-server-docker

Following this guide, you can easily deploy and configure the Context7 Documentation MCP Server in a Docker environment and utilize it with your client.


5. Custom Build Cases

5.1. Node.js Based MCP Server Custom Build

The Context7 Documentation MCP Server is Node.js based. You can build and run the server in a Node.js environment using the following Dockerfile.

FROM node:20-slim
WORKDIR /app
CMD ["tail", "-f", "/dev/null"]

Build the Docker image by running the following command in the project root directory where the Dockerfile is located. Tag the built image with a generic name like node-base-image.

docker build -t node-base-image .

Run the Docker container using the built image.

docker run -d --name mcp-server-docker -it node-base-image
  • -d: Runs the container in detached mode (in the background).
  • --name mcp-server-docker: Assigns the name mcp-server-docker to the container.

    Note: The container name specified with the --name option (mcp-server-docker) must be unique within the Docker host. If a container with the same name is already running or stopped, a new container cannot be started. In this case, you must stop and remove the existing container or use a different name.

  • -it: Enables interactive mode for the container and allocates a TTY. This is useful when executing commands inside the container.
  • node-base-image: The name of the Docker image to run.

5.2. Python (uv) Based MCP Server Custom Build (Example)

If you are using a Python-based MCP server and managing dependencies with uv, you can configure a similar Dockerfile as follows. This example assumes that a requirements.txt file exists in your project root.

FROM python:3.10-slim-buster
WORKDIR /app

# Install necessary system packages and clean up cache
RUN apt-get update && apt-get install -y --no-install-recommends curl tar \
    && rm -rf /var/lib/apt/lists/*

# Install uv (recommended)
# Download the latest uv binary and install it to /usr/local/bin.
RUN curl -sSfL https://astral.sh/uv/install.sh | sh \
    && mv /root/.local/bin/uv /usr/local/bin/uv

# Install dependencies
COPY requirements.txt .
RUN uv pip install -r requirements.txt --system

# Copy and build MCP server script (if necessary)
# Example: Assuming you have a file named custom_mcp_server.py
COPY custom_mcp_server.py .
# custom_mcp_server.py should be an MCP server that handles JSON-RPC requests/responses via standard input (stdin) and standard output (stdout).

CMD ["tail", "-f", "/dev/null"]

Build the Docker image by running the following command in the project root directory where the Dockerfile is located. Tag the built image with a generic name like python-mcp-base-image.

docker build -t python-mcp-base-image .

Run the Docker container using the built image.

docker run -d --name mcp-uv-server-docker -it python-mcp-base-image
  • -d: Runs the container in detached mode (in the background).
  • --name mcp-uv-server-docker: Assigns the name mcp-uv-server-docker to the container.
  • -it: Enables interactive mode for the container and allocates a TTY.
  • python-mcp-base-image: The name of the Docker image to run.

Here's an example of mcp.json client configuration for running a Python-based MCP server within the container:

{
    "mcpServers": {
        "Python Weather MCP (Docker exec)": {
            "command": "docker",
            "args": [
                "exec",
                "-i",
                "mcp-uv-server-docker",
                "uv",
                "run",
                "/app/custom_mcp_server.py"
            ]
        }
    }
}

After adding this configuration, you should restart your MCP client (e.g., Cursor) to apply the changes.

To stop and remove containers, use the following commands:

docker stop mcp-uv-server-docker
docker rm mcp-uv-server-docker

6. Troubleshooting and Debugging

If the MCP server is not working as expected, you can check the Docker container's logs to diagnose the issue.

  • Check Container Logs:
    docker logs <container_name>
    # Example:
    # docker logs mcp-server-docker
    # docker logs mcp-uv-server-docker
    
    This command displays all logs output by the container to standard output (stdout) and standard error (stderr) since it started. You can check the server's startup process, error messages, processed requests, and more.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
CursorThe AI Code Editor
ChatWiseThe second fastest AI chatbot™
Playwright McpPlaywright MCP server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
DeepChatYour AI Partner on Desktop
Serper MCP ServerA Serper MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Amap Maps高德地图官方 MCP Server