Weather MCP Server

Weather MCP Server

Enables weather queries using Baidu Maps API, providing real-time weather conditions, 5-day forecasts, hourly predictions, lifestyle indices, and weather alerts. Supports queries by administrative district codes or coordinates with multiple coordinate systems.

Category
Visit Server

README

天气查询MCP服务器

基于百度地图API提供天气查询功能的MCP(Model Context Protocol)工具。

服务配置

{
  "mcpServers": {
    "weather-mcp": {
      "command": "python",
      "args": ["-m", "weather_mcp.server"]
    }
  }
}

环境变量配置: 请在系统环境变量中设置:

BAIDU_AK=your_baidu_ak_here

功能特性

  • 🌤️ 实时天气查询 - 获取当前天气状况、温度、湿度、风向等信息
  • 📅 天气预报 - 提供未来5天的详细天气预报
  • 📊 生活指数 - 包含晨练、洗车、感冒、紫外线、穿衣、运动等生活指数
  • ⚠️ 气象预警 - 实时获取气象预警信息
  • 逐小时预报 - 24小时逐小时天气预报
  • 🗺️ 多种查询方式 - 支持行政区划代码和经纬度坐标查询

安装依赖

pip install -r requirements.txt

配置

设置系统环境变量:

Windows

set BAIDU_AK=your_baidu_ak_here

Linux/macOS

export BAIDU_AK=your_baidu_ak_here

或者在系统环境变量中永久设置 BAIDU_AK

获取百度地图API密钥

  1. 访问 百度地图开放平台
  2. 注册并登录账号
  3. 创建应用并获取AK(API Key)
  4. 确保开通天气服务权限

使用方法

启动MCP服务器

python server.py

工具说明

get_weather

获取指定地区的天气信息,支持多种数据类型和查询方式。

参数:

  • district_id (可选): 区县的行政区划编码,例如:'110101'(北京东城区)
  • location (可选): 经纬度坐标,格式:'经度,纬度',例如:'116.404,39.915'
  • data_type (可选): 请求数据类型
    • now: 实时天气
    • fc: 天气预报
    • index: 生活指数
    • alert: 气象预警
    • fc_hour: 逐小时预报
    • all: 所有数据(默认)
  • coordtype (可选): 坐标类型,仅在使用location时有效
    • wgs84: WGS84坐标系(默认)
    • bd09ll: 百度经纬度坐标系
    • bd09mc: 百度墨卡托坐标系
    • gcj02: 国测局坐标系

注意: district_idlocation 必须提供其中一个。

使用示例

1. 使用行政区划代码查询北京东城区天气

{
  "name": "get_weather",
  "arguments": {
    "district_id": "110101",
    "data_type": "all"
  }
}

2. 使用经纬度查询天安门广场天气

{
  "name": "get_weather",
  "arguments": {
    "location": "116.404,39.915",
    "data_type": "all",
    "coordtype": "wgs84"
  }
}

3. 只查询实时天气

{
  "name": "get_weather",
  "arguments": {
    "district_id": "110101",
    "data_type": "now"
  }
}

测试

测试百度地图API连接

python test_baidu_api.py

测试MCP服务器功能

python test_mcp_server.py

项目结构

weather_query/
├── server.py              # MCP服务器主文件
├── requirements.txt        # Python依赖
├── .env                   # 环境变量配置
├── .env.example          # 环境变量模板
├── test_baidu_api.py     # API测试脚本
├── test_mcp_server.py    # MCP服务器测试脚本
├── pyproject.toml        # 项目配置
├── setup.py              # 安装脚本
├── __init__.py           # 包初始化文件
└── README.md             # 项目说明文档

常见问题

Q: 如何获取行政区划代码?

A: 行政区划代码是中国标准的区县编码。常见的代码包括:

  • 110101: 北京市东城区
  • 110102: 北京市西城区
  • 310101: 上海市黄浦区
  • 440101: 广州市荔湾区

您可以通过百度地图API的其他接口或相关文档获取完整的行政区划代码列表。

Q: 支持哪些坐标系?

A: 支持以下坐标系:

  • WGS84: 国际标准坐标系
  • BD09LL: 百度经纬度坐标系
  • BD09MC: 百度墨卡托坐标系
  • GCJ02: 国测局坐标系(火星坐标系)

Q: API调用频率限制?

A: 请参考百度地图开放平台的API调用频率限制说明。建议合理使用API,避免频繁调用。

MCP服务配置

本地使用配置

{
  "mcpServers": {
    "weather-mcp": {
      "command": "python",
      "args": ["-m", "weather_mcp.server"]
    }
  }
}

托管部署配置

{
  "mcpServers": {
    "weather-mcp": {
      "command": "python",
      "args": ["-m", "weather_mcp.server"]
    }
  }
}

注意:使用前请确保已在系统环境变量中设置 BAIDU_AK

许可证

MIT License

贡献

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured