这是一个基于 Model Context Protocol (MCP) 的天气服务器,借助和风天气和心知天气 API 来提供天气数据。它支持故障转移功能,还能优先获取最快响应,为用户提供高效、稳定的天气信息服务。
本服务器使用和风天气和心知天气 API 提供天气数据,支持故障转移和优先获取最快响应。以下是使用该服务器的基本步骤:
# 克隆仓库
git clone
cd weather-mcp-server
# 安装依赖
npm install
# 配置环境变量
cp .env.example .env
# 编辑 .env 文件,添加你的API密钥
# 构建项目
npm run build
# 监视模式(自动重新构建)
npm run watch
npm start
本服务器仅支持 Model Context Protocol (MCP) 模式运行,不提供 HTTP 服务器功能。MCP 是一种专为大型语言模型设计的协议,允许模型与外部工具和资源进行交互。
weather://{city} - 获取指定城市的当前天气。getCurrentWeather - 获取指定城市的当前天气。getForecast - 获取指定城市的天气预报(支持 1 - 7 天)。编辑 Claude Desktop 配置文件:
// macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
// Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["你的完整路径/weather-mcp-server/build/index.js"],
"env": {
"QWEATHER_API_KEY": "你的和风天气API密钥",
"SENIVERSE_API_KEY": "你的心知天气API密钥"
}
}
}
}
查看 MCP 的日志:
# macOS
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
npx @modelcontextprotocol/inspector node 你的完整路径/weather-mcp-server/build/index.js
然后在浏览器中访问 http://localhost:5173。
此服务器同时使用多个天气 API 源:
欢迎提交问题和拉取请求!请参考 贡献指南 了解如何参与。
MIT License