# weather_mcp **Repository Path**: daitianjun/weather_mcp ## Basic Information - **Project Name**: weather_mcp - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-20 - **Last Updated**: 2026-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Weather MCP Server 基于 Model Context Protocol (MCP) 的天气查询服务,支持获取美国各州的天气预警和指定位置的天气预报。 ## 功能 - `get_alerts` - 获取美国各州的天气预警 - `get_forecast` - 获取指定经纬度的天气预报 ## 快速开始 ### 1. 安装依赖 ```bash uv sync ``` ### 2. 启动服务 **开发模式 (stdio 传输):** ```bash uv run weather.py ``` **生产模式 (HTTP):** ```bash uv run uvicorn weather:app --host 0.0.0.0 --port 8000 ``` ## 生产部署 ### 使用 uvicorn 部署 推荐使用 uvicorn 运行服务: ```bash uv run uvicorn weather:app --host 0.0.0.0 --port 8000 --workers 4 ``` ### 使用 systemd 服务 创建 `/etc/systemd/system/weather.service`: ```ini [Unit] Description=Weather MCP Server After=network.target [Service] User=www-data Group=www-data WorkingDirectory=/path/to/weather ExecStart=/path/to/weather/.venv/bin/uvicorn weather:app --host 0.0.0.0 --port 8000 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target ``` 启动服务: ```bash sudo systemctl daemon-reload sudo systemctl enable weather sudo systemctl start weather ``` ### 使用 Docker 部署 ```dockerfile FROM python:3.12-slim WORKDIR /app COPY . . RUN pip install uv && uv sync EXPOSE 8000 CMD ["uv", "run", "uvicorn", "weather:app", "--host", "0.0.0.0", "--port", "8000"] ``` 构建运行: ```bash docker build -t weather-mcp . docker run -d -p 8000:8000 --name weather weather-mcp ``` ### 使用 Nginx 反向代理 ```nginx server { listen 80; server_name your-domain.com; location / { proxy_pass http://127.0.0.1:8000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 86400; } } ``` ## API 端点 服务启动后可通过 HTTP 访问,默认端口 8000。 ## 环境变量 | 变量 | 说明 | 默认值 | |------|------|--------| | `HOST` | 服务监听地址 | `0.0.0.0` | | `PORT` | 服务监听端口 | `8000` | ## 技术栈 - Python 3.12+ - [FastMCP](https://github.com/jlowin/fastmcp) - [httpx](https://www.python-httpx.org/) - [uvicorn](https://www.uvicorn.org/) - NWS API