天气数据服务

一个通过Open-Meteo API提供实时天气信息的Model Context Protocol (MCP)服务器,支持多语言、Docker部署和TypeScript严格验证。

  • by aaudeon
  • TypeScript
  • 本地部署
  • 更新于

使用说明

MCP天气服务器

模型上下文协议(MCP)服务器,通过开放气象API提供实时天气信息。

✨ 功能

  • 🌤️ 当前天气 按城市名称或联系方式
  • 📅 预测 最多7天
  • 🌍 支持多语言 (法语、英语、西班牙语、德语等)
  • 🆓 API酬金 Open Meteo(无需钥匙)
  • 🐳 为Docker做好准备 具有优化的生产配置
  • 📊 TypeScript严格 通过参数验证

🚀 安装和快速启动

Prérequis

  • Node.js 18+
  • Docker和Docker Compose(可选)

方法1:本地启动

# Installation des dépendances
npm install

# Construction
npm run build

# Démarrage
npm start

方法2:Docker(建议用于生产)

# Déploiement automatique
chmod +x deploy.sh
./deploy.sh

📋 MCP工具可用

get_weather

获取城市的当前天气。

{
  "city": "Paris",
  "countryCode": "FR",
  "lang": "fr"
}

get_weather_forecast

获取天气预报(1-7天)。

{
  "city": "London",
  "days": 5,
  "lang": "en"
}

get_weather_by_coordinates

通过GPS坐标获取天气。

{
  "latitude": 48.8566,
  "longitude": 2.3522,
  "lang": "fr"
}

⚙️ 配置

科皮亚兹 .env.example 朝向 .env 并根据需要进行调整:

# Port du serveur (optionnel)
MCP_SERVER_PORT=3000

# Langue par défaut
DEFAULT_LANGUAGE=fr

# Environnement
NODE_ENV=production

🛠️ 发展

# Mode développement avec rechargement automatique
npm run dev

# Vérification du code
npm run lint
npm run typecheck

# Formatage du code
npm run format

📦 项目结构

src/
├── index.ts              # Point d'entrée principal
├── services/
│   └── weatherService.ts # Service API Open-Meteo
├── utils/
│   ├── formatter.ts      # Formatage des réponses
│   └── validation.ts     # Validation des paramètres
├── types/
│   └── weather.ts        # Types TypeScript
└── constants/
    └── weather.ts        # Constantes et configurations

🐳 使用Docker制作

该项目包括一个优化的Docker配置,包括:

  • 为轻量级图像构建多阶段
  • 用于安全的非root用户
  • 集成HealthChecks
  • 结构化日志
# Construction manuelle
docker build -t mcp-weather-server .

# Ou via docker-compose
docker-compose up -d

🔧 MCP集成

此服务器与所有MCP客户端兼容。Claude桌面使用示例:

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/chemin/vers/dist/index.js"]
    }
  }
}

📄 许可证

MIT-有关详细信息,请参阅许可证文件。


开发与❤️ 在TypeScript中