Skip to main content
Glama
CodeByWaqas

Weather MCP Server

by CodeByWaqas

weather

Get current weather data for any city including temperature, humidity, wind speed, and sunrise/sunset times.

Instructions

It fetches the latest weather reports for the given city. Args: city (str): The city name for which weather reports are required. Returns: dict: The weather reports for the given city.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes

Implementation Reference

  • The main handler function for the 'weather' tool. It calls Fetch_weather_info to get the data and returns it as JSON string. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def weather(city: str):
        """ It fetches the latest weather reports for the given city. 
        Args:
            city (str): The city name for which weather reports are required.
        Returns:
            dict: The weather reports for the given city.
        """
    
        weather_data = await Fetch_weather_info(city)
        if weather_data:
            return json.dumps(weather_data)
        return None
  • Helper function that performs the actual API call to OpenWeatherMap to fetch weather data for the given city and formats the response.
    async def Fetch_weather_info(city: str):
        """ It pulls the latest weather reports from the OpenWeatherMap API. """
    
        url = f"{SITE}?q={city}&appid={API_KEY}&units=metric"
        print("Hello from weather-mcp-server!")
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, headers={"User-Agent": USER_AGENT})
                response.raise_for_status()
                weather_data = response.json()
                
                if weather_data:
                    return {
                        "city": weather_data["name"],
                        "country": weather_data["sys"]["country"],
                        "temperature": weather_data["main"]["temp"],
                        "description": weather_data["weather"][0]["description"],
                        "humidity": weather_data["main"]["humidity"],
                        "wind_speed": weather_data["wind"]["speed"],
                        "sunrise": weather_data["sys"]["sunrise"],
                        "sunset": weather_data["sys"]["sunset"],
                    }
                return None
            except httpx.HTTPError as e:
                print(f"Error fetching weather data: {e}")
                return None
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool fetches 'latest' reports, implying real-time or recent data, but doesn't disclose behavioral traits like rate limits, error handling, data sources, or whether it's read-only. For a tool with no annotations, this leaves significant gaps in understanding its operation.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded, with the purpose stated first. The Args and Returns sections are structured but could be more integrated. It avoids unnecessary details, though the formatting with quotes and line breaks is slightly awkward.

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 no annotations, no output schema, and low parameter semantics coverage, the description is incomplete. It lacks information on return format details (beyond 'dict'), error cases, or operational constraints. For a tool fetching external data, this leaves the agent with insufficient context to use it effectively.

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 description adds minimal semantics beyond the input schema. It explains that 'city' is 'The city name for which weather reports are required,' which clarifies the parameter's purpose but doesn't provide format details (e.g., city name conventions) or examples. With 0% schema description coverage and 1 parameter, the baseline is 4, but the description only partially compensates, so a 3 is appropriate.

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 tool's purpose: 'fetches the latest weather reports for the given city.' It specifies the verb ('fetches') and resource ('weather reports'), though it doesn't need to distinguish from siblings since none exist. The purpose is specific and unambiguous.

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. It mentions the city parameter but offers no context about prerequisites, limitations, or typical use cases. With no siblings, this is less critical, but the description still lacks usage context.

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/CodeByWaqas/weather-mcp-server'

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