内容
# 全球天气 MCP 服务器
一个 [模型上下文协议(MCP)](https://modelcontextprotocol.io) 服务器,为 AI 助手提供天气数据访问,无需 API 密钥。
- 来自 [国家气象服务 API](https://api.weather.gov) 的美国气象警报
- 来自国家气象服务的美国逐点预报
- 来自 [Open-Meteo](https://open-meteo.com) 的全球 5 天预报,包括印度
## 要求
| 需求 | 版本 |
| --- | --- |
| Python | 3.14+ |
| uv | 最新 |
| Claude Desktop 或其他 MCP 客户端 | 最新 |
检查本地版本:
```bash
python --version
uv --version
```
## 安装
```bash
git clone https://github.com/YOUR-USERNAME/global-weather-mcp-server.git
cd global-weather-mcp-server
uv sync
```
无需 API 密钥。
## 连接到 Windows 上的 Claude Desktop
对于 Microsoft Store/package 安装的 Claude Desktop,请打开此配置文件:
```text
%LOCALAPPDATA%\Packages\Claude_pzs8sxrjxfjjc\LocalCache\Roaming\Claude\claude_desktop_config.json
```
仅在 `mcpServers` 对象中添加此服务器条目:
```json
{
"mcpServers": {
"global-weather": {
"command": "uv",
"args": [
"--directory",
"C:\\path\\to\\weather-mcp",
"run",
"global_weather_mcp_server.py"
]
}
}
}
```
如果配置文件中已经有其他 MCP 服务器,请保留它们并添加 `global-weather` 块。保存文件后重启 Claude Desktop。服务器应暴露以下工具:
- `get_alerts`
- `get_forecast`
- `get_forecast_global`
## 工具
### `get_alerts`
获取美国某个州的活跃气象警报。
示例:
```text
加利福尼亚州有哪些活跃的气象警报?
```
### `get_forecast`
获取美国某个位置的详细国家气象服务预报,位置由纬度和经度指定。
示例:
```text
纬度 40.71,经度 -74.01 的天气预报是什么?
```
### `get_forecast_global`
获取全球任意位置的当前天气状况和 5 天预报,位置由纬度和经度指定。
示例:
```text
纬度 19.0760,经度 72.8777 的天气预报是什么?
获取纬度 28.6139,经度 77.2090 的天气。
```
有用的印度城市坐标:
| 城市 | 纬度 | 经度 |
| --- | --- | --- |
| 新德里 | 28.6139 | 77.2090 |
| 孟买 | 19.0760 | 72.8777 |
| 班加罗尔 | 12.9716 | 77.5946 |
| 钦奈 | 13.0827 | 80.2707 |
| 加尔各答 | 22.5726 | 88.3639 |
| 海得拉巴 | 17.3850 | 78.4867 |
| 浦那 | 18.5204 | 73.8567 |
## 本地测试
直接运行 MCP 服务器:
```bash
uv run global_weather_mcp_server.py
```
如果它启动并保持静默,则服务器已准备好接受 MCP 客户端。
## 项目结构
```text
global-weather-mcp-server/
|-- global_weather_mcp_server.py
|-- pyproject.toml
|-- uv.lock
|-- README.md
`-- .gitignore
```