Weather MCP
A MCP server for querying real-time weather information for any city worldwide using the free Open-Meteo API, supporting CLI and integration with AI clients like Claude and Cursor.
README
Weather MCP
一个简单易用的天气查询 MCP 工具,支持 CLI 命令行和 MCP Server 两种使用方式。
功能特性
- 🌤️ 实时天气查询 - 获取全球任意城市的当前天气
- 🔧 CLI 支持 - 命令行直接查询天气
- 🤖 MCP 协议 - 支持 Claude、Cursor 等 AI 客户端
- 🌍 全球覆盖 - 支持中文、英文等多种语言城市名
- ⚡ 免费 API - 使用 Open-Meteo 免费天气服务,无需 API Key
- 📝 类型安全 - TypeScript + Zod 全面类型支持
安装
方式一:npm 全局安装(推荐)
npm install -g weather-mcp
方式二:npx 直接使用
npx weather-mcp weather 北京
方式三:源码安装
git clone https://github.com/tengzhijian/weather-mcp.git
cd weather-mcp
npm install
npm run build
CLI 使用
# 查询天气
weather-mcp weather 北京
weather-mcp weather Shanghai
# 查看帮助
weather-mcp --help
weather-mcp --version
示例输出
{
"ok": true,
"data": {
"city": "北京 (中国)",
"temperature": 22,
"humidity": 70,
"description": "多云",
"windSpeed": 9.3,
"updatedAt": "2024-01-15T08:30:00.000Z"
}
}
MCP Server 配置
Claude Desktop
编辑 %APPDATA%/Claude/settings.json(Windows)或 ~/Library/Application Support/Claude/settings.json(Mac):
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["-y", "weather-mcp", "--mcp"]
}
}
}
Cursor
在 Cursor Settings → MCP 中添加:
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["-y", "weather-mcp", "--mcp"]
}
}
}
本地开发版本
如果你从源码运行:
{
"mcpServers": {
"weather": {
"command": "node",
"args": ["/path/to/weather-mcp/dist/index.js", "--mcp"]
}
}
}
可用工具
getWeather
查询指定城市的天气信息。
参数:
city(string, 必需): 城市名称,例如:北京、上海、广州、London、Tokyo
返回:
city: 城市名称(包含国家)temperature: 温度(摄氏度)humidity: 湿度(百分比)description: 天气描述(晴朗、多云等)windSpeed: 风速(km/h)updatedAt: 数据更新时间
listSupportedCities
获取支持查询的城市列表示例。
返回:
cities: 常用城市列表示例note: 说明(实际上支持全球任何城市)
AI 客户端使用示例
配置完成后,在 Claude、Cursor 等客户端中可以直接询问:
"北京今天天气怎么样?" "上海明天会下雨吗?" "查询一下纽约的天气"
AI 会自动调用 getWeather 工具获取天气信息。
开发
# 安装依赖
npm install
# 开发模式
npm run dev weather 北京
# 运行测试
npm test
# 类型检查
npm run typecheck
# 构建
npm run build
技术栈
- TypeScript - 类型安全的 JavaScript
- MCP SDK - Model Context Protocol
- Commander.js - CLI 框架
- Zod - Schema 验证
- Vitest - 测试框架
- Open-Meteo - 免费天气 API
项目结构
weather-mcp/
├── src/
│ ├── index.ts # 入口文件
│ ├── cli.ts # CLI 命令
│ ├── mcp-server.ts # MCP Server
│ ├── weather-gateway.ts # 天气 API 封装
│ └── version.ts # 版本号
├── tests/ # 测试文件
├── .github/workflows/ # GitHub Actions
├── package.json
├── tsconfig.json
└── README.md
CI/CD
项目使用 GitHub Actions 实现自动化:
- CI: 每次 PR 和 Push 时自动运行测试(Node.js 18/20/22)
- Release: 手动触发发布到 npm
许可证
致谢
- 天气数据由 Open-Meteo 提供免费 API 支持
- 遵循 Model Context Protocol 规范
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.