weather mcp
A Model Control Protocol (MCP) based service that allows users to query weather forecasts by coordinates and receive weather alerts for U.S. states.
A Model Control Protocol (MCP) based service that allows users to query weather forecasts by coordinates and receive weather alerts for U.S. states.
x000D 一个基于 Model Control Protocol (MCP) 的天气信息服务,提供天气预报和警报查询功能。x000D x000D
x000D
- 获取美国各州的天气警报(get_alerts
)x000D
- 通过经纬度查询天气预报(get_forecast
)x000D
x000D
x000D - Python 3.11+x000D - MCP (Model Control Protocol)x000D - FastMCP 服务器_x000D_ - LangGraph + LangChain_x000D_ - SSE (Server-Sent Events) 传输_x000D_ x000D
x000D
1. 克隆仓库:x000D
bash_x000D_
git clone https://github.com/haichaozheng/weather-mcp.git_x000D_
cd weather-mcp_x000D_
x000D
x000D
2. 创建虚拟环境:x000D
bash_x000D_
# 使用 Python 标准库_x000D_
python -m venv weather_venv_x000D_
_x000D_
# 激活虚拟环境(Windows)_x000D_
weather_venvScriptsactivate_x000D_
_x000D_
# 激活虚拟环境(Linux/Mac)_x000D_
source weather_venv/bin/activate_x000D_
x000D
x000D
3. 安装依赖:x000D
bash_x000D_
pip install -r requirements.txt_x000D_
x000D
x000D
4. 配置环境变量:x000D
- 创建 .env
文件,参考 .env.example
文件格式_x000D_
- 添加必要的 API 密钥_x000D_
x000D
x000D
1. 启动 Weather 服务器:x000D
bash_x000D_
python weather/weather.py_x000D_
x000D
服务器将在 http://localhost:8000 上启动,使用 SSE 传输。x000D
x000D
2. 在另一个终端窗口中运行客户端:x000D
bash_x000D_
python weather/mcp_client.py_x000D_
x000D
客户端将连接到服务器并执行一系列天气查询测试。x000D
x000D
x000D
x000D
python_x000D_
get_alerts(state: str) -> str_x000D_
x000D
- state
: 两字母美国州代码(例如:CA, NY)x000D
- 返回:该州的活跃天气警报列表_x000D_
x000D
x000D
python_x000D_
get_forecast(latitude: float, longitude: float) -> str_x000D_
x000D
- latitude
: 位置纬度_x000D_
- longitude
: 位置经度_x000D_
- 返回:该位置的天气预报_x000D_
x000D
weather-mcp/x000D ├── weather/x000D │ ├── weather.py # 主服务器文件_x000D_ │ ├── mcp_client.py # 客户端测试文件_x000D_ ├── requirements.txt # 项目依赖_x000D_ ├── .env.example # 环境变量示例_x000D_ └── README.md # 本文档_x000D_ ```x000D x000D
x000D
项目使用 .env
文件存储环境变量和敏感信息。请按照以下步骤设置:x000D
x000D
1. 复制环境变量模板文件:x000D
bash_x000D_
cp .env.example .env_x000D_
x000D
x000D
2. 编辑 .env
文件,填入您的实际配置:x000D
_x000D_
MOONSHOT_API_KEY=your_actual_api_key_x000D_
x000D
x000D
3. 确保 .env
文件不会被提交到版本控制系统中