FastMCP 欢迎服务器
](https://github.com/cgjdparashar/template-mcp-server-in-python-fastmcp/actions/workflows/github-deploy.yml)  
一个使用FastMCP构建的模型上下文协议(MCP)服务器,提供问候功能。
🚀 快速部署
一键部署:
您已部署的服务器将在以下地址可用:
ghcr.io/cgjdparashar/template-mcp-server-in-python-fastmcp:latest # GitHub Container Registry
https://your-app-name.up.railway.app # Railway
https://your-app-name.onrender.com # Render特点/功能
- 一个简单的问候工具,接收名字并返回个性化的问候语
- 采用FastMCP构建,便于与MCP客户端集成
- 支持流式传输和SSE传输模式
- Docker支持,便于部署
- 全面的CI/CD(持续集成/持续交付)流水线
- 用于监控的健康检查端点
- 可投入生产的配置
安装
从 PyPI(发布时)
pip install fastmcp-greet-server来自源(或“来源”)
git clone https://github.com/cgjdparashar/template-mcp-server-in-python-fastmcp.git
cd template-mcp-server-in-python-fastmcp
uv sync用法
运行服务器
# Using uv
uv run python greet.py
# Or if installed via pip
python greet.py服务器将在 http://127.0.0.1:8002 默认情况下。
与MCP客户端配合使用
服务器提供以下工具:
greet(name: str) -> str根据给定的名字返回个性化的问候语health() -> str用于监控的健康检查端点
测试已部署的服务器
一旦部署完成,您就可以测试您的服务器:
# Test the greet tool
curl -X POST "https://your-deployed-url/mcp" \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "greet", "arguments": {"name": "World"}}}'
# Test health check
curl "https://your-deployed-url/health"Docker 部署
# Build and run with Docker Compose
docker-compose up -d
# Or build and run manually
docker build -t fastmcp-greet .
docker run -p 8002:8002 fastmcp-greet配置
服务器可以通过环境变量进行配置:
HOST绑定地址(默认:127.0.0.1,使用0.0.0.0(用于云部署)PORT端口号(默认:8002)TRANSPORT传输模式(sse或者streamable-http,默认:sse)
发展
设置开发环境
# Clone the repository
git clone https://github.com/cgjdparashar/template-mcp-server-in-python-fastmcp.git
cd template-mcp-server-in-python-fastmcp
# Install with development dependencies
uv sync --all-extras运行测试
uv run pytest代码质量
# Linting
uv run ruff check .
# Formatting
uv run ruff format .
# Type checking
uv run mypy .部署选项
1. 一键部署(推荐)
2. GitHub 容器注册表
该项目包含了GitHub Actions,用于在发布时自动构建并推送Docker镜像到GitHub容器注册表。
docker pull ghcr.io/cgjdparashar/template-mcp-server-in-python-fastmcp:latest3. 手动云部署
铁路(手册)
- 访问 railway.app(可译为“铁路应用”或保持原样作为专有名词)
- 连接您的GitHub账户
- 从此仓库部署
渲染(手动)
- 访问 render.com(注:在中文语境中,网址通常直接保留原样,不进行翻译,因此“render.com”直接作为网址使用,无需翻译。)
- 创建一个新的Web服务
- 连接这个GitHub仓库
Heroku
heroku create your-app-name
heroku container:push web
heroku container:release webFly.io
flyctl launch
flyctl deploy4. 自托管
使用提供的 docker-compose.yml 用于生产环境部署,配合nginx反向代理。
API 文档
当服务器运行时,它会暴露MCP协议端点。您可以使用任何MCP客户端或提供的测试客户端来测试问候工具。
示例用法
from greetclient import test_greet_tool
# Test the greeting tool
result = test_greet_tool("Alice")
print(result) # Output: Hello, Alice!MCP客户端配置
在您的MCP客户端配置中添加以下内容:
{
"servers": {
"fastmcp-greet": {
"type": "http",
"url": "https://your-deployed-url",
"transport": "sse"
}
}
}贡献
- 为仓库创建分支(或:克隆仓库)
- 创建一个特性分支:
git checkout -b feature-name - 进行你的更改并添加测试
- 运行测试套件:
uv run pytest - 提交拉取请求
许可证
这个项目采用MIT许可证授权——详见 许可证 文件中有详细信息。
致谢
- 构建于 FastMCP
- 模型上下文协议(由……提出/定义) “Anthropic”翻译成中文是“人类中心的”或“以人为本的”,具体含义取决于上下文,但通常指的是以人类为核心或出发点的观念或实践
支持
- 在(某平台/系统)上创建一个问题
- 检查 FastMCP 文档
- 审查/回顾 MCP规范
______________________________________________________________________
