get_current_weather
Retrieve current weather conditions for any city worldwide, with Sydney as the default location, using global weather data from the Open-Meteo API.
Instructions
Récupère la météo actuelle pour une ville (Sydney par défaut)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | No | Nom de la ville (optionnel, Sydney par défaut) | Sydney |
| country | No | Code pays optionnel (ex: AU, FR, US) |
Implementation Reference
- src/index.js:192-238 (handler)The main handler function that fetches current weather data for a specified city (default Sydney) using Open-Meteo APIs, formats and returns the response.async getCurrentWeather(city, country) { let location; if (city.toLowerCase() === 'sydney' && !country) { location = DEFAULT_LOCATION; } else { location = await this.getCoordinates(city, country); } const url = `${WEATHER_API}?latitude=${location.latitude}&longitude=${location.longitude}¤t=temperature_2m,relative_humidity_2m,apparent_temperature,is_day,precipitation,rain,showers,snowfall,weather_code,cloud_cover,pressure_msl,surface_pressure,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timezone=auto`; const response = await fetch(url); const data = await response.json(); if (!response.ok) { throw new Error('Erreur lors de la récupération de la météo'); } const current = data.current; const weatherDesc = this.getWeatherDescription(current.weather_code); const windDir = this.getWindDirection(current.wind_direction_10m); return { content: [ { type: 'text', text: `🌤️ Météo actuelle à ${location.name || location.admin1 || 'Localisation'}${location.country ? `, ${location.country}` : ''} 📍 **Localisation:** ${location.latitude}°, ${location.longitude}° 🌡️ **Température:** ${Math.round(current.temperature_2m)}°C 🤔 **Ressenti:** ${Math.round(current.apparent_temperature)}°C ☁️ **Conditions:** ${weatherDesc} ${current.is_day ? '☀️' : '🌙'} 💧 **Humidité:** ${current.relative_humidity_2m}% 🌬️ **Vent:** ${Math.round(current.wind_speed_10m)} km/h ${windDir} 💨 **Rafales:** ${Math.round(current.wind_gusts_10m)} km/h 🔽 **Pression:** ${Math.round(current.pressure_msl)} hPa ☁️ **Couverture nuageuse:** ${current.cloud_cover}% ${current.precipitation > 0 ? `🌧️ **Précipitations:** ${current.precipitation} mm` : ''} ${current.rain > 0 ? `🌧️ **Pluie:** ${current.rain} mm` : ''} ${current.snowfall > 0 ? `❄️ **Neige:** ${current.snowfall} cm` : ''} ⏰ **Dernière mise à jour:** ${new Date(current.time).toLocaleString('fr-FR')}`, }, ], }; }
- src/index.js:51-69 (registration)Registration of the 'get_current_weather' tool in the ListTools response, including name, description, and input schema.{ name: 'get_current_weather', description: 'Récupère la météo actuelle pour une ville (Sydney par défaut)', inputSchema: { type: 'object', properties: { city: { type: 'string', description: 'Nom de la ville (optionnel, Sydney par défaut)', default: 'Sydney' }, country: { type: 'string', description: 'Code pays optionnel (ex: AU, FR, US)', } }, required: [], }, },
- src/index.js:146-147 (registration)Dispatcher case in CallToolRequestSchema handler that routes calls to the getCurrentWeather method.case 'get_current_weather': return await this.getCurrentWeather(args.city || 'Sydney', args.country);
- src/index.js:178-190 (helper)Helper function to resolve city name to coordinates using geocoding API, used by getCurrentWeather.async getCoordinates(city, country) { const query = country ? `${city}, ${country}` : city; const url = `${GEOCODING_API}?name=${encodeURIComponent(query)}&count=1&language=fr&format=json`; const response = await fetch(url); const data = await response.json(); if (!response.ok || !data.results || data.results.length === 0) { throw new Error(`Ville "${query}" non trouvée`); } return data.results[0]; }
- src/index.js:395-428 (helper)Helper to translate weather codes to human-readable descriptions.getWeatherDescription(code) { const descriptions = { 0: 'Ciel dégagé', 1: 'Principalement dégagé', 2: 'Partiellement nuageux', 3: 'Couvert', 45: 'Brouillard', 48: 'Brouillard givrant', 51: 'Bruine légère', 53: 'Bruine modérée', 55: 'Bruine dense', 56: 'Bruine verglaçante légère', 57: 'Bruine verglaçante dense', 61: 'Pluie légère', 63: 'Pluie modérée', 65: 'Pluie forte', 66: 'Pluie verglaçante légère', 67: 'Pluie verglaçante forte', 71: 'Neige légère', 73: 'Neige modérée', 75: 'Neige forte', 77: 'Grains de neige', 80: 'Averses légères', 81: 'Averses modérées', 82: 'Averses violentes', 85: 'Averses de neige légères', 86: 'Averses de neige fortes', 95: 'Orage', 96: 'Orage avec grêle légère', 99: 'Orage avec grêle forte' }; return descriptions[code] || 'Conditions inconnues'; }