内容
# mcp-python
一个 [Model Context Protocol](https://modelcontextprotocol.io) (MCP) 服务器,通过 [国家气象局 API](https://www.weather.gov/documentation/services-web-api) 提供美国天气数据,作为工具、资源和提示,供 MCP 兼容的客户端(如 Claude Desktop)使用。
## 功能
**工具**
- `get_alerts(state)` — 获取某个两字母的美国州代码(例如 `CA`、`NY`)的活跃天气警报
- `get_forecast(latitude, longitude)` — 获取给定位置的未来 5 个时间段的预报
**资源**
- `weather://states` — 有效的两字母美国州代码列表
- `weather://alerts/{state}` — 任意州的警报,作为可读资源
- `CA`、`NY`、`TX`、`FL` 的静态警报资源(因此它们可以从 Claude Desktop 的选择器中附加,该选择器仅列出静态资源)
**提示**
- `weather_briefing(state)` — 针对某个州的简明严重天气简报
- `trip_packing_advice(latitude, longitude)` — 根据位置的预报提供行李打包建议
## 要求
- Python >= 3.11
- [uv](https://docs.astral.sh/uv/)
## 设置
```bash
uv sync
```
## 运行服务器
```bash
uv run weather.py
```
服务器通过标准输入/输出进行通信,因此它主要是由 MCP 客户端启动,而不是单独运行。
## 与 Claude Desktop 一起使用
将以下内容添加到您的 Claude Desktop 配置文件(`claude_desktop_config.json`):
```json
{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mcp-python",
"run",
"weather.py"
]
}
}
}
```
重启 Claude Desktop 后,天气工具、资源和提示将可用。
## 项目结构
- `weather.py` — MCP 服务器(工具、资源、提示)
- `main.py` — 项目模板的占位入口点
- `pyproject.toml` / `uv.lock` — 依赖项,由 `uv` 管理