- Weather
Weather
个基于Go语言开发的天气查询MCP(Model Context Protocol)服务器,提供实时和未来天气信息查询功能。
Content
Weather MCP Server
一个基于Go语言开发的天气查询MCP(Model Context Protocol)服务器,提供实时天气信息查询功能。
功能特性
- 🌤️ 实时天气查询
- 📍 支持城市名和坐标查询
- 🌍 多语言支持(中文)
- 🇨🇳 支持中文城市名和区级地名查询
- 🔧 基于MCP协议,易于集成
- 🏗️ 遵循领域驱动设计(DDD)原则
快速开始
1. 获取OpenWeatherMap API密钥
- 访问 OpenWeatherMap
- 注册免费账户
- 获取API密钥
2. 克隆项目
git clone <repository-url>
cd weather-mcp-server
3. 设置环境变量
export OPENWEATHER_API_KEY=your_api_key_here
项目结构
weather-mcp-server/
├── cmd/server/ # 应用入口
│ └── main.go
├── internal/ # 内部包
│ ├── domain/weather/ # 天气领域模型
│ ├── application/services/ # 应用服务
│ ├── infrastructure/ # 基础设施
│ │ ├── weather/ # 天气API客户端
│ │ └── mcp/ # MCP协议实现
│ └── interfaces/ # 接口层
├── configs/ # MCP配置文件
├── test_weather.go # 测试脚本
└── README.md
MCP工具
get_weather
获取指定位置的天气信息,支持实时天气和未来小时预报。
参数:
location(string, 必需): 位置信息,可以是城市名(如:北京、Beijing)或坐标(如:39.9042,116.4074)hours(integer, 可选): 需要查询的小时数,0或不传表示查询实时天气,1-12表示查询未来小时预报
注意: OpenWeatherMap 的预报 API 返回的是3小时间隔的数据。例如:
- 请求3小时会返回 [当前+3h, 当前+6h, 当前+9h] 的数据
- 请求6小时会返回 [当前+3h, 当前+6h] 的数据
- 请求9小时会返回 [当前+3h, 当前+6h, 当前+9h] 的数据
示例:
// 查询实时天气
{
"location": "北京"
}
// 查询未来3小时预报
{
"location": "北京",
"hours": 3
}
// 查询未来6小时预报
{
"location": "39.9600,116.3000",
"hours": 6
}
支持的城市名格式:
- 中文城市名:北京、上海、广州、深圳等
- 英文城市名:Beijing、Shanghai、Guangzhou、Shenzhen等
- 区级地名:北京海淀、上海浦东、广州天河等
- 坐标格式:39.9042,116.4074
响应示例:
📍 北京, CN
🌡️ 温度: 25.3°C (体感: 26.1°C)
💧 湿度: 65%
🌪️ 风速: 3.2 m/s (东北)
🌡️ 气压: 1013 hPa
☁️ 天气: 多云
🕐 更新时间: 2024-01-15 14:30:00
配置
服务器配置
通过环境变量进行配置:
环境变量
OPENWEATHER_API_KEY: OpenWeatherMap API密钥(必需)
MCP客户端配置
要使用天气MCP服务器,需要在MCP客户端中配置 mcp_settings.json 文件。
1. 使用go run命令(开发模式)
{
"mcpServers": {
"weather-mcp-server": {
"command": "go",
"args": [
"run",
"cmd/server/main.go"
],
"env": {
"OPENWEATHER_API_KEY": "your_openweather_api_key_here"
},
"cwd": "/path/to/weather-mcp-server"
}
}
}
2. 使用构建的二进制文件
{
"mcpServers": {
"weather-mcp-server": {
"command": "./bin/weather-mcp-server",
"args": [],
"env": {
"OPENWEATHER_API_KEY": "your_openweather_api_key_here"
},
"cwd": "/path/to/weather-mcp-server"
}
}
}
3. 使用绝对路径的二进制文件
{
"mcpServers": {
"weather-mcp-server": {
"command": "/absolute/path/to/weather-mcp-server/bin/weather-mcp-server",
"args": [],
"env": {
"OPENWEATHER_API_KEY": "your_openweather_api_key_here"
}
}
}
}
配置说明
command: 要执行的命令args: 命令行参数数组env: 环境变量对象cwd: 工作目录路径(可选)
配置文件位置
根据不同的MCP客户端,配置文件位置可能不同:
- Claude Desktop:
~/Library/Application Support/Claude/claude_desktop_config.json - Cursor:
~/.cursor/mcp_settings.json - 其他客户端: 请参考客户端文档
示例配置文件
项目提供了配置文件示例:
configs/mcp_settings.json.example- 基本配置configs/mcp_settings_relative.json.example- 相对路径配置configs/mcp_settings_go_run.json.example- Go run开发模式配置
Server Config
{
"mcpServers": {
"weather-mcp-server": {
"command": "go",
"args": [
"run",
"cmd/server/main.go"
],
"env": {
"OPENWEATHER_API_KEY": "your_openweather_api_key_here"
},
"cwd": "/path/to/weather-mcp-server"
}
}
}Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
CursorThe AI Code Editor
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Tavily Mcp
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Amap Maps高德地图官方 MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Serper MCP ServerA Serper MCP Server