Skip to main content
Glama
Danii2020

Weather MCP Server

by Danii2020

get_forecast

Retrieve weather forecasts for specific coordinates using latitude and longitude inputs to access current and upcoming conditions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYes
longitudeYes

Implementation Reference

  • The asynchronous handler function implementing the core logic of the 'get_forecast' tool. It retrieves weather forecast data from the NWS API using latitude and longitude, formats the first 5 periods, and returns a string summary.
    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)
  • The @mcp.tool() decorator registers the get_forecast function as an MCP tool, using its name as the tool identifier.
    @mcp.tool()
  • Utility function to make asynchronous HTTP requests to the NWS API, handling errors and headers. Called twice in the get_forecast handler.
    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
  • Constants used by the get_forecast tool: base URL for NWS API and User-Agent header.
    NWS_API_BASE = "https://api.weather.gov"
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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