mcp-weather

Andy123211/mcp-weather

3.2

If you are the rightful owner of mcp-weather and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project implements a simple MCP server using the FastMCP framework, offering functionalities like addition, personalized greetings, and city weather queries.

Tools
  1. sum

    Adds two numbers.

  2. greeting

    Returns a personalized greeting based on the provided name.

  3. get_weather

    Fetches real-time weather information using city name or adcode.

MCP 天气查询服务

本项目基于 FastMCP 框架,实现了一个简单的 MCP 服务器,支持加法、个性化问候和城市天气查询等功能。

功能简介

  • sum:两个数字相加。
  • greeting:根据名字返回个性化问候。
  • get_weather:通过城市名或 adcode 查询实时天气(高德天气API)。

依赖环境

  • Python 3.10+
  • requests
  • mcp[cli]>=1.11.0

安装依赖(推荐使用 uv): 直接安装主要依赖:

uv pip install requests mcp[cli]>=1.11.0

数据准备

请确保项目根目录下有 result.json 文件,内容为城市名与 adcode 的映射,例如:

[
  {"name": "北京市", "adcode": 110000, "citycode": "010"},
  {"name": "上海市", "adcode": 310000, "citycode": "021"}
]

高德API Key

请在 main.py 中将 amap_key 替换为你自己的高德开放平台 Web服务 Key,并确保已开通“天气查询”服务。

启动服务

python main.py

MCP 工具使用示例

1. 查询加法

sum(a=1, b=2)

2. 个性化问候

get_greeting(name="小明")

3. 查询天气

  • 通过城市名:
get_weather(city_name="北京市")
  • 通过adcode:
get_weather(adcode="110000")

其他说明

  • 支持自定义扩展更多 MCP 工具。
  • 如需批量查询天气,可自行遍历 result.json 调用 get_weather。

如有问题欢迎反馈!