How to Intermediate · 3 min read

How to deploy MCP server to production

Quick answer
Deploy an MCP server to production by running the mcp.server.stdio.stdio_server or a custom mcp.server.Server implementation on a reliable host with proper process management. Use containerization or systemd for stability, and ensure secure environment variables and logging are configured.

PREREQUISITES

  • Python 3.8+
  • pip install mcp
  • Basic knowledge of systemd or Docker
  • Access to a Linux server or cloud VM

Setup

Install the mcp Python package and prepare your environment variables. Ensure Python 3.8 or higher is installed on your production server.

bash
pip install mcp

Step by step

Run a basic MCP server using the stdio transport. This example shows a minimal server that can be deployed as a systemd service or inside a Docker container.

python
import os
from mcp.server.stdio import stdio_server

if __name__ == "__main__":
    # Optionally configure logging or environment here
    stdio_server()
output
Server started, listening on stdio for MCP messages...

Common variations

You can implement a custom mcp.server.Server subclass for advanced logic or use alternative transports like SSE. For production, wrap the server in a Docker container or use systemd for process management and auto-restart.

python
from mcp.server import Server

class CustomMCPServer(Server):
    def handle_request(self, request):
        # Implement your request handling logic here
        return {"result": "ok"}

if __name__ == "__main__":
    server = CustomMCPServer()
    server.serve()
output
Custom MCP server running and handling requests...

Troubleshooting

  • If the server stops unexpectedly, use systemd or Docker restart policies to auto-restart.
  • Check logs for JSON parsing errors or transport issues.
  • Ensure environment variables are securely managed and not exposed.

Key Takeaways

  • Use mcp.server.stdio.stdio_server for a simple production-ready MCP server.
  • Manage the MCP server process with systemd or Docker for reliability.
  • Implement custom mcp.server.Server subclasses for advanced use cases.
  • Secure environment variables and logs to protect sensitive data.
  • Monitor server logs and set up auto-restart to handle failures gracefully.
Verified 2026-04
Verify ↗