A production-ready template for building Model Control Protocol (MCP) servers in Python. This template provides a solid foundation with best practices, proper project structure, and example implementations to help you quickly develop your own MCP server.
- Python 3.12+
- uv package manager (recommended) or pip
Option A: Use Template (Recommended)
- Click the "Use this template" button on GitHub pageβ "Create a new repository"
- Name your repository and clone it:
git clone <your-new-repo-url> cd <your-repo-name>
Option B: Direct Clone This Repository
git clone https://github.com/pathintegral-institute/mcp-server-python-template.git
cd mcp-server-python-templateCreate virtual env and activate it
uv venv
source .venv/bin/activate # on Unix-like system
# .venv\Scripts/activate # on WindowsInstall Dependencies
uv sync # Install dependenciesuv pip install -e . # Enables the `uv run mcp-server` command# Method 1: Using the configured script (recommended)
uv run mcp-server
# Method 2: Direct execution
uv run python src/mcp_server/server.pyYour MCP server is now running and ready to accept connections!
mcp-server-python-template/
βββ src/mcp_server/ # Main package directory
β βββ __init__.py # Package initialization
β βββ server.py # FastMCP server entrypoint
β βββ lily.jpeg # Example static asset
βββ pyproject.toml # Project configuration & dependencies
βββ uv.lock # Locked dependency versions
βββ README.md # This file
βββ AGENTS.md # Detailed development guidelines for AI Agent
Tools are the core functionality of your MCP server. Here's how to add them:
- Open
src/mcp_server/server.py - Add your tool function with the
@mcp.tool()decorator:
@mcp.tool()
def your_tool_name(param1: str, param2: int) -> TextContent:
"""Brief description of what this tool does.
Args:
param1: Description of first parameter
param2: Description of second parameter
Returns:
Description of what this returns
"""
# Your implementation here
result = f"Processed {param1} with value {param2}"
return TextContent(type="text", text=result)from mcp.types import TextContent
@mcp.tool()
def get_text_data() -> TextContent:
return TextContent(type="text", text="Your text here")import base64
from mcp.types import ImageContent
@mcp.tool()
def get_image() -> ImageContent:
with open("path/to/image.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode("utf-8")
return ImageContent(data=image_data, mimeType="image/jpeg", type="image")from typing import List
from mcp.types import TextContent, ImageContent
@mcp.tool()
def get_mixed_content() -> List[TextContent | ImageContent]:
return [
TextContent(type="text", text="Here's an image:"),
ImageContent(data=your_base64_data, mimeType="image/png", type="image")
]This template includes example tools to get you started:
add(a: int, b: int)- Simple arithmetic operationget_name_and_image_of_flower()- Returns text and image content
uv run mcp-serverUncomment the following line in server.py:
# mcp.run(transport="stdio") # Comment this out
mcp.run(transport="streamable_http") # Uncomment thisThen run:
uv run mcp-serverYou can test and debug your MCP servers by MCP Inspector. Please refer to the official doc.
Take Lucien Desktop as example:

And you should be able to let LLM call your tools:

Add new dependencies:
uv add [package_name]the pyproject.toml will be updated automatically
Let anyone run your MCP server without cloning or installing globally using uvx:
uvx --from 'git+https://github.com/[AUTHOR]/[REPO_NAME]@<TAG_OR_BRANCH_OR_SHA>' mcp-serverWhat to fill in:
git+https://github.com/[AUTHOR]/[REPO_NAME]: Your public GitHub repo. The repo must be a valid Python package with apyproject.toml.@<TAG_OR_BRANCH_OR_SHA>: Optional but recommended. Pin to a release tag (e.g.@v0.1.0) for reproducible installs; omit to use the default branch.mcp-server: The console script name. This template already defines it inpyproject.tomlasmcp-server = "mcp_server.server:main".
How it works:
uvxcreates an isolated, ephemeral environment, installs your package (+ deps frompyproject.toml/uv.lock), then runs the specified entry point. Nothing is installed globally.
Client usage:
- Most MCP clients let you specify a command to launch a server. Use the same oneβliner above as the command. If your server requires flags, add them after
mcp-server. - This template defaults to stdio transport. If you switch to HTTP in
server.py, configure your client accordingly and ensure the port is reachable.
Tips for maintainers:
- Publish release tags so others can pin versions (stability and cacheβfriendly).
- Keep
requires-pythonand dependencies up to date; commituv.lockfor reproducibility. - Ensure the entry point remains
mcp-server(or update documentation if renamed).
We're maintaining a fully open sourced MCP registry. If you're interested in contributing, please check this doc.
- MCP Documentation - Official MCP documentation
- MCP Python SDK Official MCP SDK repo
MIT Licence
Happy building! π
Need help? Check the issues page