weather-mcp

weather-mcp
TypeScript MCP 服务器,提供由 OpenWeatherMap 支持的天气工具。
工具
工具 | 描述 |
| 按城市名称或经纬度获取当前天气 |
| 按经纬度获取 5 天 / 3 小时预报 |
传输方式
模式 | 环境变量 | 适用场景 |
|
| 本地 Cursor / Claude Desktop |
Streamable HTTP |
| 部署(Render 等)/ 远程 URL |
MCP 官方文档:https://modelcontextprotocol.io/docs/
远程在线服务(Render)
部署在 Render 的免费套餐上:
基础 URL | |
MCP 端点 | |
健康检查 |
Cursor 配置(远程)
将其添加到 设置 → MCP 或 ~/.cursor/mcp.json:
{
"mcpServers": {
"weather": {
"url": "https://weather-mcp-ts.onrender.com/mcp"
}
}
}Cursor 中无需本地构建或 API 密钥——密钥存放在 Render 的环境变量中。
Render 免费套餐: 服务在无活动 ~15 分钟后关闭。下一个请求是冷启动,MCP 可能需要最多 ~50 秒才能响应。如果 Cursor 工具看起来卡在唤醒状态,请访问一次
/health。
Related MCP server: mcp-weatherapi
前提条件(仅本地)
Node.js 20+
pnpm(或 npm/yarn)
OpenWeatherMap API 密钥(在此获取)
本地设置
pnpm install
cp .env.example .env编辑 .env 并设置你的密钥:
OPEN_WEATHER_MAP_API_KEY=your_key_here
TRANSPORT=stdio构建服务器:
pnpm run build这会将可运行的入口文件写入 dist/index.js。
添加到 Cursor(本地 stdio)
Cursor 默认不会从项目根目录启动此进程来加载环境变量,因此请通过 Node 的 --env-file 标志传入绝对路径的环境文件。
打开 Cursor 设置 → MCP,或编辑
~/.cursor/mcp.json。在
mcpServers下添加一个weather条目:
{
"mcpServers": {
"weather": {
"command": "node",
"args": [
"--env-file",
"/ABSOLUTE/PATH/TO/weather-mcp/.env",
"/ABSOLUTE/PATH/TO/weather-mcp/dist/index.js"
]
}
}
}将 /ABSOLUTE/PATH/TO/weather-mcp 替换为你的真实项目路径(例如在仓库根目录运行 pwd)。在 .env 中保留 TRANSPORT=stdio(或不设置)。
替代方案:内联环境变量
{
"mcpServers": {
"weather": {
"command": "node",
"args": [
"/ABSOLUTE/PATH/TO/weather-mcp/dist/index.js"
],
"env": {
"OPEN_WEATHER_MAP_API_KEY": "your_key_here",
"TRANSPORT": "stdio"
}
}
}
}建议使用 .env + --env-file,这样密钥不会出现在 mcp.json 中。
保存后,在 设置 → MCP 中关闭/重新打开服务器(或重启 Cursor)。
确认服务器显示为已连接,并列出
get_current_weather和get_forecast。
代码更改后
pnpm run build然后在 Cursor 中重新加载 MCP 服务器。
Streamable HTTP(本地)
HTTP 模式在 POST/GET /mcp(可配置)提供 MCP 服务,并额外提供 GET /health。Streamable HTTP 通过官方 SDK 的 createMcpHandler + toNodeHandler 进行配置。
pnpm run build
TRANSPORT=http PORT=3000 pnpm run start
# or
pnpm run start:http你应该会看到类似这样的输出:
Weather MCP Server running on http://0.0.0.0:3000/mcp (Streamable HTTP)在 Render 上部署
从此仓库(项目根目录)创建一个 Web Service。
构建:
pnpm install && pnpm run build(或等效的npm命令)。启动:
node dist/index.js(或pnpm run start)。环境变量:
TRANSPORT=httpOPEN_WEATHER_MAP_API_KEY=...PORT由 Render 自动设置
MCP URL:
https://<your-service>.onrender.com/mcp
此部署:https://weather-mcp-ts.onrender.com/mcp
HTTP 端点未经过身份验证。任何拥有该 URL 的人都可以调用这些工具。在广泛分享之前请添加身份验证。
手动冒烟测试(OpenWeatherMap)
在设置好 .env 后:
node --env-file=.env -e "
import { getApiKey, buildCurrentWeatherUrl, makeOWMRequest, formatCurrentWeather } from './dist/utils.js';
const apiKey = getApiKey();
const data = await makeOWMRequest(buildCurrentWeatherUrl({ apiKey, city: 'Yaounde,CM', units: 'metric' }));
console.log(data ? formatCurrentWeather(data, 'metric') : 'failed');
"远程健康检查:
curl -s https://weather-mcp-ts.onrender.com/health仓库结构
weather-mcp/
├── README.md
├── package.json
├── tsconfig.json
├── .env.example
└── src/
├── index.ts # stdio + Streamable HTTP entry
├── server.ts # tool registration
├── types.ts
└── utils.ts注意事项
切勿提交
.env(它已被 gitignore)。Stdio 服务器不得向 stdout 写入除 MCP JSON-RPC 之外的任何内容;日志应写入 stderr(
console.error)。OpenWeatherMap 的免费套餐涵盖当前天气以及此处使用的 5 天 / 3 小时预报。
许可证
ISC
This server cannot be deployed
Maintenance
Related MCP Connectors
OpenWeather MCP — wraps the OpenWeatherMap API (openweathermap.org)
Hosted MCP server for Xweather weather data: conditions, forecasts, alerts, and more.
Weather MCP — wraps Open-Meteo API (free, no auth)
MCP server for weather with reasoning — umbrella advice, outdoor checks, city comparisons.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceWraps the OpenWeatherMap API to provide weather data through MCP, enabling AI agents to query current conditions, forecasts, and other weather information via natural language.20 npmMIT
- AlicenseNot gradedqualityBmaintenanceProvides weather data from WeatherAPI.com through MCP, enabling AI agents to query current conditions and forecasts via natural language.9 npmMIT
- FlicenseNot gradedqualityDmaintenanceEnables MCP clients like Kiro and Claude to access current weather conditions and forecasts for any location using the OpenWeatherMap API.-
- AlicenseNot gradedqualityDmaintenanceIntegrates OpenWeatherMap API with MCP to provide weather data, forecasts, air quality, maps, alerts, and geocoding via natural language.11 npmMIT