weather-mcp-server-js
A remote MCP server that exposes a get_weather tool for real-time current weather queries of any city via the free wttr.in API, supporting Streamable HTTP transport.
README
🌤️ 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即可启动
📦 环境要求
- Node.js ≥ 18(内置
fetch,无需额外依赖)
🚀 快速开始
# 1. 安装依赖
npm install
# 2. 启动服务(默认端口 3000)
npm start
# 后台运行(日志写入 logs/server.log)
npm run start:bg
启动成功后,服务地址为:
http://localhost:3000/mcp
常用脚本
| 命令 | 说明 |
|---|---|
npm start |
前台启动服务 |
npm start:bg |
后台启动,日志写入 logs/server.log |
npm run dev |
开发模式,文件变更自动重启 |
npm run status |
查看 3000 端口服务是否在运行 |
npm run logs |
实时查看日志 |
npm run stop |
停止服务 |
npm run restart |
重启服务 |
npm run restart:bg |
后台重启 |
🔌 配置 MCP 客户端
在 Claude Code 或其他支持 Streamable HTTP 的 MCP 客户端中,将服务注册为远程 MCP 服务器。
Claude Code
通过 MCP 服务器列表添加(<kbd>/mcp</kbd> → 添加 → HTTP):
{
"type": "http",
"url": "http://localhost:3000/mcp"
}
JSON 配置文件方式
{
"mcpServers": {
"weather": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}
🧰 提供的工具
get_weather
获取指定城市的当前天气情况。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
city |
string | ✅ | 城市名称,例如 Beijing、Tokyo |
返回示例
当前 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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.