This repository provides a reusable template for a Python server implementing the Model Context Protocol (MCP), running in a Docker container and utilizing Server-Sent Events (SSE) for real-time communication. Built using the FastMCP library, this template enables easy integration with Large Language Models (LLMs).
The Model Context Protocol (MCP) is a standardized protocol designed specifically for interactions with Large Language Models (LLMs). MCP allows applications to clearly separate the concerns of providing context (data and functionality) from the actual LLM interactions. MCP servers expose:
- Resources: Provide data to LLMs (similar to GET endpoints).
- Tools: Allow LLMs to execute actions or computations (similar to POST endpoints).
- Prompts: Reusable templates for structured interactions with LLMs.
This template demonstrates a production-ready MCP server running in a Docker container, utilizing Server-Sent Events (SSE) for real-time communication.
dockerized-mcp-server-template/
├── src/
│ ├── Dockerfile
│ ├── requirements.txt
│ └── server.py
├── docker-compose.yml
└── README.md
docker-compose up --buildThe server will be accessible at:
http://localhost:3000/sse
Alternatively, you can run the server directly using Python. First, install dependencies:
pip install -r src/requirements.txtThen run the server:
python src/server.pyThe server will be accessible at:
http://localhost:3000/sse
The example includes a simple MCP tool function add:
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + bYou can invoke this tool via MCP client requests.