Skip to main content
Glama
jeannassereldine

MCP Weather Server

get_forecast

Retrieve weather forecast data for any location by providing its latitude and longitude coordinates.

Instructions

Get weather forecast for a location. Args: latitude: Latitude of the location longitude: Longitude of the location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes

Implementation Reference

  • The handler function that implements the logic for the 'get_forecast' tool. It uses hardcoded weather data for a specific location and formats it into a string using the format_forecast helper.
    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)
  • The @mcp.tool() decorator registers the get_forecast function as an MCP tool within the register function.
    @mcp.tool()
    def get_forecast(latitude: float, longitude: float) -> str:
  • weather.py:2-7 (registration)
    Imports the get_forcast module containing the tool definitions and calls its register(mcp) function to register the tools, including get_forecast, with the MCP server instance.
    from tools import get_forcast
    # Initialize FastMCP server
    mcp = FastMCP("weather")
    
    
    get_forcast.register(mcp)
  • Helper function used by get_forecast to format the list of forecast dictionaries into a human-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
            )
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/jeannassereldine/mcp-server'

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