天气数据服务

一个基于国家气象局API提供天气数据和警报的模型上下文协议服务器。

  • by arjones
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 arjones/weather-mcp

使用说明

气象MCP服务器

模型上下文协议(MCP)服务器,使用美国国家气象局(NWS)API提供天气数据。源 MCP/面向服务器开发人员/快速入门

特性

  • 天气警报:获取美国任何州的活跃天气警报
  • 天气预报:获取特定坐标的详细天气预报
  • 美国覆盖范围:全面覆盖美国领土

项目结构

src/
├── index.ts      # MCP server configuration and main entry point
├── types.ts      # TypeScript interfaces and type definitions
├── api.ts        # NWS API client and request handling
└── forecast.ts   # Business logic for alerts and forecast processing

架构概述

  • index.ts:MCP服务器设置、工具注册和主要功能
  • types.ts:所有TypeScript接口(AlertFeature, ForecastPeriod等等)
  • api.ts:用于NWS API的HTTP客户端,带有错误处理
  • forecast.ts:格式化和处理天气数据的核心业务逻辑

设置

  1. 安装依赖项:

    npm install
    
  2. 构建项目:

    npm run build
    

可用工具

get_alerts

获取美国某个州的天气警报。

参数:

  • state (string):两个字母的州代码(例如“CA”、“NY”)

例子:

{
  "state": "CA"
}

get_forecast

获取特定坐标的天气预报。

参数:

  • latitude (数字):纬度(-90到90)
  • longitude (数字):经度(-180到180)

例子:

{
  "latitude": 37.7749,
  "longitude": -122.4194
}

使用MCP检查器进行调试

MCP检查器是调试和测试MCP服务器的强大工具。

安装

直接与npx一起使用:

npx @modelcontextprotocol/inspector node build/index.js

用法

连接到您的服务器:

  • 服务器类型: stdio
  • 命令: node
  • 论据: build/index.js
  • 点击 连接