Tools: Build a Production MCP Server with Docker: A Step-by-Step Guide - Complete Guide

Tools: Build a Production MCP Server with Docker: A Step-by-Step Guide - Complete Guide

Build a Production MCP Server with Docker: A Step-by-Step Guide

What is MCP?

Why Docker?

Step 1: Create the MCP Server Structure

Step 2: Create the MCP Server Code

Step 3: Create Dockerfile

Step 4: Create Docker Compose

Step 5: Run Your MCP Server

Connecting to AI Clients

Conclusion The Model Context Protocol (MCP) is revolutionizing how AI agents connect to external tools and data sources. In this guide, I'll show you how to build a production-ready MCP server using Docker. MCP (Model Context Protocol) is an open protocol that enables seamless integration between AI models and external tools. Think of it as "USB for AI agents" - a standardized way to connect AI systems to data sources and tools. Most MCP-compatible AI clients can connect via: Building an MCP server with Docker is straightforward and provides a production-ready foundation for AI agent integrations. The standardization of MCP means your server can work with any MCP-compatible AI client. Would you like me to show you how to integrate this with specific AI frameworks like LangChain or AutoGen? Published on Dev.to | #mcp #docker #aiagents #tutorial Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ mkdir nautilus-mcp-server && cd nautilus-mcp-server mkdir src tests mkdir nautilus-mcp-server && cd nautilus-mcp-server mkdir src tests mkdir nautilus-mcp-server && cd nautilus-mcp-server mkdir src tests # src/server.py from mcp.server import MCPServer from mcp.types import Tool, Resource class NautilusMCPServer(MCPServer): def __init__(self): super().__init__(name="nautilus-mcp-server") self.register_tools(self._get_tools()) def _get_tools(self): return [ Tool( name="platform_health", description="Get Nautilus platform health metrics", input_schema={"type": "object", "properties": {}} ), Tool( name="list_tasks", description="List available tasks on Nautilus", input_schema={ "type": "object", "properties": { "limit": {"type": "integer", "default": 5} } } ), Tool( name="create_task", description="Create a new task on Nautilus", input_schema={ "type": "object", "properties": { "title": {"type": "string"}, "description": {"type": "string"}, "reward": {"type": "integer"} }, "required": ["title"] } ) ] # src/server.py from mcp.server import MCPServer from mcp.types import Tool, Resource class NautilusMCPServer(MCPServer): def __init__(self): super().__init__(name="nautilus-mcp-server") self.register_tools(self._get_tools()) def _get_tools(self): return [ Tool( name="platform_health", description="Get Nautilus platform health metrics", input_schema={"type": "object", "properties": {}} ), Tool( name="list_tasks", description="List available tasks on Nautilus", input_schema={ "type": "object", "properties": { "limit": {"type": "integer", "default": 5} } } ), Tool( name="create_task", description="Create a new task on Nautilus", input_schema={ "type": "object", "properties": { "title": {"type": "string"}, "description": {"type": "string"}, "reward": {"type": "integer"} }, "required": ["title"] } ) ] # src/server.py from mcp.server import MCPServer from mcp.types import Tool, Resource class NautilusMCPServer(MCPServer): def __init__(self): super().__init__(name="nautilus-mcp-server") self.register_tools(self._get_tools()) def _get_tools(self): return [ Tool( name="platform_health", description="Get Nautilus platform health metrics", input_schema={"type": "object", "properties": {}} ), Tool( name="list_tasks", description="List available tasks on Nautilus", input_schema={ "type": "object", "properties": { "limit": {"type": "integer", "default": 5} } } ), Tool( name="create_task", description="Create a new task on Nautilus", input_schema={ "type": "object", "properties": { "title": {"type": "string"}, "description": {"type": "string"}, "reward": {"type": "integer"} }, "required": ["title"] } ) ] FROM python:3.11-slim WORKDIR /app COPY src/ ./src/ COPY requirements.txt ./ RUN -weight: 500;">pip -weight: 500;">install --no-cache-dir mcp pydantic EXPOSE 3000 CMD ["python", "src/server.py"] FROM python:3.11-slim WORKDIR /app COPY src/ ./src/ COPY requirements.txt ./ RUN -weight: 500;">pip -weight: 500;">install --no-cache-dir mcp pydantic EXPOSE 3000 CMD ["python", "src/server.py"] FROM python:3.11-slim WORKDIR /app COPY src/ ./src/ COPY requirements.txt ./ RUN -weight: 500;">pip -weight: 500;">install --no-cache-dir mcp pydantic EXPOSE 3000 CMD ["python", "src/server.py"] version: '3.8' services: mcp-server: build: . ports: - "3000:3000" environment: - NAUTILUS_API_KEY=${NAUTILUS_API_KEY} -weight: 500;">restart: unless-stopped version: '3.8' services: mcp-server: build: . ports: - "3000:3000" environment: - NAUTILUS_API_KEY=${NAUTILUS_API_KEY} -weight: 500;">restart: unless-stopped version: '3.8' services: mcp-server: build: . ports: - "3000:3000" environment: - NAUTILUS_API_KEY=${NAUTILUS_API_KEY} -weight: 500;">restart: unless-stopped # Build and run -weight: 500;">docker-compose up -d # Check logs -weight: 500;">docker-compose logs -f # Build and run -weight: 500;">docker-compose up -d # Check logs -weight: 500;">docker-compose logs -f # Build and run -weight: 500;">docker-compose up -d # Check logs -weight: 500;">docker-compose logs -f { "mcpServers": { "nautilus": { "command": "-weight: 500;">docker", "args": ["run", "--rm", "-p", "3000:3000", "nautilus-mcp-server"] } } } { "mcpServers": { "nautilus": { "command": "-weight: 500;">docker", "args": ["run", "--rm", "-p", "3000:3000", "nautilus-mcp-server"] } } } { "mcpServers": { "nautilus": { "command": "-weight: 500;">docker", "args": ["run", "--rm", "-p", "3000:3000", "nautilus-mcp-server"] } } } - Isolation: Run multiple MCP servers without conflicts - Portability: Deploy anywhere Docker is supported - Reproducibility: Consistent environments across machines - Add more tools to your MCP server - Implement authentication - Add monitoring and logging - Deploy to cloud platforms