get_uv_forecast
Get UV index forecasts for Portugal to plan outdoor activities safely and monitor sun exposure risks using data from IPMA weather services.
Instructions
Obter previsão do índice UV
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:499-566 (handler)The core handler function that fetches UV forecast data from the IPMA API, maps global IDs to location names, groups data by date, categorizes UV levels, and formats a markdown response.private async getUVForecast() { try { const response = await fetch(`${this.baseUrl}/forecast/meteorology/uv/uv.json`); const data = await response.json() as UVData[]; if (!Array.isArray(data) || data.length === 0) { return { content: [ { type: "text", text: "☀️ Não há dados de UV disponíveis no momento." } ] }; } // Obter locais para mapear globalIdLocal para nomes const locationsResponse = await fetch(`${this.baseUrl}/distrits-islands.json`); const locationsData = await locationsResponse.json() as ApiResponse<Location>; const locationMap = locationsData.data.reduce((acc: any, loc: Location) => { acc[loc.globalIdLocal] = loc.local; return acc; }, {}); let result = "☀️ **Previsão do Índice UV**\n\n"; // Agrupar por data const uvByDate: { [key: string]: UVData[] } = {}; data.forEach((uvData: UVData) => { if (!uvByDate[uvData.data]) { uvByDate[uvData.data] = []; } uvByDate[uvData.data].push(uvData); }); Object.keys(uvByDate).slice(0, 3).forEach((date: string) => { result += `📅 **${date}**\n`; uvByDate[date].slice(0, 10).forEach((uv: UVData) => { const locationName = locationMap[uv.globalIdLocal] || `Local ${uv.globalIdLocal}`; const uvLevel = parseFloat(uv.iUv); let uvCategory = ""; if (uvLevel <= 2) uvCategory = "Baixo 🟢"; else if (uvLevel <= 5) uvCategory = "Moderado 🟡"; else if (uvLevel <= 7) uvCategory = "Alto 🟠"; else if (uvLevel <= 10) uvCategory = "Muito Alto 🔴"; else uvCategory = "Extremo 🟣"; result += `• ${locationName}: UV ${uv.iUv} (${uvCategory}) - ${uv.intervaloHora}\n`; }); result += "\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 UV: ${errorMessage}`); } }
- src/index.ts:189-196 (registration)Tool registration definition in the ListTools handler, specifying name, description, and empty input schema.{ name: "get_uv_forecast", description: "Obter previsão do índice UV", inputSchema: { type: "object", properties: {} } }
- src/index.ts:219-220 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to the getUVForecast method.case "get_uv_forecast": return await this.getUVForecast();
- src/index.ts:192-195 (schema)Input schema for the get_uv_forecast tool, which requires no parameters.inputSchema: { type: "object", properties: {} }
- src/index.ts:87-92 (helper)TypeScript interface defining the structure of UV forecast data returned from the IPMA API.interface UVData { data: string; globalIdLocal: number; iUv: string; intervaloHora: string; }