Skip to main content
Glama

get_weather_forecast

Retrieve weather forecasts for cities in Portugal using IPMA meteorological data. Specify a city and number of days (up to 10) to get detailed weather predictions.

Instructions

Obter previsão meteorológica para uma cidade específica em Portugal

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesNome da cidade (ex: Lisboa, Porto, Coimbra, Faro, etc.)
daysNoNúmero de dias de previsão (máximo 10)

Implementation Reference

  • The primary handler function for the get_weather_forecast tool. It searches for the city in IPMA locations, fetches forecast data, maps weather types, limits to specified days, formats a detailed text report, and returns it as MCP content. Handles errors appropriately.
    async getWeatherForecast(city, days) { try { const locationsResponse = await fetch(`${this.baseUrl}/distrits-islands.json`); const locationsData = await locationsResponse.json(); const location = locationsData.data.find((loc) => loc.local.toLowerCase().includes(city.toLowerCase()) ); if (!location) { return { content: [ { type: "text", text: `Cidade "${city}" não encontrada. Use get_locations para ver cidades disponíveis.` } ] }; } const forecastResponse = await fetch( `${this.baseUrl}/forecast/meteorology/cities/daily/${location.globalIdLocal}.json` ); const forecastData = await forecastResponse.json(); const weatherTypesResponse = await fetch(`${this.baseUrl}/weather-type-classe.json`); const weatherTypesData = await weatherTypesResponse.json(); const weatherTypes = weatherTypesData.data.reduce((acc, item) => { acc[item.idWeatherType] = item; return acc; }, {}); const limitedData = forecastData.data.slice(0, days); let result = `**Previsão para ${location.local}**\n\n`; result += `Coordenadas: ${location.latitude}, ${location.longitude}\n`; result += `Última atualização: ${forecastData.dataUpdate}\n\n`; limitedData.forEach((day) => { const weatherDesc = weatherTypes[day.idWeatherType]?.descWeatherTypePT || "Desconhecido"; result += `**${day.forecastDate}**\n`; result += `Temperatura: ${day.tMin}°C - ${day.tMax}°C\n`; result += `Condições: ${weatherDesc}\n`; result += `Probabilidade de precipitação: ${day.precipitaProb}%\n`; result += `Vento: ${day.predWindDir}\n\n`; }); return { content: [ { type: "text", text: result } ] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Erro ao obter previsão: ${errorMessage}`); } }
  • Input schema for get_weather_forecast tool defining required 'city' string parameter and optional 'days' number (default 5).
    inputSchema: { type: "object", properties: { city: { type: "string", description: "Nome da cidade (ex: Lisboa, Porto, Coimbra, Faro, etc.)" }, days: { type: "number", description: "Número de dias de previsão (máximo 10)", default: 5 } }, required: ["city"] }
  • src/index.js:33-51 (registration)
    Registration of the get_weather_forecast tool in the ListToolsRequestSchema response, including name, description, and input schema.
    { name: "get_weather_forecast", description: "Obter previsão meteorológica para uma cidade específica em Portugal", inputSchema: { type: "object", properties: { city: { type: "string", description: "Nome da cidade (ex: Lisboa, Porto, Coimbra, Faro, etc.)" }, days: { type: "number", description: "Número de dias de previsão (máximo 10)", default: 5 } }, required: ["city"] } },
  • src/index.js:105-109 (registration)
    Tool dispatcher case in CallToolRequestSchema handler that validates input and calls the getWeatherForecast method.
    case "get_weather_forecast": if (!args?.city) { throw new McpError(ErrorCode.InvalidParams, "City parameter is required"); } return await this.getWeatherForecast(args.city, args.days || 5);

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/brandao-20/mcp_server_ipma'

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