get_forecast
Retrieve detailed weather forecasts for a specific location by providing latitude and longitude coordinates using the MCP Weather Server.
Instructions
Get weather forecast for a location. Args: latitude: Latitude of the location longitude: Longitude of the location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | ||
| longitude | Yes |
Implementation Reference
- tools/get_forcast.py:15-39 (handler)The handler function for the 'get_forecast' tool. It takes latitude and longitude, returns a formatted string of hardcoded weather forecasts.@mcp.tool() def get_forecast(latitude: float, longitude: float) -> str: """Get weather forecast for a location. Args: latitude: Latitude of the location longitude: Longitude of the location """ forecasts = [ { "name": "This Afternoon", "temperature": "68°F", "wind": "18 mph WSW", "forecast": "Sunny. High near 68, with temperatures falling to around 66 in the afternoon. West southwest wind around 18 mph, with gusts as high as 23 mph." }, { "name": "Tonight", "temperature": "55°F", "wind": "8 to 17 mph WSW", "forecast": "Mostly clear, with a low around 55. West southwest wind 8 to 17 mph, with gusts as high as 22 mph." }, ] # Hardcode replace it with you api , you can call https://api.weather.gov ... return format_forecast(forecasts)
- tools/get_forcast.py:43-50 (helper)Helper function used by get_forecast to format the forecast data into a readable string.def format_forecast(forecasts: List[Dict]) -> str: """ Format a list of forecast dictionaries into a readable string. """ return "\n---\n".join( f"{f['name']}:\nTemperature: {f['temperature']}\nWind: {f['wind']}\nForecast: {f['forecast']}" for f in forecasts )
- tools/get_forcast.py:15-15 (registration)The @mcp.tool() decorator registers the get_forecast function as an MCP tool.@mcp.tool()
- tools/get_forcast.py:16-16 (schema)Type hints defining the input schema (latitude: float, longitude: float) and output (str).def get_forecast(latitude: float, longitude: float) -> str: