Back to MCP directory
publicPublicdnsLocal runtime

weather-mcp

一个基于美国国家气象局(NWS)公开API的MCP服务器,提供美国各州的实时天气警报和指定经纬度坐标的短期天气预报功能。

article

README

🚀 天气MCP服务器

这是一个MCP服务器,具备以下功能:

  • 根据美国双字母州代码提供美国国家气象局(NWS)的实时警报。
  • 根据经纬度坐标提供短期点位预报(未来5个时段)。

数据来源于美国国家气象局的公共API:https://api.weather.gov 。

✨ 主要特性

本服务器提供了两个实用工具,具体信息如下: | 工具 | 描述 | 输入参数 | |------|-------------|--------| | get_alerts | 获取美国某州的实时NWS警报 | state(字符串,双字母代码) | | get_forecast | 获取指定坐标的短期预报(未来5个时段) | latitude(数字), longitude(数字) |

📦 安装指南

安装依赖

pip install .

运行MCP服务器(标准输入输出传输)

python -m weather.weather

你的MCP客户端应配置为通过包入口点或上述模块路径来启动服务器。

💻 使用示例

基础用法

可参考上述安装和运行步骤在本地启动服务器,然后使用提供的工具获取天气信息。例如,使用 get_alerts 工具获取某个州的实时警报:

# 假设已经正确导入相关模块和工具
result = get_alerts(state="CA")  # 获取加利福尼亚州的实时警报
print(result)

高级用法

可根据实际需求,结合不同的输入参数,灵活使用 get_alertsget_forecast 工具。例如,获取特定经纬度的短期预报:

# 假设已经正确导入相关模块和工具
latitude = 34.0522
longitude = -118.2437
result = get_forecast(latitude=latitude, longitude=longitude)
print(result)

📚 详细文档

服务器JSON摘要

有关注册表元数据(包括名称、版本、工具和入口点配置),请参阅 server.json

发布步骤概述

  1. 使用发布者进行身份验证(GitHub命名空间)
mcp-publisher login github
  1. 创建并将仓库推送到GitHub(具体步骤见下文)
  2. (可选)如果作为包分发,发布到PyPI
  3. 发布到MCP注册表
mcp-publisher publish
  1. 验证
curl "https://registry.modelcontextprotocol.io/v0/servers?search=io.github.vtiwari/weather-mcp"

创建并推送GitHub仓库

如果该目录还不是一个git仓库

git init
git add .
git commit -m "Initial commit: Weather MCP server"

使用GitHub CLI创建并推送仓库

gh repo create vtiwari/weather-mcp --public --source . --remote origin --push

如果不使用GitHub CLI

手动通过GitHub网页界面创建仓库,然后执行以下命令:

git remote add origin https://github.com/vtiwari/weather-mcp.git
git branch -M main
git push -u origin main

为版本发布打标签以保持一致性

git tag v0.1.0
git push origin v0.1.0

PyPI打包(可选)

若要通过PyPI进行分发,需确保 pyproject.toml 包含构建后端和元数据(作者、许可证)。然后执行以下命令:

pip install build twine
python -m build
twine upload dist/*

📄 许可证

本项目采用MIT许可证(如有不同请自行调整)。

⚠️ 重要提示

此服务器使用美国国家海洋和大气管理局(NOAA)/国家气象局(NWS)的公共端点。请遵守API使用指南和速率限制。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client