使用说明
OpenWeather MCP服务器
一种使用Open-Meteo API提供天气数据的OpenWeather模型上下文协议(MCP)服务器。
特性
- 仅使用坐标获取当前天气数据
- 仅使用坐标获取天气预报数据
- 不需要API密钥(使用Open-Meteo API)
- 缓存以提高性能
- 支持公制、英制和标准单位
重要提示
此服务器只接受纬度和经度坐标。在获取天气数据之前,您必须首先获取位置的坐标。该设计强制执行两步过程:
- 获取位置的坐标(使用aws位置mcp服务器等其他服务)
- 使用这些坐标获取天气数据
安装
来源
# Clone the repository
git clone <repository-url>
cd openweather-mcp-server
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
# Install the package in development mode
pip install -e .
完成项目后,您可以停用虚拟环境:
deactivate
用法
运行服务器
您可以使用CLI运行服务器:
# Run with standard stdio transport (for use with MCP clients)
python openweather_server_cli.py
# Run with SSE transport (for web-based clients)
python openweather_server_cli.py --sse --port 8888
MCP配置
要将此服务器与MCP客户端一起使用,请将以下配置添加到您的 mcp.json 文件:
{
"servers": [
{
"name": "openweather-mcp-server",
"command": "python /path/to/openweather-mcp-server/openweather_server_cli.py",
"transport": "stdio"
}
]
}
替换 /path/to/openweather-mcp-server 安装的实际路径。
环境变量
FASTMCP_LOG_LEVEL:设置日志记录级别(默认值:警告)
可用工具
get_current天气坐标
使用纬度和经度坐标获取当前天气。
get_current_weather_by_coordinates(
latitude: float, # Latitude coordinate
longitude: float, # Longitude coordinate
units: str = "metric" # Units of measurement (metric, imperial, standard)
)
获取预测坐标
使用纬度和经度坐标获取天气预报。
get_forecast_by_coordinates(
latitude: float, # Latitude coordinate
longitude: float, # Longitude coordinate
days: int = 3, # Number of days (1-16)
units: str = "metric" # Units of measurement (metric, imperial, standard)
)
许可证
MIT许可证
