MCP ExplorerExplorer

Dockerized Mcp Server Template

@zantison a year ago
1 MIT
FreeCommunity
AI Systems
A reusable Dockerized Python server template implementing the Model Context Protocol (MCP) with Server-Sent Events (SSE), built using the FastMCP library for easy integration with Large Language Models (LLMs).

Overview

What is Dockerized Mcp Server Template

The dockerized-mcp-server-template is a reusable Dockerized Python server template that implements the Model Context Protocol (MCP) using Server-Sent Events (SSE) for real-time communication. It is built with the FastMCP library to facilitate easy integration with Large Language Models (LLMs).

Use cases

Use cases for the dockerized-mcp-server-template include building chatbots that utilize LLMs for conversation, creating tools that perform computations or actions based on user input, and developing applications that require real-time updates and interactions with LLMs.

How to use

To use the dockerized-mcp-server-template, you can either build and run it using Docker Compose with the command ‘docker-compose up --build’ or run it directly using Python after installing the necessary dependencies with ‘pip install -r src/requirements.txt’ and executing ‘python src/server.py’. The server will be accessible at http://localhost:3000/sse.

Key features

Key features of the dockerized-mcp-server-template include: 1) Implementation of the Model Context Protocol (MCP) for structured interactions with LLMs; 2) Utilization of Server-Sent Events (SSE) for real-time communication; 3) Easy integration with Large Language Models (LLMs); 4) A production-ready template with a clear project structure.

Where to use

The dockerized-mcp-server-template can be used in various fields that require interaction with Large Language Models (LLMs), such as natural language processing applications, chatbots, AI-driven tools, and any application needing real-time data communication.

Content

Dockerized MCP Server Template

This repository provides a reusable template for a Python server implementing the Model Context Protocol (MCP), running in a Docker container and utilizing Streamable HTTP for real-time communication. Built on the Python implementation of the Model Context Protocol (MCP), this template enables easy integration with Large Language Models (LLMs).

What is MCP?

The Model Context Protocol (MCP) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way.

This template demonstrates a production-ready MCP server running in a Docker container, utilizing stateless Streamable HTTP for real-time communication.

Project Structure

dockerized-mcp-server-template/
├── src/
│   ├── Dockerfile
│   ├── requirements.txt
│   └── server.py
├── docker-compose.yml
└── README.md

Getting Started

Build and Run with Docker Compose

docker-compose up --build

The server will be accessible at:

http://localhost:8080/mcp

Running Directly (without Docker)

Alternatively, you can run the server directly using Python. First, install dependencies:

pip install -r src/requirements.txt

Then run the server:

python src/server.py

The server will be accessible at:

http://localhost:8080/mcp

Example Usage

The example includes a simple MCP tool function add:

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

You can invoke this tool via MCP client requests.

Technical Notes

This template uses Streamable HTTP transport, which is available in the Model Context Protocol starting with the Python SDK v1.8.0 (https://github.com/modelcontextprotocol/python-sdk).

Why Streamable HTTP?

Streamable HTTP significantly improves upon the previous SSE transport by enabling stateless operation, making MCP compatible with serverless architectures and standard web infrastructure. This approach eliminates the need for persistent connections, resulting in better resource efficiency and cost effectiveness, while offering a more straightforward implementation for developers. The result is an MCP server that’s easier to deploy, more scalable, and more resource-efficient without sacrificing functionality.

Resources

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers