
天气 MCP 服务器

2025.04.01
0
Python天气查询位置服务位置服务
天气 MCP 服务器是一个基于 FastMCP 构建的天气查询服务,提供全球城市天气信息查询功能。该服务支持查询温度、湿度和天气描述信息,并允许在摄氏度和华氏度之间切换温度单位。它通过 Model Context Protocol (MCP) 实现,具有完整的日志记录功能。
View on GitHub
Overview
基本能力
产品定位
天气 MCP 服务器是一个专门用于查询全球城市天气信息的服务。
核心功能
- 支持全球城市天气查询
- 提供温度、湿度和天气描述信息
- 支持摄氏度和华氏度温度单位切换
- 基于 Model Context Protocol (MCP) 实现
- 完整的日志记录
适用场景
- 个人用户查询特定城市的天气情况
- 应用程序集成天气数据
- 旅行规划时了解目的地天气
MCP 工具
get_weather
获取指定城市的天气信息。
参数:
- city
: 城市名称(必填)
- units
: 温度单位(可选,默认为 "metric")
- "metric": 摄氏度
- "imperial": 华氏度
常见问题解答
无明确常见问题解答部分。
使用教程
使用依赖
- Python 3.8+
- OpenWeatherMap API 密钥
- uv (Python 包管理工具)
安装教程
选项 1:使用 uvx(推荐)
将以下配置添加到 Claude Desktop 的配置文件 claude_desktop_config.json
中:
{
"mcpServers": {
"weather-mcp-server": {
"command": "uvx",
"args": [
"weather-mcp-server"
],
"env": {
"OPENWEATHER_API_KEY": "你的OpenWeatherMap_API密钥"
}
}
}
}
选项 2:本地开发模式
- 克隆仓库并安装依赖:
git clone <repository-url>
cd weather-mcp-server
make install
- 设置环境变量:
创建
.env
文件并添加以下内容:
OPENWEATHER_API_KEY=你的OpenWeatherMap_API密钥
- 在 Claude Desktop 配置文件中添加:
{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"--directory",
"path/to/src/weather_mcp_server",
"run",
"weather-mcp-server"
],
"env": {
"OPENWEATHER_API_KEY": "你的OpenWeatherMap_API密钥"
}
}
}
}
调试方式
运行服务器:
make run
可用命令:
make install # 安装依赖
make format # 格式化代码
make lint # 运行代码检查
make clean # 清理临时文件
make run # 运行服务器