Skip to main content
Glama
CodeByWaqas

Weather MCP Server

by CodeByWaqas

weather

Fetch real-time weather reports for any city, including temperature, humidity, wind speed, and sunrise/sunset times, using OpenWeatherMap API integration.

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 handler function for the 'weather' tool, decorated with @mcp.tool() to register it with the MCP server. It takes a city name as input and returns JSON-serialized weather data by calling the helper function.
    @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
  • Supporting helper function that performs the HTTP request to the OpenWeatherMap API, parses the response, and extracts relevant weather information for the given city.
    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
  • The @mcp.tool() decorator registers the 'weather' function as an MCP tool.
    @mcp.tool()
  • The docstring provides the input schema (city: str) and output description (dict of weather data) for the tool.
    """ 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. """

Other Tools

Related 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