Skip to main content
Glama

get_weather_forecast

Retrieve 7-day weather forecasts for any global location using the Open-Meteo API, with Sydney as the default city. Specify city, country, and forecast duration (1-7 days) for accurate planning.

Instructions

Récupère les prévisions météo sur 7 jours (Sydney par défaut)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityNoNom de la ville (optionnel, Sydney par défaut)Sydney
countryNoCode pays optionnel
daysNoNombre de jours de prévision (1-7)

Implementation Reference

  • The primary handler function for the get_weather_forecast tool. It geocodes the city (using helper), fetches daily forecast data from Open-Meteo API, formats it into a structured text response with temperatures, conditions, wind, sunrise/sunset for each day.
    async getWeatherForecast(city, country, days) { 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}&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,precipitation_sum,rain_sum,showers_sum,snowfall_sum,precipitation_hours,wind_speed_10m_max,wind_gusts_10m_max,wind_direction_10m_dominant&timezone=auto&forecast_days=${days}`; const response = await fetch(url); const data = await response.json(); if (!response.ok) { throw new Error('Erreur lors de la récupération des prévisions'); } const daily = data.daily; let forecastText = `🗓️ Prévisions météo ${days} jours pour ${location.name || location.admin1}${location.country ? `, ${location.country}` : ''}\n\n`; for (let i = 0; i < days; i++) { const date = new Date(daily.time[i]); const dayName = date.toLocaleDateString('fr-FR', { weekday: 'long' }); const dateStr = date.toLocaleDateString('fr-FR'); const weatherDesc = this.getWeatherDescription(daily.weather_code[i]); const windDir = this.getWindDirection(daily.wind_direction_10m_dominant[i]); forecastText += `📅 **${dayName.charAt(0).toUpperCase() + dayName.slice(1)} ${dateStr}**\n`; forecastText += `🌡️ ${Math.round(daily.temperature_2m_min[i])}°C → ${Math.round(daily.temperature_2m_max[i])}°C\n`; forecastText += `🤔 Ressenti: ${Math.round(daily.apparent_temperature_min[i])}°C → ${Math.round(daily.apparent_temperature_max[i])}°C\n`; forecastText += `☁️ ${weatherDesc}\n`; forecastText += `🌬️ Vent: ${Math.round(daily.wind_speed_10m_max[i])} km/h ${windDir}\n`; if (daily.precipitation_sum[i] > 0) { forecastText += `🌧️ Précipitations: ${daily.precipitation_sum[i]}mm\n`; } forecastText += `🌅 Lever: ${new Date(daily.sunrise[i]).toLocaleTimeString('fr-FR', {hour: '2-digit', minute: '2-digit'})}\n`; forecastText += `🌇 Coucher: ${new Date(daily.sunset[i]).toLocaleTimeString('fr-FR', {hour: '2-digit', minute: '2-digit'})}\n\n`; } return { content: [ { type: 'text', text: forecastText.trim(), }, ], }; }
  • Tool schema definition in the ListTools response, specifying name, description, and input schema with optional parameters city, country, and days.
    { name: 'get_weather_forecast', description: 'Récupère les prévisions météo sur 7 jours (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', }, days: { type: 'number', description: 'Nombre de jours de prévision (1-7)', default: 7, minimum: 1, maximum: 7 } }, required: [], }, },
  • src/index.js:149-150 (registration)
    Registration in the CallToolRequestSchema switch statement that dispatches to the getWeatherForecast handler with default parameters.
    case 'get_weather_forecast': return await this.getWeatherForecast(args.city || 'Sydney', args.country, args.days || 7);
  • Helper function used by the handler to resolve city/country to latitude/longitude coordinates via Open-Meteo geocoding API.
    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]; }
  • Helper utility to translate weather codes to human-readable French descriptions, used in forecast formatting.
    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'; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Yarflam/weather-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server