Template MCP Server

Template MCP Server

A production-ready template for building Model Context Protocol servers in Python, featuring example tools, structured logging, and multiple transport protocols.

Category
访问服务器

README

Template MCP Server

Python 3.12+ Tests Coverage License: Apache 2.0 Open in GitHub Codespaces

A production-ready template for developing Model Context Protocol (MCP) servers using Python and FastMCP. This server provides a foundation for creating MCP-compliant servers with comprehensive examples of tools, structured logging, configuration management, and containerized deployment.

The template includes three example MCP tools: a multiply calculator, a code review prompt generator, and a Red Hat logo tool. It demonstrates best practices for MCP server development including proper error handling, health checks, multiple transport protocols (HTTP, SSE, streamable-HTTP), SSL support, and comprehensive development tooling.

Features

  • FastMCP + FastAPI with multiple transport protocols (HTTP, SSE, streamable-HTTP)
  • Three example tools: multiply calculator, code review prompt, Red Hat logo
  • Pydantic configuration via environment variables
  • Structured JSON logging with structlog
  • SSL/TLS support for secure deployments
  • Container-ready with Red Hat UBI base image
  • OpenShift deployment manifests included
  • Full CI/CD with GitHub Actions (tests, linting, security, releases)
  • OAuth integration with PostgreSQL token storage

Quick Start

git clone https://github.com/redhat-data-and-ai/template-mcp-server
cd template-mcp-server
make install        # creates venv, installs deps + pre-commit hooks
make local          # starts server on localhost:5001

Verify in another terminal:

curl http://localhost:5001/health

<details> <summary>Manual setup (without Make)</summary>

# Create venv and install
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"
pre-commit install

# Configure and run
cp .env.example .env
template-mcp-server

# Verify
curl http://localhost:5001/health

</details>

How to Use This Template

Option 1: GitHub Template (Recommended)

  1. Click the "Use this template" button at the top of the repository page.
  2. Name your new repository (e.g., my-mcp-server).
  3. Clone your new repository and follow the rename checklist below.

Option 2: Manual Clone

git clone https://github.com/redhat-data-and-ai/template-mcp-server.git my-mcp-server
cd my-mcp-server
rm -rf .git
git init

Rename Checklist

After creating your project, replace all references to template-mcp-server and template_mcp_server with your project name. The following files require updates:

File / Directory What to Change
template_mcp_server/ Rename the package directory (e.g.,my_mcp_server/)
pyproject.toml name, project.scripts entry, [project.urls], [tool.coverage.run] source
Makefile References in lint, local, and deployment targets
Containerfile COPY source path and CMD module path
compose.yaml container_name, service name, healthcheck URL
deployment/openshift/ App labels, image names, route hostnames in all manifests (deployment.yaml, route.yaml, kustomization.yaml, etc.)
.github/workflows/ Workflow names and paths
README.md Title, description, clone URL, and all badge URLs (tests, coverage, Codespaces)
.env.example Adjust defaults if your server uses a different port or protocol

Verify Rename

Run this to catch any leftover references:

grep -rn "template.mcp" --include="*.py" --include="*.yaml" --include="*.yml" --include="*.toml" --include="*.md" .

The output should be empty (or only match this README section itself).

Configuration

Variable Default Description
MCP_HOST localhost Server bind address
MCP_PORT 5001 Server port (1024-65535)
MCP_TRANSPORT_PROTOCOL http Transport protocol (http, sse, streamable-http)
MCP_SSL_KEYFILE None SSL private key file path
MCP_SSL_CERTFILE None SSL certificate file path
ENABLE_AUTH False* Enable OAuth authentication (see Auth Guide)
USE_EXTERNAL_BROWSER_AUTH False Browser-based OAuth for local dev
PYTHON_LOG_LEVEL INFO Logging level

* ENABLE_AUTH defaults to False in .env.example but True in code. Always copy .env.example to .env to start with auth disabled.

Documentation

Guide Description
Architecture System diagrams, code structure, key components, MCP tools
Development Setup, running locally, testing, code quality
Deployment Podman, OpenShift, container configuration
CI/CD Workflows, pipeline features, running CI locally
Contributing Development workflow, commit conventions, PR process
Security Vulnerability reporting policy
Changelog Release history
Authentication OAuth setup, auth modes, troubleshooting
Tutorial Your First Tool in 5 Minutes
Examples FastMCP and LangGraph client examples

Contributing

See CONTRIBUTING.md for detailed guidelines.

# Fork, clone, and set up
git clone https://github.com/<your-username>/template-mcp-server.git
cd template-mcp-server
make install

# Create a branch, make changes, verify
git checkout -b feat/your-feature
make lint && make test && make pre-commit

# Commit and open a PR
git commit -m "feat: your descriptive message"
git push origin feat/your-feature

License

Apache 2.0

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选