Skip to main content
Glama
gitPratikSingh

Weather MCP Server

get_weather_forecast

Retrieve multi-day weather forecasts for any location to plan activities and prepare for upcoming conditions.

Instructions

Get weather forecast for a specific location for multiple days

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesCity name or location (e.g., 'New York', 'London')
daysNoNumber of days to forecast (1-5)

Implementation Reference

  • main.py:99-113 (handler)
    MCP tool handler dispatch: validates input, calls WeatherAPI.get_forecast, returns JSON-formatted forecast data.
    elif name == "get_weather_forecast":
        location = arguments.get("location", "")
        days = arguments.get("days", 5)
        
        if not location:
            return [TextContent(
                type="text",
                text="Error: location parameter is required"
            )]
        
        forecast_data = await weather_api.get_forecast(location, days)
        return [TextContent(
            type="text",
            text=json.dumps(forecast_data, indent=2)
        )]
  • main.py:44-64 (registration)
    Tool registration in list_tools(): defines name, description, and input schema.
    Tool(
        name="get_weather_forecast",
        description="Get weather forecast for a specific location for multiple days",
        inputSchema={
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City name or location (e.g., 'New York', 'London')"
                },
                "days": {
                    "type": "integer",
                    "description": "Number of days to forecast (1-5)",
                    "minimum": 1,
                    "maximum": 5,
                    "default": 5
                }
            },
            "required": ["location"]
        }
    ),
  • main.py:47-63 (schema)
    Input schema defining parameters: location (required string), days (optional integer 1-5, default 5).
    inputSchema={
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City name or location (e.g., 'New York', 'London')"
            },
            "days": {
                "type": "integer",
                "description": "Number of days to forecast (1-5)",
                "minimum": 1,
                "maximum": 5,
                "default": 5
            }
        },
        "required": ["location"]
    }
  • WeatherAPI.get_forecast: core logic with caching, OpenWeatherMap API call (or mock), data processing and formatting into structured forecast.
    async def get_forecast(self, location: str, days: int = 5) -> Dict:
        """
        Get weather forecast for a location.
        
        Args:
            location: City name or location string
            days: Number of days to forecast (1-5)
            
        Returns:
            Dictionary with forecast data
        """
        location = self._normalize_location(location)
        days = max(1, min(5, days))  # Clamp between 1 and 5
        
        # Check cache
        cache_key = f"forecast_{location}_{days}"
        cached = self._get_from_cache(cache_key)
        if cached:
            return cached
        
        # If no API key, return mock data
        if not self.api_key:
            return self._get_mock_forecast(location, days)
        
        try:
            async with httpx.AsyncClient() as client:
                url = f"{self.base_url}/forecast"
                params = {
                    "q": location,
                    "appid": self.api_key,
                    "units": "metric",
                    "cnt": days * 8  # 8 forecasts per day (3-hour intervals)
                }
                response = await client.get(url, params=params, timeout=10.0)
                response.raise_for_status()
                data = response.json()
                
                # Format the response
                forecasts = []
                for item in data.get("list", [])[:days * 8]:
                    forecasts.append({
                        "datetime": item.get("dt_txt", ""),
                        "temperature": item.get("main", {}).get("temp", 0),
                        "feels_like": item.get("main", {}).get("feels_like", 0),
                        "humidity": item.get("main", {}).get("humidity", 0),
                        "pressure": item.get("main", {}).get("pressure", 0),
                        "description": item.get("weather", [{}])[0].get("description", ""),
                        "wind_speed": item.get("wind", {}).get("speed", 0),
                        "clouds": item.get("clouds", {}).get("all", 0),
                    })
                
                result = {
                    "location": data.get("city", {}).get("name", location),
                    "country": data.get("city", {}).get("country", ""),
                    "forecasts": forecasts,
                    "days": days,
                    "timestamp": datetime.now().isoformat()
                }
                
                self._cache_data(cache_key, result)
                return result
                
        except httpx.HTTPError as e:
            # Fallback to mock data on API error
            return self._get_mock_forecast(location, days)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but doesn't describe behavioral traits such as rate limits, authentication needs, error handling, or what the forecast includes (e.g., temperature, precipitation). This is a significant gap for a tool with no annotation coverage.

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 a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part of the sentence contributes to understanding the tool's function, making it appropriately sized and well-structured.

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

Completeness2/5

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

Given the complexity of a weather forecasting tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the forecast returns (e.g., data format, units), potential limitations, or how it differs from siblings, leaving gaps for effective agent use.

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

Parameters3/5

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

The schema description coverage is 100%, with clear documentation for both parameters ('location' and 'days'), including constraints like the 1-5 range for 'days'. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('weather forecast') with specific scope ('for a specific location for multiple days'), making the purpose evident. However, it doesn't explicitly distinguish from sibling tools like 'get_current_weather' (which likely provides current conditions rather than forecasts) or 'search_locations' (which might find locations rather than provide weather data).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_current_weather' or 'search_locations'. It lacks context about prerequisites, exclusions, or comparative use cases, leaving the agent to infer usage based on tool names alone.

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/gitPratikSingh/weather_mcp_server'

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