Skip to main content

中国城市天气查询 MCP 服务

基于高德地图 API 的中国城市天气查询 Model Context Protocol (MCP) 服务。该服务允许用户通过简单的请求获取中国各城市的实时天气状况和未来几天的天气预报。

功能特点

  • 使用高德地图天气 API 获取精确的中国城市天气数据
  • 支持查询实时天气状况
  • 支持查询未来 3-4 天的天气预报
  • 支持智能城市名称识别,包括城市、区县级别的查询
  • 支持城市名称搜索功能
  • 实现为标准 MCP 服务,易于集成到 AI 应用中

安装说明

前提条件

  • 高德地图开发者 API 密钥(需通过环境变量配置)

安装步骤

  1. 克隆或下载本仓库
  2. 进入项目目录
  3. 使用 uv 安装依赖:
uv venv
source .venv/bin/activate
uv add "mcp[cli]" httpx

使用方法

启动 MCP 服务

如果你需要自行创建客户端测试该 MCP 服务,请手动启动。 在终端中执行以下命令启动 MCP 服务:

uv run weather.py

使用集成的 MCP 服务

在 Claude Desktop 中使用

如果想在 Claude Desktop 中使用,请添加服务器配置: 请在文本编辑器中打开 Claude for Desktop App 配置,路径参考如下 ~/Library/Application Support/Claude/claude_desktop_config.json 如果文件不存在,请确保创建该文件。

{
    "mcpServers": {
        "amap-weather-mcp-server": {
            "command": "uv",
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
                "run",
                "weather.py"
            ],
            "env": {
                "AMAP_API_KEY": "YOUR_API_KEY_HERE"
            }
        }
    }
}

在 Cherry Studio 中使用

如下图所示配置即可: in-cherrystudio

调用服务

MCP 服务提供了三个主要工具函数用于天气查询:

  1. get_current_weather: 获取城市当前天气状况
  2. get_weather_forecast: 获取未来几天的天气预报
  3. search_city: 搜索城市名称

使用 MCP 客户端调用示例:

from mcp.client import Client

# 连接到服务
client = Client("amap-weather-mcp-server")

# 查询实时天气
current_weather = await client.get_current_weather("北京市")
print(current_weather)

# 查询天气预报
forecast = await client.get_weather_forecast("上海市")
print(forecast)

# 搜索城市名称
cities = await client.search_city("广州")
print(cities)

API 参考

get_current_weather

获取指定城市的实时天气数据。

参数:

  • city: 中国城市名称,需要包含省/市/县等行政区划标识,如"北京市"、"上海市"、"海珠区"等

返回: 格式化的城市实时天气信息字符串,包括:

  • 城市名称
  • 天气状况
  • 温度
  • 风向
  • 风力
  • 湿度
  • 发布时间

get_weather_forecast

获取指定城市的天气预报(未来3-4天)。

参数:

  • city: 中国城市名称,需要包含省/市/县等行政区划标识,如"北京市"、"上海市"、"浙江省杭州市"等

返回: 格式化的城市天气预报信息字符串,包括:

  • 城市名称
  • 未来几天的日期
  • 白天和夜间天气状况
  • 白天和夜间温度
  • 白天和夜间风向、风力

search_city

根据关键词搜索匹配的城市名称。

参数:

  • keyword: 城市名称关键词,建议包含省/市/县等行政区划标识,如"广州市"、"海珠区"等

返回: 包含匹配城市名称列表的字符串。

数据来源

本服务使用高德地图开放平台提供的天气数据 API:

注意事项

  • 该服务仅支持中国大陆地区的城市天气查询
  • 高德地图 API 可能有请求频率限制
  • 城市名称识别支持直接输入城市名称或区县名称(建议带上行政区划标识如"市"、"县"、"区"等)
  • 环境变量必须正确配置,否则API请求将失败

许可证

MIT 许可证

Metadata

Release files for amapote-moni-mcp-server 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amapote-moni-mcp-server 0.1.0
File Size Uploaded Provenance
amapote_moni_mcp_server-0.1.0.tar.gz 7.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for amapote-moni-mcp-server 0.1.0
File Interpreter ABI Platform
amapote_moni_mcp_server-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / amapote_moni_mcp_server-0.1.0.tar.gz

Download URL amapote_moni_mcp_server-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ea703cd1793f5421336d730afa196cf63ca02eab16cec978877a1f4c5ed8c7d0
BLAKE2b-256 checksum
How to use checksums
62c5292e6f6ebe5332319d49c9d6aa5421eff666837103aa45ea6aa744c6f429
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / amapote_moni_mcp_server-0.1.0-py3-none-any.whl

Download URL amapote_moni_mcp_server-0.1.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
048b07c9df1639a8a7abb1b3d674fb8a18f27a2b0fdf220f5d9ba916bc07a30b
BLAKE2b-256 checksum
How to use checksums
93f0ee4c9b289c4644261e7ea6b44e9cd726acf6d0dd36814e018934e21a0198
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for amapote-moni-mcp-server 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page