get_uv_forecast
Retrieve UV index forecasts for locations in Portugal to plan outdoor activities and manage sun exposure risks.
Instructions
Obter previsão do índice UV
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.js:389-454 (handler)The primary handler function for the 'get_uv_forecast' tool. It fetches UV forecast data from the IPMA API, resolves location names, groups data by date, limits to recent dates and locations, categorizes UV levels (Baixo, Moderado, Alto, Muito Alto, Extremo), formats a markdown report, and returns it as MCP text content. Handles errors with McpError.async getUVForecast() { try { const response = await fetch(`${this.baseUrl}/forecast/meteorology/uv/uv.json`); const data = await response.json(); if (!Array.isArray(data) || data.length === 0) { return { content: [ { type: "text", text: "Não há dados de UV disponíveis no momento." } ] }; } const locationsResponse = await fetch(`${this.baseUrl}/distrits-islands.json`); const locationsData = await locationsResponse.json(); const locationMap = locationsData.data.reduce((acc, loc) => { acc[loc.globalIdLocal] = loc.local; return acc; }, {}); let result = "**Previsão do Índice UV**\n\n"; const uvByDate = {}; data.forEach((uvData) => { if (!uvByDate[uvData.data]) { uvByDate[uvData.data] = []; } uvByDate[uvData.data].push(uvData); }); Object.keys(uvByDate).slice(0, 3).forEach((date) => { result += `**${date}**\n`; uvByDate[date].slice(0, 10).forEach((uv) => { 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.js:93-96 (schema)Input schema definition for the 'get_uv_forecast' tool, specifying an object with no properties (no input parameters required).inputSchema: { type: "object", properties: {} }
- src/index.js:90-97 (registration)Registration of the 'get_uv_forecast' tool in the ListToolsRequestSchema response, including name, description, and input schema.{ name: "get_uv_forecast", description: "Obter previsão do índice UV", inputSchema: { type: "object", properties: {} } }
- src/index.js:118-119 (registration)Dispatch registration in the CallToolRequestSchema handler's switch statement, mapping the tool name to the getUVForecast method call.case "get_uv_forecast": return await this.getUVForecast();