Weathernode 翻译成中文是“天气节点”
一个可投入生产的天气服务,通过REST API和MCP(模型上下文协议)端点提供实时天气数据。
特点/特性
- 双协议支持REST API和MCP终端点
- 天气数据使用WeatherAPI.com获取当前天气及预报信息
- 准备就绪,可投入生产Docker,Kubernetes,Helm图表
- 安全速率限制、输入验证、跨域资源共享(CORS)
- 监测健康检查和指标
- TypeScript全面的类型安全与现代开发
快速入门
先决条件
- Node.js 18及以上版本
- WeatherAPI.com(可译为“天气API网站”或保持原样作为专有名词) API密钥(免费套餐:每月100万次调用)
安装
# Clone repository
git clone https://github.com/Philip-Walsh/weathernode.git
cd weathernode
# Install dependencies
npm install
# Set up environment
cp .env.example .env
# Add your WeatherAPI.com key to .env
# Start development server
npm run dev服务器运行于: http://localhost:3000
API终端点
REST API
# Current weather
GET /api/weather?city=London
# Weather forecast
GET /api/forecast?city=London&days=5
# Default location weather
GET /api/local
# Health check
GET /api/healthMCP协议
# List available tools
POST /mcp
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}
# Get weather data
POST /mcp
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": {"city": "London"}
}
}发展
npm run dev # Development server with hot reload
npm run build # Build for production
npm run start # Start production server
npm test # Run test suite
npm run lint # Lint code部署
Docker
# Build image
docker build -t weathernode .
# Run container
docker run -p 3000:3000 \
-e WEATHER_API_KEY=your_key_here \
weathernodeKubernetes(中文常译为“K8s”)
# Create secret
kubectl create secret generic weather-api-key \
--from-literal=api-key=your_weatherapi_key_here
# Deploy with Helm
helm install weather-service ./helm/weather-service \
--set env.WEATHER_API_KEY=your_key_here文档
- API 参考 - 完整的API文档
- 部署指南 - 生产环境部署
- WeatherAPI 设置 - 天气数据源设置
环境变量
WEATHER_API_KEY=your_weatherapi_key_here # Required
DEFAULT_LOCATION=London # Optional
TEMP_UNIT=C # Optional
PORT=3000 # Optional
NODE_ENV=development # Optional许可证
麻省理工学院(MIT)
