get_uv_forecast
Retrieve UV index forecasts for Portuguese locations to plan outdoor activities safely. Provides 3-day UV radiation levels with risk categories from low to extreme.
Instructions
Get UV index forecast for Portugal (Previsão Índice Ultravioleta até 3 dias).
Returns UV radiation index forecast for Portuguese locations.
UV Index levels:
- 0-2: Low
- 3-5: Moderate
- 6-7: High
- 8-10: Very High
- 11+: Extreme
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- weather.py:344-380 (handler)The handler function for the 'get_uv_forecast' tool. It fetches UV index forecast data from the IPMA API using the helper function make_ipma_request, formats the response or provides a fallback message if data is unavailable.@mcp.tool() async def get_uv_forecast() -> str: """Get UV index forecast for Portugal (Previsão Índice Ultravioleta até 3 dias). Returns UV radiation index forecast for Portuguese locations. UV Index levels: - 0-2: Low - 3-5: Moderate - 6-7: High - 8-10: Very High - 11+: Extreme """ uv_url = f"{IPMA_API_BASE}/forecast/meteorology/uv/uv.json" uv_data = await make_ipma_request(uv_url) if not uv_data: return """UV index forecast is currently unavailable. The IPMA API provides UV radiation index forecasts for up to 3 days. UV Index levels: - 0-2: Low (minimal protection needed) - 3-5: Moderate (protection recommended) - 6-7: High (protection essential) - 8-10: Very High (extra protection required) - 11+: Extreme (avoid sun exposure) Please try again later or check the IPMA website directly.""" # Process UV data based on actual API structure if isinstance(uv_data, dict): result = "UV Index Forecast\n\n" result += str(uv_data) else: result = "UV Index Forecast\n\n" result += str(uv_data) return result
- weather.py:12-21 (helper)Helper function used by get_uv_forecast to make HTTP requests to the IPMA API with error handling.async def make_ipma_request(url: str) -> dict[str, Any] | list[dict[str, Any]] | None: """Make a request to the IPMA API with proper error handling.""" async with httpx.AsyncClient() as client: try: response = await client.get(url, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None
- weather.py:344-344 (registration)The @mcp.tool() decorator registers the get_uv_forecast function as an MCP tool.@mcp.tool()