Skip to main content
Glama

get_forecast

Retrieve 5-day weather forecasts for Portuguese cities, including temperature, precipitation, wind, and weather conditions.

Instructions

Get 5-day weather forecast for a Portuguese city (Previsão Meteorológica até 5 dias).

Args:
    city_name: Name of the Portuguese city (e.g. Lisboa, Porto, Faro, Aveiro, Braga)

Returns detailed 5-day forecast including temperature, precipitation, wind, and weather type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
city_nameYes

Implementation Reference

  • The handler function for the 'get_forecast' tool. It is registered via the @mcp.tool() decorator. Takes a city_name parameter, fetches city ID from IPMA API, then retrieves and formats the 5-day weather forecast including temperatures, precipitation, wind, etc.
    @mcp.tool()
    async def get_forecast(city_name: str) -> str:
        """Get 5-day weather forecast for a Portuguese city (Previsão Meteorológica até 5 dias).
    
        Args:
            city_name: Name of the Portuguese city (e.g. Lisboa, Porto, Faro, Aveiro, Braga)
        
        Returns detailed 5-day forecast including temperature, precipitation, wind, and weather type.
        """
        # First, get the global ID for the city
        cities_url = f"{IPMA_API_BASE}/distrits-islands.json"
        cities_data = await make_ipma_request(cities_url)
    
        if not cities_data or "data" not in cities_data:
            return "Unable to fetch city database."
    
        # Search for the best match
        city_name_lower = city_name.lower()
        best_match = None
        
        for entry in cities_data["data"]:
            local_name = entry.get("local", "").lower()
            if city_name_lower in local_name or local_name in city_name_lower:
                best_match = entry
                break
        
        if not best_match:
            # Return available cities if no match found
            available_cities = [entry.get("local", "") for entry in cities_data["data"][:15]]
            return f"City '{city_name}' not found. Some available cities: {', '.join(available_cities)}"
        
        # Get the forecast using the global ID
        global_id = best_match.get("globalIdLocal")
        forecast_url = f"{IPMA_API_BASE}/forecast/meteorology/cities/daily/{global_id}.json"
        forecast_data = await make_ipma_request(forecast_url)
    
        if not forecast_data or "data" not in forecast_data:
            return "Unable to fetch forecast data for this location."
    
        # Format the forecast data
        city_info = f"5-Day Weather Forecast for {best_match.get('local')}\n"
        city_info += f"Location: {best_match.get('latitude')}°N, {best_match.get('longitude')}°E\n\n"
        
        forecasts = []
        for day in forecast_data["data"][:5]:  # Show next 5 days
            forecast = f"""Date: {day.get('forecastDate', 'Unknown')}
    Max Temperature: {day.get('tMax', 'N/A')}°C
    Min Temperature: {day.get('tMin', 'N/A')}°C
    Precipitation Probability: {day.get('precipitaProb', 'N/A')}%
    Weather Type ID: {day.get('idWeatherType', 'N/A')}
    Wind Direction: {day.get('predWindDir', 'N/A')}
    Wind Speed Class: {day.get('classWindSpeed', 'N/A')}
    Precipitation Intensity Class: {day.get('classPrecInt', 'N/A')}
    """
            forecasts.append(forecast)
    
        return city_info + "---\n".join(forecasts)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses the 5-day time horizon and forecast components (temperature, precipitation, wind, weather type), which are useful behavioral traits. However, it doesn't mention rate limits, authentication needs, data freshness, or error conditions. The description adds some value but leaves significant behavioral aspects undocumented.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement, parameter documentation, and return value description in just three sentences. Every sentence adds value: the first states what the tool does, the second documents the single parameter with examples, and the third describes the output. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description provides adequate basic information about purpose and parameters but lacks details about return format structure, error handling, or behavioral constraints. For a weather forecasting tool with no structured metadata, the description should ideally include more about data sources, update frequency, or validation rules to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and only 1 parameter, the description provides essential semantic context: it explains city_name must be a Portuguese city name and gives concrete examples (Lisboa, Porto, Faro, Aveiro, Braga). This compensates well for the schema's lack of description, though it doesn't specify format constraints like case sensitivity or special characters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get 5-day weather forecast'), resource ('for a Portuguese city'), and scope ('detailed 5-day forecast including temperature, precipitation, wind, and weather type'). It distinguishes from siblings like get_fire_risk or get_sea_forecast by focusing on comprehensive 5-day weather forecasts rather than specialized data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for Portuguese cities with the example list, but doesn't explicitly state when to use this tool versus alternatives like get_daily_aggregate_forecast or get_weather_warnings. The Portuguese city constraint is mentioned, but no guidance on exclusions or specific scenarios where this tool is preferred over siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/gabriel20vieira/ipma-mcp-server'

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