Skip to main content
Glama
hanweg

mcp-tool-builder

by hanweg

get_weather_forecast

Retrieve weather forecasts for any US ZIP code using National Weather Service data to plan activities and prepare for conditions.

Instructions

Retrieves weather forecast for a given ZIP code using NWS API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
zip_codeYes

Implementation Reference

  • The main handler function for the get_weather_forecast tool. It takes a zip_code, uses geopy to get coordinates, fetches weather grid and forecast from NWS API, extracts next 4 periods' forecast, and returns location and forecast summary or error.
    def get_weather_forecast(zip_code):
        try:
            # Initialize geocoder
            geolocator = Nominatim(user_agent="weather_forecast_app")
            
            # Get location coordinates from ZIP code
            location = geolocator.geocode(zip_code)
            if not location:
                return {"error": "Unable to find coordinates for the given ZIP code"}
            
            # Get NWS grid point
            grid_url = f"https://api.weather.gov/points/{location.latitude},{location.longitude}"
            grid_response = requests.get(grid_url, headers={'User-Agent': 'WeatherApp/1.0'})
            grid_data = grid_response.json()
            
            if grid_response.status_code != 200:
                return {"error": "Unable to retrieve grid information"}
            
            # Get forecast
            forecast_url = grid_data['properties']['forecast']
            forecast_response = requests.get(forecast_url, headers={'User-Agent': 'WeatherApp/1.0'})
            forecast_data = forecast_response.json()
            
            if forecast_response.status_code != 200:
                return {"error": "Unable to retrieve forecast"}
            
            # Extract key forecast information
            periods = forecast_data['properties']['periods']
            forecast_summary = []
            for period in periods[:4]:  # First 4 periods
                forecast_summary.append({
                    "name": period['name'],
                    "temperature": f"{period['temperature']}°{period['temperatureUnit']}",
                    "short_forecast": period['shortForecast'],
                    "detailed_forecast": period['detailedForecast']
                })
            
            return {
                "location": f"{location.address}",
                "forecast": forecast_summary
            }
        
        except Exception as e:
            return {"error": f"An error occurred: {str(e)}"}

Tool Definition Quality

Score is being calculated. Check back soon.

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/hanweg/mcp-tool-builder'

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