Skip to main content
Glama
Danii2020

Weather MCP Server

by Danii2020

get_forecast

Retrieve real-time weather forecasts for specific locations by providing latitude and longitude coordinates. Fetches data from the National Weather Service API via the Weather MCP Server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes

Implementation Reference

  • The core handler function implementing the 'get_forecast' tool logic. It fetches the weather forecast for given coordinates from the National Weather Service API, formats the first 5 forecast periods, and returns them as a string.
    @mcp.tool() async def get_forecast(latitude: float, longitude: float) -> str: url = f"{NWS_API_BASE}/points/{latitude},{longitude}" data = await make_nws_request(url) if not data: return "Unable to fetch forecast data for this location." forecast_url = data["properties"]["forecast"] forecast_data = await make_nws_request(forecast_url) if not forecast_data: return "Unable to fetch detailed forecast." periods = forecast_data["properties"]["periods"] forecasts = [] for period in periods[:5]: forecast = f""" {period['name']}: Temperature: {period['temperature']}°{period['temperatureUnit']} Wind: {period['windSpeed']} {period['windDirection']} Forecast: {period['detailedForecast']} """ forecasts.append(forecast) return "\n---\n".join(forecasts)
  • Helper utility function used by the get_forecast handler to make asynchronous HTTP requests to the NWS API endpoints.
    async def make_nws_request(url: str) -> dict[str, Any] | None: headers = {"User-Agent": USER_AGENT, "Accept": "application/geo+json"} async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None
  • The MCP server instance creation and tool registration via @mcp.tool() decorator for get_forecast.
    mcp = FastMCP("weather")

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/Danii2020/weather-mcp'

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