Back to MCP directory
publicPublicdnsLocal runtime

weather

一个基于国家气象局API的天气MCP服务器,提供美国各州天气警报和具体位置天气预报功能。

article

README

🚀 天气 MCP 服务器

这是一个借助国家气象局 API 来提供天气信息的 Model Context Protocol (MCP) 服务器。它能有效满足获取美国天气相关信息的需求,为用户提供便利。

🚀 快速开始

先决条件

  • Python 3.12 或更高版本
  • uv 包管理器

安装步骤

  1. 创建并激活虚拟环境:
uv venv
source .venv/bin/activate  # 在 Unix/macOS 上
# 或者
.venv\Scripts\activate     # 在 Windows 上
  1. 安装依赖项:
uv pip install -e .

运行服务器

uv run weather-server

✨ 主要特性

  • 获取美国州的天气警报
  • 获取特定位置的详细天气预报

💻 使用示例

基础用法

该服务器提供两个工具:

  1. get_alerts(state): 获取某个美国州的天气警报

    • 示例:get_alerts("CA") 获取加利福尼亚州的警报信息
  2. get_forecast(latitude, longitude): 根据经纬度获取天气预报

    • 示例:get_forecast(38.5816, -121.4944) 获取萨克拉门托(CA)的预报信息

📚 详细文档

配置方法

要在 Claude for Desktop 中使用此服务器:

  1. 打开 ~/Library/Application Support/Claude/claude_desktop_config.json 文件
  2. 添加以下配置:
{
    "mcpServers": {
        "weather": {
            "command": "/Users/zhihaoouyang/.local/bin/uv",
            "args": [
                "--directory",
                "/Users/zhihaoouyang/Desktop/code/weather",
                "run",
                "weather-server"
            ]
        }
    }
}
  1. 重启 Claude for Desktop

🔧 技术细节

项目结构

weather/
├── mcp-server/           # MCP 服务器实现
│   └── weather.py       # 主程序代码
├── pyproject.toml       # 项目配置和依赖
└── README.md            # 本文件

⚠️ 重要提示

此服务器使用国家气象局 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