Uses Express.js to provide HTTP/SSE transport capabilities for remote connections
Built with pure JavaScript ES Modules for direct execution without compilation steps
Requires Node.js 18.0.0+ to run the server and access the weather data APIs
Employs Zod for parameter validation in weather data requests
Weather MCP Server (JavaScript ES Modules)
一个使用纯 JavaScript ES Modules 构建的天气 MCP 服务器,支持多种传输方式。
功能特性
- 获取美国各州的天气警报信息
- 获取指定经纬度的天气预报
- 支持 stdio 和 HTTP/SSE 两种传输方式
- 使用美国国家气象局 (NWS) API
- ✨ 纯 JavaScript - 无需编译步骤,直接运行
安装与设置
- 克隆或下载项目
- 安装依赖:
使用方式
1. stdio 传输(推荐用于本地开发)
获取当前项目绝对路径:
2. HTTP/SSE 传输(支持远程连接)
这将启动一个 HTTP 服务器在端口 8080,提供以下端点:
- SSE 端点:
http://localhost:8080/sse
- 用于建立 Server-Sent Events 连接
- 支持实时双向通信
- HTTP 端点:
http://localhost:8080/mcp
- 用于标准的 HTTP POST 请求
- 支持批量请求
可用工具
get-alerts
获取指定州的天气警报信息
参数:
state
(string): 两位州代码,如 "CA"、"NY"
示例:
get-forecast
获取指定经纬度的天气预报
参数:
latitude
(number): 纬度 (-90 到 90)longitude
(number): 经度 (-180 到 180)
示例:
客户端连接示例
使用 curl 测试 SSE 连接
运行测试客户端
MCP 客户端配置
stdio 传输配置(推荐)
如果你使用 MCP 客户端(如 Claude Desktop),需要使用绝对路径配置:
配置步骤:
- 在项目目录下运行
pwd
获取绝对路径 - 将上面配置中的路径替换为你的实际路径
- 保存配置文件并重启MCP客户端
Windows 配置示例:
HTTP/SSE 传输配置
注意: 使用HTTP传输时,需要先运行 npm run serve
启动服务器。
快速生成配置
在项目目录下运行以下命令,快速生成MCP客户端配置:
技术栈
- JavaScript ES Modules (.mjs)
- Node.js (>=18.0.0)
- MCP SDK
- Express.js (用于 HTTP/SSE 代理)
- mcp-proxy (提供 HTTP/SSE 支持)
- Zod (用于参数验证)
项目结构
开发优势
- 无编译步骤 - 直接运行,开发更快
- 简化部署 - 不需要构建过程
- 兼容性更好 - 纯JavaScript,兼容性更广
调试模式
这将启动带有调试信息的服务器。
查看日志
服务器会输出详细的连接和请求日志,帮助你调试问题。
注意事项
- NWS API 仅支持美国地区的天气数据
- HTTP/SSE 模式支持多个并发连接
- 服务器会自动处理 CORS,支持跨域请求
- 需要 Node.js 18.0.0 或更高版本
故障排除
- 端口被占用: 修改
npm run serve
命令中的端口号 - 连接失败: 确保防火墙允许相应端口的连接
- 数据获取失败: 检查网络连接和 NWS API 可用性
- 模块导入错误: 确保使用 Node.js 18+ 并且 package.json 中
"type": "module"
- MCP客户端无法启动服务器:
- 确保使用绝对路径而不是相对路径
- 检查路径中是否包含空格,如有空格需要用引号包围
- 验证 Node.js 在系统 PATH 中可用:
which node
或where node
- 测试路径是否正确:在终端中直接运行完整命令
- Windows 路径问题:
- 使用正斜杠
/
或双反斜杠\\
- 避免使用单反斜杠
\
(会被转义)
- 使用正斜杠
Related MCP Servers
- AsecurityFlicenseAqualityA Model Context Protocol server that provides AI agents with tools to retrieve weather alerts and detailed forecasts for US locations using the National Weather Service API.Last updated -280TypeScript
- -securityFlicense-qualityA lightweight microservice that fetches weather alerts and forecasts from the National Weather Service API, providing U.S. state-level alerts and location-based forecasts.Last updated -Python
- AsecurityFlicenseAqualityA Model Context Protocol server that provides tools to fetch weather alerts for US states and forecasts based on latitude/longitude coordinates using the US National Weather Service API.Last updated -280TypeScript
- -securityFlicense-qualityA standardized API server that enables AI agents and client applications to fetch current weather information for any location without directly interacting with external weather APIs.Last updated -Python