Weather MCP Server
Enables real-time weather queries for global cities via natural language, with support for Chinese and English city names and optional integration with OpenWeather API.
README
Weather MCP Server
一个基于 Model Context Protocol (MCP) 的天气服务器,支持获取全球城市的实时天气信息。
🌟 功能特性
- 实时天气查询 - 获取全球任意城市的当前天气信息
- 多语言支持 - 支持中英文城市名称查询
- 优雅降级 - 无API密钥时自动提供演示数据
- 完整气象数据 - 温度、湿度、风速、气压、天气状况
- 免费API支持 - 集成OpenWeather免费API(每分钟60次调用)
🚀 快速开始
1. 安装依赖
npm install
2. 配置API密钥(可选)
# 复制环境变量模板
cp .env.example .env
# 编辑.env文件,添加您的OpenWeather API密钥
OPENWEATHER_API_KEY=your_actual_api_key_here
💡 提示: 访问 OpenWeatherMap 注册获取免费API密钥
3. 构建项目
npm run build
4. 运行服务器
# 生产模式
npm start
# 开发模式(自动构建并运行)
npm run dev
📋 使用方法
作为独立MCP服务器运行
服务器启动后通过stdio进行JSON-RPC通信:
node dist/index.js
集成到Claude Desktop
在Claude Desktop配置文件 (claude_desktop_config.json) 中添加:
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/absolute/path/to/weather-mcp-server/dist/index.js"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
}
}
}
集成到CodeBuddy Code
在CodeBuddy Code的MCP配置中添加:
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/absolute/path/to/weather-mcp-server/dist/index.js"]
}
}
}
🔧 可用工具
get_current_weather
获取指定城市的当前详细天气信息。
请求参数:
{
city: string // 城市名称(支持中英文)
}
返回数据:
{
location: string // 城市位置信息
temperature: number // 温度(摄氏度)
description: string // 天气描述
humidity: number // 湿度百分比
windSpeed: number // 风速(公里/小时)
pressure: number // 气压(百帕)
}
🎯 使用示例
示例1: 查询北京天气
用户: 北京今天天气怎么样?
助手: [调用 get_current_weather 工具,city="北京"]
🌤️ 当前北京天气:
📍 位置: 北京, CN
🌡️ 温度: 22°C
☁️ 天气: 部分多云
💧 湿度: 65%
💨 风速: 15 km/h
📊 气压: 1013 hPa
示例2: 查询纽约天气
用户: What's the weather in New York?
助手: [调用 get_current_weather 工具,city="New York"]
🌤️ Current weather in New York:
📍 Location: New York, US
🌡️ Temperature: 18°C
☁️ Conditions: clear sky
💧 Humidity: 55%
💨 Wind Speed: 12 km/h
📊 Pressure: 1015 hPa
🛠️ 开发命令
# 安装依赖
npm install
# 构建TypeScript项目
npm run build
# 开发模式(监听变化并自动构建)
npm run dev
# 运行测试
node test-mcp.js
📁 项目结构
weather-mcp-server/
├── src/
│ ├── index.ts # MCP服务器主入口
│ └── weather.ts # 天气服务核心逻辑
├── dist/ # 编译后的JavaScript文件
├── .env # 环境变量配置文件
├── .env.example # 环境变量模板
├── package.json # 项目配置和依赖
└── README.md # 项目说明文档
⚠️ 注意事项
- API限制: OpenWeather免费账户每分钟最多60次API调用
- 演示模式: 未设置API密钥时使用静态演示数据
- 城市格式: 支持中文和英文城市名称
- 错误处理: API调用失败时自动降级到演示数据
- 单位系统: 使用公制单位(摄氏度、公里/小时)
🔗 相关链接
📄 许可证
MIT License - 详见 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.
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.
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.
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
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
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.