fetch_weather
Retrieve current weather conditions and temperature data for any specified location worldwide using real-time weather information.
Instructions
Get weather information for a given location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes |
Implementation Reference
- main.py:7-13 (handler)The handler function for the 'fetch_weather' tool, registered via @mcp.tool() decorator. It takes a location string and returns the weather by delegating to the get_weather helper.@mcp.tool() async def fetch_weather(location: str) -> str: """ Get weather information for a given location """ return get_weather(location)
- tools/weather.py:3-22 (helper)Helper function containing the core logic to fetch weather data from wttr.in API using urllib, with error handling.def get_weather(location:str) -> str: """ fetches the weather for a given location, example: "London, new-york, San-francisco, etc." Args: location(str): the city or location name to fetch the weather for. Returns: str: a string containing the weather for the location """ try: url = f"https://wttr.in/{location}?format=3" with urllib.request.urlopen(url) as response: result = response.read().decode('utf-8').strip() return result except Exception as e: return f"Error fetching weather: {e}"