澳门气象MCP服务器
模型上下文协议(MCP)服务器,提供澳门气象和地球物理局(SMG)提供的澳门实时天气数据。该服务器通过MCP工具公开天气信息,允许AI助手获取当前天气状况、每日预报和7天天气预报。
特性
- 实时天气数据:获取当前天气状况,包括温度、湿度、风速。
- 今日预测:检索今天的天气预报和详细描述
- 7天预测:获取未来7天的扩展天气预报
- HTTP流式MCP:使用FastMCP构建,支持流式HTTP,易于集成
- 中文语言支持:所有天气数据均以繁体中文提供
需求
- Python 3.12或更高版本
uv包管理器(推荐)或pip
安装
使用紫外线(推荐)
# Install dependencies
uv sync使用pip
# Install dependencies
pip install httpx "mcp[cli]>=1.22.0"部署
方法一:使用Docker Compose(推荐)
使用Docker Compose可以轻松部署MCP服务器,您也可以选择同时部署MCPO网桥服务器。
# start MCP server
docker compose up -d
# If you want to enable MCPO server, please edit docker-compose.yml
# Uncomment mcpo service part, then run:
docker compose up -d服务器将在以下时间运行 http://0.0.0.0:8001/mcp。如果启用MCPO,它将在 http://0.0.0.0:8000.
# view logs
docker compose logs -f
# stop the service
docker compose down方法2:直接用Python运行
在主机上直接运行MCP服务器:
# use uv
uv run weather.py --port 8001
# or use python
python weather.py --port 8001服务器将在以下时间运行 http://0.0.0.0:8001/mcp.
方法3:手动构建Docker镜像
如果你想手动构建和运行Docker容器:
# build the image
docker build -t macau-weather-mcp .
# run the container
docker run -d -p 8001:8001 --name macau-weather-mcp macau-weather-mcp命令行参数
--host:绑定地址(默认值:0.0.0.0)--port:侦听端口(默认值:8000)
用法
OpenWeb用户界面
OpenWebUI需要一个MCP到OpenAI桥接服务器(MCPO)将MCP工具转换为OpenAI兼容的工具API:
uvx mcpo --port 8000 --api-key "top-secret" --server-type "streamable-http" -- http://0.0.0.0:8001/mcp然后在OpenWebUI设置中配置外部工具。有关更多MCPO部署方法,请参阅 官方文档.
克劳德桌面版
将以下配置添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"macau-weather": {
"url": "http://localhost:8001/mcp",
"transport": "http"
}
}
}其他MCP客户端
任何支持HTTP流传输的MCP客户端都可以在以下位置连接到此服务器:
http://localhost:8001/mcp可用工具
服务器提供三个MCP工具:
1. get_macau_realtime_weather
获取澳门当前「整点实况」天气数据,包含:
- 更新时间
- 当前温度(°C)
- 相对湿度(%)
- 风速(km/h)
- 风向
2. get_macau_today_forecast
获取澳门「今日预测」与天气概述,包含:
- 今日日期
- 天气形势
- 今日天气概况
3. get_macau_7days_forecast
获取澳门「7天预测」与天气概述,包含:
- 每日预测温度范围
- 每日湿度预测
- 每日天气描述
数据源
所有天气数据均来自澳门气象地球物理局(SMG)的XML API:
- 当前天气:
https://xml.smg.gov.mo/c_actual_brief.xml - 今日预测:
https://xml.smg.gov.mo/c_forecast.xml - 7天预测:
https://rss.smg.gov.mo/c_WForecast7days_rss.xml
技术细节
- 框架:FastMCP(MCP服务器框架)
- HTTP客户端:httpx
- 服务器:Uvicorn(ASGI服务器)
- 数据格式:使用ElementTree进行XML解析
- 运输:HTTP流式传输
