Production MCP Template
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Production MCP TemplateCheck the system health and list all active background jobs."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Production MCP Template
一个偏生产级、可扩展、可直接二次开发的 Python MCP 服务模版。它不是单文件 demo,而是围绕最新 MCP 官方 Python SDK、当前 Streamable HTTP 规范、远程发布形态、认证钩子、可观测性、后台任务、资源/提示/工具分层做出的完整工程骨架。
设计目标
使用官方
mcpPython SDK 的稳定v1.x能力,而不是临时 API。默认面向远程部署:
Streamable HTTP + json_response + stateless_http。保留
stdio兼容,方便本地接入 Claude / Inspector / 其他 MCP host。工具、资源、提示、服务层、传输层、认证层清晰分离。
提供健康检查、readiness、Prometheus metrics、
server.json、Docker、CI、类型检查和测试。演示 MCP 新能力的落点:structured output、elicitation、sampling、resource templates、completion、event replay。
已实现能力
1. 核心工程骨架
src/mcp_template/app容器、生命周期、Server Factory。
src/mcp_template/services纯服务层,承载业务逻辑,不直接依赖传输协议。
src/mcp_template/modulesMCP capability 层,负责注册
tools/resources/prompts。
src/mcp_template/securityToken verifier 与认证装配。
src/mcp_template/transportSQLite event store,用于 Streamable HTTP 的重放与恢复准备。
src/mcp_template/types所有结构化返回模型。
2. 内置模块
system健康检查、echo、能力目录、构建信息资源、系统提示。
workspace安全的只读工作区扫描、文本读取、资源清单。
jobs后台任务提交、状态查询、任务资源模板、postmortem prompt。
design功能 brief 采集、工具契约设计、host sampling 示例、生产准备模板资源。
3. 生产配套
Streamable HTTP与stdio双传输。DNS rebinding 防护与
Origin/Hostallowlist。JWT / static bearer 两种 verifier 装配路径。
healthz、readyz、metrics、manifest、server.json。SQLite event replay store。
ruff + mypy + pytest + GitHub Actions。Dockerfile、.env.example、Makefile、server.json。
为什么这套模版偏“当前最优实践”
这份模版刻意吸收了近一段时间 MCP 官方和社区里最值得保留的思路:
优先使用官方 SDK 的
FastMCP稳定能力,而不是依赖不确定封装。默认使用
Streamable HTTP,并保留stdio,适配本地 host 与远程部署双场景。把“协议层”与“业务层”拆开,避免工具函数直接长成不可测试的业务体。
让 structured output 成为默认,而不是把一切结果都塞进字符串。
把认证、事件重放、后台任务、可观测性当成一等公民,而不是上线前才补。
把
elicitation和sampling作为未来高级能力保留入口。
快速开始
1. 安装
uv sync --all-groups2. 配置
cp .env.example .env3. 运行诊断
uv run mcp-template doctor4. 运行 HTTP 模式
uv run mcp-template run --transport streamable-http默认监听:
Host:
127.0.0.1Port:
8000MCP endpoint:
/mcp
5. 运行 stdio 模式
uv run mcp-template run --transport stdio与 Host / Inspector 联调
Claude Code / Claude
claude mcp add --transport http mcp-template http://localhost:8000/mcpMCP Inspector
npx -y @modelcontextprotocol/inspector然后连接:
http://localhost:8000/mcp常用命令
uv run mcp-template show-config
uv run mcp-template doctor
uv run mcp-template run --transport stdio
uv run mcp-template run --transport streamable-http
uv run ruff format .
uv run ruff check .
uv run mypy src
uv run pytest或者:
make sync
make fmt
make lint
make test
make run-http
make run-stdio
make doctor配置说明
关键环境变量如下:
MCP_TEMPLATE_DEFAULT_TRANSPORTstdio/sse/streamable-http
MCP_TEMPLATE_JSON_RESPONSE是否为 Streamable HTTP 返回 JSON response
MCP_TEMPLATE_STATELESS_HTTP是否启用 stateless 模式
MCP_TEMPLATE_EVENT_STORE_BACKENDnone/sqlite
MCP_TEMPLATE_EVENT_STORE_PATHSQLite 事件库路径
MCP_TEMPLATE_ENABLED_MODULES启用哪些 capability 模块
MCP_TEMPLATE_AUTH_MODEnone/static-bearer/jwt
MCP_TEMPLATE_AUTH_ISSUER_URL认证发行方
MCP_TEMPLATE_AUTH_RESOURCE_SERVER_URL资源服务器 URL
MCP_TEMPLATE_JWT_JWKS_URLJWT 验签 JWKS 地址
项目结构
.
├── .github/workflows/ci.yml
├── CLAUDE.md
├── Dockerfile
├── Makefile
├── server.json
├── src/mcp_template
│ ├── app
│ ├── core
│ ├── modules
│ ├── security
│ ├── services
│ ├── transport
│ ├── types
│ ├── cli.py
│ └── config.py
└── tests如何扩展
新增一个业务模块
在
src/mcp_template/modules/下新增模块文件。在模块里实现
register(server, container) -> ModuleDescriptor。把工具逻辑放入
services/,不要直接堆在 tool 函数里。在
src/mcp_template/modules/__init__.py注册。写对应测试。
接入真实外部系统
推荐路径:
在
services/新增客户端或仓储层。用
tenacity包装重试。设定 timeout、错误分类和结构化输出。
如果有副作用,明确 tool annotation 和鉴权边界。
增加远程认证
推荐路径:
保持
AuthSettings与 verifier 解耦。优先接入标准 issuer + JWKS。
作用域设计要贴近真实操作边界。
不要把“静态 token”当成真正生产方案。
健康与运维接口
GET /healthz进程级健康与模块状态。
GET /readyz就绪探针。
GET /metricsPrometheus 指标。
GET /manifest运行时 manifest。
GET /server.jsonRegistry 风格输出。
当前测试状态
已验证:
ruff checkmypy srcpytest
后续建议
如果你要把这个模版推进到更重的企业场景,建议继续演进:
OpenTelemetry tracing / metrics exporter
Redis 或 Postgres event store
多租户鉴权与 header variable 注入
MCP Apps /
ui://资源更完整的 OAuth Authorization Server provider
更强的审计日志与策略引擎
设计依据与参考
这份模版主要基于以下官方资料与实现方向:
MCP Python SDK(稳定
v1.x):https://github.com/modelcontextprotocol/python-sdkMCP Transport 规范(
2025-11-25,Streamable HTTP与安全要求):https://modelcontextprotocol.io/specification/2025-11-25/basic/transportsMCP Registry Remote Servers /
server.json:https://modelcontextprotocol.io/registry/remote-servers
如果你希望,我还可以在这份模版上继续扩展:
多租户 SaaS 版本
接入真实数据库 / Redis / S3 / Queue
OAuth 资源服务器完整实现
MCP Apps 前端壳层
面向某个具体业务域的企业级 server 脚手架
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/RichFerry/-MCP-'
If you have feedback or need assistance with the MCP directory API, please join our Discord server