weather-mcp-server-js
🌤️ Weather MCP Server (Node.js)
基于 Node.js / Express 实现的远程 MCP (Model Context Protocol) 服务器。
通过 Streamable HTTP transport 暴露 get_weather 工具,让 Claude Code 等 MCP 客户端可以实时查询任意城市的当前天气。
天气数据来自 wttr.in —— 免费、无需注册、无需 API key。
✨ 功能特性
🛰️ 远程 MCP 服务:基于官方
@modelcontextprotocol/sdk实现 Streamable HTTP 传输,支持 JSON 与 SSE 两种响应模式🌆 全球城市支持:直接传城市名(如
Beijing、Tokyo、Paris)即可查询当地天气🔌 完整会话管理:自动生成/校验
Mcp-Session-Id,支持会话的建立、复用与关闭(DELETE)🧩 单文件即用:无需数据库,零配置文件,一个
server.js即可启动
Related MCP server: MCP Weather Server — Demo
📦 环境要求
Node.js ≥ 18(内置
fetch,无需额外依赖)
🚀 快速开始
# 1. 安装依赖
npm install
# 2. 启动服务(默认端口 3000)
npm start
# 后台运行(日志写入 logs/server.log)
npm run start:bg启动成功后,服务地址为:
http://localhost:3000/mcp常用脚本
命令 | 说明 |
| 前台启动服务 |
| 后台启动,日志写入 |
| 开发模式,文件变更自动重启 |
| 查看 3000 端口服务是否在运行 |
| 实时查看日志 |
| 停止服务 |
| 重启服务 |
| 后台重启 |
🔌 配置 MCP 客户端
在 Claude Code 或其他支持 Streamable HTTP 的 MCP 客户端中,将服务注册为远程 MCP 服务器。
Claude Code
通过 MCP 服务器列表添加(/mcp → 添加 → HTTP):
{
"type": "http",
"url": "http://localhost:3000/mcp"
}JSON 配置文件方式
{
"mcpServers": {
"weather": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}🧰 提供的工具
get_weather
获取指定城市的当前天气情况。
参数
参数 | 类型 | 必填 | 说明 |
| string | ✅ | 城市名称,例如 |
返回示例
当前 Beijing 的天气是晴(Sunny),温度 28°C(体感 30°C),湿度 45%,风速 12 km/h。⚙️ 实现说明
会话隔离:每个会话持有独立的
Server+transport实例(SDK 的connect()只支持一个 transport),通过Mcp-Session-Id请求头关联。新会话流程:不带
Mcp-Session-Id的 POST 视为初始化请求,服务器生成会话 ID 并通过Mcp-Session-Id响应头返回(通过 CORS 的exposedHeaders显式暴露给浏览器客户端)。兼容性处理:无会话 ID 的 GET SSE 探测请求会保持一个打开的 SSE 流(而非返回 404/400),让 Claude Code 等客户端可以继续走 POST 初始化流程。
可靠的错误返回:天气 API 调用失败时返回
isError: true的结果而非让整个请求崩溃。
🗂️ 项目结构
.
├── server.js # 全部服务逻辑(单文件)
├── package.json # 项目配置与脚本
├── logs/ # 运行时日志(已被 .gitignore 忽略)
└── LICENSE # MIT 许可证📄 License
This server cannot be installed
Maintenance
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
- FlicenseBqualityDmaintenanceA simple MCP server that provides a tool to fetch current weather information for cities using the Open-Meteo API, communicating through stdin/stdout.12
- Alicense-qualityDmaintenanceDemo MCP server that provides weather data for cities, with tools to get weather and list available cities.MIT
- AlicenseAqualityBmaintenanceMCP server that provides current weather for any city using Open-Meteo APIs. It exposes a single tool 'get_weather' returning temperature, humidity, wind, and other weather data.113MIT
- AlicenseAqualityBmaintenanceA simple MCP server that exposes a get_weather tool to fetch real-time weather for any GPS coordinates using the Open-Meteo API, no API key required.114ISC
Related MCP Connectors
AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.
MCP server exposing the Backtest360 engine API as tools for AI agents.
Remote ChromaDB vector database MCP server with streamable HTTP transport
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/yuxiaosenstar/weather-mcp-server-js'
If you have feedback or need assistance with the MCP directory API, please join our Discord server