Skip to main content
Glama

Weather Server

by NeilJo-GY

<<<<<<< HEAD <<<<<<< HEAD

Weather Server

全球天气查询MCP服务器 - 提供实时天气、天气预报和多城市天气比较功能

🌤️ 功能特性

  • 实时天气查询: 获取任意城市的当前天气信息
  • 坐标天气查询: 支持经纬度坐标查询天气
  • 天气预报: 提供最多5天的天气预报
  • 多城市比较: 同时查询多个城市的天气信息
  • 多语言支持: 支持中英文等多种语言
  • 智能提示: 根据查询类型生成相应的提示模板

🚀 快速开始

1. 环境配置

首先需要获取OpenWeatherMap API密钥:

  1. 访问 OpenWeatherMap 注册账号
  2. 获取免费的API密钥
  3. 配置环境变量:
# 编辑 .env 文件 WEATHER_API_KEY=your_openweathermap_api_key_here WEATHER_API_BASE_URL=https://api.openweathermap.org/data/2.5 WEATHER_API_TIMEOUT=30 DEFAULT_UNITS=metric DEFAULT_LANGUAGE=en

2. 安装依赖

pip install -r requirements.txt # 或者 pip install requests pyyaml pydantic mcp-factory

3. 启动服务器

python server.py

🛠️ 可用工具

1. 城市天气查询

get_weather_by_city(city: str, country: str = "", units: str = "metric")
  • city: 城市名称(必填)
  • country: 国家代码(选填,如 "CN", "US")
  • units: 温度单位(metric/imperial/kelvin)

示例

  • get_weather_by_city("Beijing")
  • get_weather_by_city("New York", "US")
  • get_weather_by_city("London", "GB", "imperial")

2. 坐标天气查询

get_weather_by_coordinates(latitude: float, longitude: float, units: str = "metric")
  • latitude: 纬度
  • longitude: 经度
  • units: 温度单位

示例

  • get_weather_by_coordinates(39.9042, 116.4074) # 北京
  • get_weather_by_coordinates(40.7128, -74.0060) # 纽约

3. 天气预报

get_weather_forecast(city: str, country: str = "", days: int = 5, units: str = "metric")
  • city: 城市名称
  • country: 国家代码(选填)
  • days: 预报天数(1-5天)
  • units: 温度单位

示例

  • get_weather_forecast("Shanghai", "CN", 3)
  • get_weather_forecast("Paris", "FR", 5, "metric")

4. 多城市天气比较

get_multiple_cities_weather(cities: List[str], units: str = "metric")
  • cities: 城市列表,支持 "城市名,国家代码" 格式
  • units: 温度单位

示例

  • get_multiple_cities_weather(["Beijing", "Shanghai", "Guangzhou"])
  • get_multiple_cities_weather(["New York,US", "London,GB", "Tokyo,JP"])

📊 返回数据格式

当前天气返回数据

{ "city": "Beijing", "country": "CN", "weather": { "main": "Clear", "description": "clear sky", "icon": "01d" }, "temperature": { "current": 25.5, "feels_like": 26.2, "min": 22.1, "max": 28.3, "unit": "°C" }, "humidity": 65, "pressure": 1013, "wind": { "speed": 3.2, "direction": 180 }, "visibility": 10000, "clouds": 20, "timestamp": 1703123456, "sunrise": 1703070000, "sunset": 1703104000 }

天气预报返回数据

{ "city": "Beijing", "country": "CN", "coordinates": { "latitude": 39.9042, "longitude": 116.4074 }, "forecast_count": 40, "forecasts": [ { "datetime": 1703123456, "weather": { "main": "Clear", "description": "clear sky", "icon": "01d" }, "temperature": { "current": 25.5, "feels_like": 26.2, "min": 22.1, "max": 28.3, "unit": "°C" }, "humidity": 65, "pressure": 1013, "wind": { "speed": 3.2, "direction": 180 }, "clouds": 20, "precipitation": 10 } ] }

📋 资源功能

1. API配置信息

get_weather_api_config()

返回天气API的配置信息和使用说明。

2. 支持的城市列表

get_supported_cities()

返回常用城市列表和使用示例。

💡 提示模板

天气查询提示

weather_query_prompt(query_type: str = "current", location: str = "", context: str = "")
  • query_type: 查询类型(current/forecast/multiple/coordinates)
  • location: 位置信息
  • context: 额外上下文

根据查询类型和语言环境生成相应的提示模板。

🌍 支持的城市

服务器支持全球任意城市的天气查询,包括但不限于:

🇨🇳 中国

  • 北京 (Beijing)
  • 上海 (Shanghai)
  • 广州 (Guangzhou)
  • 深圳 (Shenzhen)
  • 香港 (Hong Kong)

🇺🇸 美国

  • 纽约 (New York)
  • 洛杉矶 (Los Angeles)
  • 芝加哥 (Chicago)
  • 旧金山 (San Francisco)

🇬🇧 欧洲

  • 伦敦 (London)
  • 巴黎 (Paris)
  • 柏林 (Berlin)
  • 罗马 (Rome)

🇯🇵 亚洲

  • 东京 (Tokyo)
  • 首尔 (Seoul)
  • 新加坡 (Singapore)
  • 孟买 (Mumbai)

⚠️ 注意事项

  1. API密钥必填: 需要配置有效的OpenWeatherMap API密钥
  2. 请求限制: 免费账户每天限制1000次请求
  3. 网络要求: 需要稳定的网络连接访问外部API
  4. 错误处理: 所有API调用都包含错误处理和友好的错误消息

🔧 故障排除

常见问题

  1. API密钥错误
    • 检查 .env 文件中的 WEATHER_API_KEY 是否正确
    • 确认API密钥是否已激活
  2. 网络连接问题
    • 检查网络连接
    • 确认防火墙设置
  3. 城市名称无法识别
    • 尝试使用英文城市名
    • 添加国家代码,如 "Beijing,CN"
  4. 返回数据为空
    • 检查城市名称拼写
    • 确认该城市是否存在于OpenWeatherMap数据库中

📜 许可证

MIT License

🤝 贡献

欢迎提交Issue和Pull Request来改进这个项目!


MCP Factory 生成

weather-server

MCP server: weather-server

origin/main =======

weather-server

MCP server: weather-server

origin/main

Related MCP Servers

  • -
    security
    A
    license
    -
    quality
    Weather forecast server which returns 7 days of detailed weather anywhere in the world, using the OpenWeatherMap One Call API 3.0.
    Last updated -
    3
    Python
    MIT License
  • A
    security
    A
    license
    A
    quality
    Provides Swiss weather forecast data, allowing users to search for Swiss locations and get detailed hourly and daily weather forecasts.
    Last updated -
    2
    1
    JavaScript
    MIT License
  • -
    security
    F
    license
    -
    quality
    A standardized API server that enables AI agents and client applications to fetch current weather information for any location without directly interacting with external weather APIs.
    Last updated -
    Python
    • Apple
    • Linux

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/NeilJo-GY/weather-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server