🇮🇳 印度天气MCP服务器
一个全面的模型上下文协议(MCP)服务器,为印度城市提供详细的天气信息、空气质量数据以及农业见解。该服务器采用TypeScript构建,并由Open-Meteo API提供支持。
✨ 特点/功能
🌤️ 天气预报
- 当前天气实时温度、风速及状况
- 每小时预报12小时详细天气预报
- 每日预报5天天气预报,含最低/最高气温
- 空气质量指数(AQI)PM2.5、PM10和美国空气质量指数(AQI)读数
📊 历史天气分析
- 历史数据最多30天的历史天气信息
- 趋势分析将当前状况与历史平均水平进行比较
- 天气模式识别温度和降水趋势
🏙️ 多城市对比
- 城市比较同时比较印度2-5个城市之间的天气
- 极端天气检测找出最热、最冷和风最大的地点
- 温度范围计算城市间的温差
🏥 健康与舒适指数
- 热指数根据温度和湿度计算得出
- 紫外线指数含安全等级的防晒建议
- 舒适度水平个性化舒适度评估
- 健康建议基于天气的健康建议
🚜 农业气象智能
- 土壤湿度指数基于近期的降雨量和温度
- 生长度日(Growing Degree Days,简称GDD)对于水稻、小麦和棉花作物
- 季风状况当前季节识别
- 农业建议针对特定作物的天气建议
🛠️ 安装
先决条件
- Node.js 18及以上版本
- npm 或 yarn
- TypeScript(用于开发)
设置
# Clone the repository
git clone https://github.com/yourusername/Indian-Weather-MCP-Server.git
cd Indian-Weather-MCP-Server.git
# Install dependencies
npm install
# Build the project
npm run build🚀 使用方法
独立服务器使用
直接服务器执行
# Start the MCP server directly
node build/index.js服务器将启动并监听通过标准输入输出(stdio)接收的MCP协议消息。这在以下方面很有用:
- 与MCP兼容应用程序的集成
- 直接协议通信
- 仅服务器部署
服务器输出
🇮🇳 Indian Weather MCP Server running with AQI, Hourly Forecast, Historical Data, Multi-City Comparison, Health Indexes & Agricultural Weather客户端-服务器使用
交互式客户端模式
# Navigate to client directory
cd client
# Start the interactive client
npm start自动化测试模式
# Navigate to client directory
cd client
# Run automated tests
npm test客户端功能
- 实时天气查询交互式命令行界面
- 自动化测试所有工具的综合测试套件
- 错误处理优雅的错误处理和报告
- 性能监控响应时间测量
🛠️ 可用工具
1. 天气预报
get_forecast_india(city: string)示例获取孟买的当前天气和天气预报
- 当前温度、风速及状况
- 12小时逐小时预报
- 5天逐日天气预报
- 空气质量信息
2. 历史天气
get_historical_weather_india(city: string, days?: number)示例获取德里7天的历史天气数据
- 历史温度、降水量和风力数据
- 与当前状况的比较
- 趋势分析与平均值
3. 城市比较
compare_weather_india(cities: string[])示例比较孟买、德里和班加罗尔的天气
- 并排天气对比
- 极端天气识别
- 温度范围分析
4. 健康与舒适
get_health_comfort_india(city: string)示例获取针对钦奈的健康建议
- 热指数计算
- 紫外线指数及防护建议
- 空气质量对健康的影响
- 个性化的舒适度水平
5. 农业气象
get_agricultural_weather_india(city: string, cropType?: string)示例获取旁遮普邦水稻作物种植建议
- 土壤湿度评估
- 主要作物的生长度日
- 季节性农业建议
- 针对特定作物的天气建议
🎯 使用场景
场景1:独立服务器集成
# Start server for MCP-compatible applications
node build/index.js用例:
- 与Claude桌面版的集成
- 定制化的MCP应用程序
- 仅服务器部署
- API网关实现
场景2:交互式开发与测试
# Start interactive client for development
cd client
npm start
# Available commands:
forecast Mumbai
historical Delhi 14
compare Mumbai,Delhi,Bangalore
health Chennai
agricultural Punjab rice场景3:自动化测试与验证
# Run comprehensive test suite
cd client
npm test测试覆盖率:
- 全部5种天气工具
- 错误处理验证
- 性能基准测试
- 响应格式验证
场景4:生产部署
# Build and deploy server
npm run build
node build/index.js
# Or use as system service
pm2 start build/index.js --name weather-mcp🏗️ 建筑学
项目结构
├── src/ # Source code
│ ├── config/
│ │ └── constants.ts # API endpoints and thresholds
│ ├── services/
│ │ ├── geocoding.ts # City coordinate lookup
│ │ ├── weather-api.ts # Weather data fetching
│ │ └── weather-processor.ts # Data processing and formatting
│ ├── tools/
│ │ ├── forecast-tool.ts # Weather forecasting
│ │ ├── historical-tool.ts # Historical analysis
│ │ ├── comparison-tool.ts # Multi-city comparison
│ │ ├── health-tool.ts # Health and comfort
│ │ └── agricultural-tool.ts # Agricultural insights
│ ├── types/
│ │ └── weather.ts # TypeScript interfaces
│ ├── utils/
│ │ └── calculations.ts # Weather calculations
│ └── index.ts # Main server file
├── client/ # MCP Client
│ ├── index.js # Interactive client
│ ├── test-client.js # Automated test suite
│ ├── package.json # Client dependencies
│ └── README.md # Client documentation
├── build/ # Compiled JavaScript
├── package.json # Server dependencies
└── README.md # This documentation数据来源
- Open-Meteo(可译为“开放气象”或根据具体语境译为“开放气象服务”等)天气预报和历史数据
- Open-Meteo 空气质量空气质量与污染数据
- Nominatim印度城市地理编码
🔧 配置
环境变量
无需API密钥——使用免费的Open-Meteo API。
定制化
编辑 src/config/constants.ts 待修改:
- API终端点
- 空气质量指数(AQI)阈值
- 紫外线指数等级
- 作物基础温度
- 季风季节的定义
📊 API 接口
该服务器集成了多个Open-Meteo终端点:
- 天气预报:
https://api.open-meteo.com/v1/forecast - 历史数据:
https://archive-api.open-meteo.com/v1/archive - 空气质量:
https://air-quality-api.open-meteo.com/v1/air-quality - 地理编码:
https://nominatim.openstreetmap.org/search
🧮 天气计算
热指数
使用美国国家气象局的公式,根据温度和湿度计算热指数。
生长积温(Growing Degree Days,简称GDD)
针对不同作物进行计算:
- Rice 翻译成中文是“大米”基准温度10°C
- 小麦基准温度0°C
- 棉花基准温度15°C
土壤湿度指数
根据近期降雨量和平均气温来评估土壤湿度水平。
🌍 支持的城市
所有印度主要城市都通过Nominatim地理编码系统提供支持:
- 孟买、德里、班加罗尔、钦奈、加尔各答
- 海得拉巴、浦那、艾哈迈达巴德、斋浦尔、苏拉特
- 还有很多其他的。。。
🔧 开发
快速入门
# Clone and setup
git clone https://github.com/yourusername/Indian-Weather-MCP-Server.git
cd Indian-Weather-MCP-Server
npm install
npm run build
# Test the server
cd client
npm install
npm test开发工作流程
# 1. Make changes to TypeScript files in src/
# 2. Build the project
npm run build
# 3. Test with client
cd client
npm start
# 4. Run automated tests
npm test客户开发
# Interactive development
cd client
npm run dev # Auto-restart on changes
# Test specific scenarios
node test-client.js🤝 贡献(或:参与贡献)
- 为该仓库创建分支(或“克隆该仓库”)
- 创建一个特性分支(
git checkout -b feature/amazing-feature) - 进行更改并测试它们:
npm run build
cd client && npm test- 提交您的更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 提交拉取请求
📝 许可证
这个项目采用ISC许可证授权——详见 许可证 文件中包含详细信息。
🙏 致谢
- Open-Meteo(可译为“开放气象”或根据具体语境译为“开放天气服务”) 为提供免费天气API
- Nominatim 用于地理编码服务
- 模型上下文协议 对于MCP框架
📞 支持
寻求帮助
- GitHub Issues(GitHub问题)创建一个关于错误或功能请求的问题
- 文档检查主README文件和客户端README文件
- 代码示例审查客户端实现以了解使用模式
常见问题
服务器无法启动
# Ensure project is built
npm run build
# Check if build directory exists
ls build/客户端连接失败
# Ensure server is built first
cd .. && npm run build && cd client
# Test server directly
node ../build/index.jsAPI错误
- 检查网络连接
- 验证Open-Meteo API的可访问性
- 确保Nominatim地理编码服务可用
性能优化技巧
- 服务器运行高效,内存占用极少
- 客户优化以实现快速响应时间
- 缓存考虑在生产环境中实现响应缓存
______________________________________________________________________
倾注爱心打造,专为印度天气智能服务
