天气数据服务

Weathernode 是一个生产就绪的天气服务,通过 REST API 和 MCP 端点提供实时天气数据和预报。

  • by Philip-Walsh
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 Philip-Walsh/weathernode

使用说明

Weathernode 翻译成中文是“天气节点”

一个可投入生产的天气服务,通过REST API和MCP(模型上下文协议)端点提供实时天气数据。

特点/特性

  • 双协议支持REST API和MCP终端点
  • 天气数据使用WeatherAPI.com获取当前天气及预报信息
  • 准备就绪,可投入生产Docker,Kubernetes,Helm图表
  • 安全速率限制、输入验证、跨域资源共享(CORS)
  • 监测健康检查和指标
  • TypeScript全面的类型安全与现代开发

快速入门

先决条件

安装

# 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/health

MCP协议

# 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 \
  weathernode

Kubernetes(中文常译为“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

文档

环境变量

WEATHER_API_KEY=your_weatherapi_key_here  # Required
DEFAULT_LOCATION=London                   # Optional
TEMP_UNIT=C                              # Optional
PORT=3000                                # Optional
NODE_ENV=development                     # Optional

许可证

麻省理工学院(MIT)