MCP Weather Server
by liusicheng
README.md
# MCP Weather Server
一个基于 FastMCP 的天气查询 MCP Server,提供当前天气、未来天气预报、摄氏度/华氏度转换、热门城市资源和旅行天气建议 Prompt。
项目包含两个启动入口:
- `server.py`:本地 stdio 模式,适合 Claude Desktop、Cursor、Cherry Studio 等本地 MCP 客户端。
- `server_remote.py`:Streamable HTTP 模式,适合部署到 ModelScope 等远程托管平台。
## 功能
- `get_weather(city: str)`:查询指定城市当前天气。
- `get_forecast(city: str, days: int = 3)`:查询指定城市未来天气预报,默认 3 天。
- `temperature_convert(value: float, from_unit: str)`:摄氏度与华氏度互转。
- `weather://cities`:返回常用城市列表资源。
- `travel_advisor(destination: str, date: str)`:生成旅行天气咨询 Prompt。
天气数据来自 `wttr.in`,无需额外 API Token。
## 环境要求
- Python >= 3.12
- 推荐使用 `uv` 管理依赖
## 安装依赖
```bash
uv sync
```
如果不使用 `uv`,也可以在虚拟环境中安装依赖:
```bash
pip install "mcp[cli]>=1.27.0" "httpx>=0.28.1"
```
## 本地运行
stdio 模式:
```bash
uv run python server.py
```
MCP 客户端配置示例:
```json
{
"mcpServers": {
"weather-server": {
"command": "uv",
"args": ["run", "python", "server.py"]
}
}
}
```
## 远程运行
Streamable HTTP 模式:
```bash
uv run python server_remote.py
```
默认监听:
```text
http://0.0.0.0:8000/mcp/
```
远程 MCP 客户端配置示例:
```json
{
"mcpServers": {
"weather-server": {
"url": "http://127.0.0.1:8000/mcp/"
}
}
}
```
## ModelScope 部署说明
在 ModelScope 创建或部署 MCP Server 时,可填写本项目的 GitHub 仓库地址,并使用远程入口文件:
```bash
python server_remote.py
```
服务会以 Streamable HTTP 方式启动,监听 `0.0.0.0:8000`,MCP endpoint 为:
```text
/mcp/
```
如果平台支持自定义启动命令,建议使用:
```bash
uv run python server_remote.py
```
或在平台环境中提前安装依赖后使用:
```bash
python server_remote.py
```
## 项目结构
```text
.
├── README.md
├── pyproject.toml
├── server.py
├── server_remote.py
└── uv.lock
```
## 许可证
如需开源发布,请根据实际情况补充 License 文件。
TDQS
A3.9/5.0
Scored across 3 tools
Disambiguation5/5
Each tool has a clearly distinct purpose: get_forecast for future days, get_weather for current conditions, and temperature_convert for unit conversion. No overlap exists.
Naming Consistency4/5
All tools use snake_case, but two follow verb_noun pattern (get_forecast, get_weather) while one uses noun_verb (temperature_convert), a minor inconsistency.
Tool Count4/5
3 tools is slightly below average for a weather server, but still reasonable for core functionality (current, forecast, conversion). The count feels lean but not insufficient.
Completeness4/5
Covers basic current weather and forecast, plus a unit converter. Missing features like alerts or historical data, but the essential weather information needs are met.
Maintenance
ActivityInactive
ResponsivenessNo issues