Skip to main content
Glama

mcp-weather-ts

TypeScript MCP 服务器,将 National Weather Service API 中的美国天气数据提供给 Cursor 等宿主。

宿主启动 node build/index.js,并通过 stdio 以 JSON-RPC 进行通信。模型本身不会直接调用 NWS,而是调用该服务器的工具(也可以读取资源或使用提示)。

MCP 工作原理(工具、资源、提示、传输):docs/create-mcp.readme.md


环境要求

  • Node.js 22+(本仓库使用 ESM 和 fetch

  • npm

  • 可访问 https://api.weather.gov 的网络(仅限美国地区)


Related MCP server: weather

设置

npm install
npm run build

tsc 会将 JavaScript 写入 build/。Cursor 必须运行构建后的文件,而不是 src/index.ts

脚本

命令

作用

npm run build

src/ 编译到 build/

npm test

对 NWS 做冒烟测试:访问 /points,然后访问预报 URL 和逐小时预报 URL


在 Cursor 中挂载

  1. 构建(npm run build)。

  2. 在本项目中添加 .cursor/mcp.json

{
  "mcpServers": {
    "weather": {
      "type": "stdio",
      "command": "node",
      "args": ["${workspaceFolder}/build/index.js"]
    }
  }
}

对于所有 Cursor 项目,请使用 %USERPROFILE%\.cursor\mcp.json 以及 build\index.js 的完整路径,而不是 ${workspaceFolder}

  1. 打开自定义 → MCP(或 Cursor 设置 → MCP)并启用 weather

  2. 修改 src/ 后,再次运行 npm run build,并将服务器关闭再打开,以便 Cursor 重启该进程。

服务器连接后,请勿使用 console.log:stdout 是 MCP 的通信通道。日志请使用 console.error


你可以调用什么

工具

模型(或你在 Agent 聊天中提问)通过 tools/call 调用以下工具。

名称

输入

作用

get_alerts

state — 两位美国州代码(CANY

该州的生效警报

get_forecast

latitudelongitude

12 小时预报(NWS 先访问 /points,再访问 properties.forecast

test_tool

name

练习:Hello, {name}!

聊天示例:

  • “CA 有什么天气警报吗?”

  • “39.7456, -97.0892 的预报”

参数示例:

{ "state": "CA" }
{ "latitude": 39.7456, "longitude": -97.0892 }

资源

名称

URI

作用

nws_guide

weather://nws-guide

关于工具和 NWS 查询流程的简短静态说明

请让智能体读取 weather://nws-guide,或在客户端中使用 resources/read

提示

名称

参数

作用

check_weather

place — 例如 Boston MACA

用户消息模板,指示模型使用 get_forecast / get_alerts

在 Cursor 中,选择 Check weather 提示并填写 place


项目结构

src/index.ts              Create McpServer, register, connect stdio
src/tools.ts              get_alerts, get_forecast, test_tool
src/resources.ts          weather://nws-guide
src/prompts.ts            check_weather
src/weather-api-call.ts   NWS fetch + types + alert formatting
src/createTransport.ts    StdioServerTransport + connect
tests/weather-api-call.test.ts
docs/create-mcp.readme.md How to design MCP servers

src/index.ts 中的启动顺序:

  1. new McpServer({ name: "weather", version: "1.0.0" })

  2. registerWeatherTools / registerWeatherResources / registerWeatherPrompts

  3. connectStdioTransport(server)


NWS 说明

  • 预报并不位于 /points/{lat},{lon}/forecast。请先加载 /points/{lat},{lon}(保留四位小数),然后再访问 properties.forecastproperties.forecastHourly

  • NWS 要求提供 User-Agent 请求头(已在 weather-api-call.ts 中设置)。

  • 覆盖范围为美国(及部分领地)。其他坐标通常会失败。


故障排查

症状

尝试方法

服务器红色 / 没有工具

重新构建,确认 build/index.js 存在,切换 MCP 开关

握手失败

确保你已 connect stdio,且不要向 stdout 写日志

预报为空或失败

仅支持美国经纬度;查看 MCP 日志

npm test 失败

网络 / NWS 故障

Cursor:输出 → MCP 日志


许可证

ISC

Install Server
A
license - permissive license
C
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    C
    quality
    C
    maintenance
    Exposes US weather data as MCP tools, resources, and prompts via the National Weather Service API, enabling clients like Claude Desktop to get alerts, forecasts, and weather briefings.
    2
    1
  • F
    license
    Not graded
    quality
    C
    maintenance
    This MCP server provides tools to get current weather, forecasts, and weather alerts from the US National Weather Service via REST APIs, enabling AI agents to query live weather data.
    1
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables natural-language weather queries for U.S. states and coordinates, returning real-time alerts and forecasts from the National Weather Service API via MCP tools.

View all related MCP servers

Related MCP Connectors

  • US weather, alerts, earthquakes and elevation for AI agents, from NWS/NOAA and USGS. No API keys.

  • US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.

  • Get US weather forecasts, active alerts, and current observations.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kingshuknandy2016/weather-mcp-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server