Skip to main content
Glama
liusicheng

MCP Weather Server

by liusicheng

get_forecast

Retrieve weather forecasts for any city up to three days ahead. Enter a city name (English) and optional number of days to get future weather predictions. Supports up to 3 days.

Instructions

获取指定城市未来几天的天气预报。

参数:
    city: 城市名称(英文)
    days: 预报天数,默认 3 天,最多 3 天

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes
daysNo

Implementation Reference

  • server.py:59-87 (handler)
    The main handler function for the 'get_forecast' tool. Fetches weather forecast from wttr.in API and returns list of daily forecasts.
    @mcp.tool()
    async def get_forecast(city: str, days: int = 3) -> list:
        """获取指定城市未来几天的天气预报。
    
        参数:
            city: 城市名称(英文)
            days: 预报天数,默认 3 天,最多 3 天
        """
        import httpx
    
        try:
            async with httpx.AsyncClient() as client:
                resp = await client.get(
                    f"https://wttr.in/{city}?format=j1",
                    timeout=10,
                )
                resp.raise_for_status()
                data = resp.json()
    
                forecasts = []
                for day in data.get("weather", [])[:days]:
                    forecasts.append({
                        "date": day["date"],
                        "max_temp_c": day["maxtempC"],
                        "min_temp_c": day["mintempC"],
                        "avg_temp_c": day["avgtempC"],
                        "description": day["hourly"][4]["weatherDesc"][0]["value"],
                    })
                return forecasts
  • server.py:59-59 (registration)
    Registration of the get_forecast tool via @mcp.tool() decorator on FastMCP instance.
    @mcp.tool()
  • Duplicate handler for get_forecast in the Streamable HTTP version (server_remote.py), slightly different output (no avg_temp_c).
    @mcp.tool()
    async def get_forecast(city: str, days: int = 3) -> list:
        """获取指定城市未来几天的天气预报。
    
        参数:
            city: 城市名称(英文)
            days: 预报天数,默认 3 天,最多 3 天
        """
        try:
            async with httpx.AsyncClient() as client:
                resp = await client.get(
                    f"https://wttr.in/{city}?format=j1",
                    timeout=10,
                )
                resp.raise_for_status()
                data = resp.json()
    
                forecasts = []
                for day in data.get("weather", [])[:days]:
                    forecasts.append({
                        "date": day["date"],
                        "max_temp_c": day["maxtempC"],
                        "min_temp_c": day["mintempC"],
                        "description": day["hourly"][4]["weatherDesc"][0]["value"],
                    })
                return forecasts
  • server_remote.py:60-60 (registration)
    Registration of get_forecast in server_remote.py via @mcp.tool() decorator.
    @mcp.tool()
Behavior3/5

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

With no annotations, the description carries the burden. It discloses that city must be in English and days max is 3, but does not mention read-only nature, error handling, or output format. Basic constraints are provided but deeper behavior is missing.

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

Conciseness5/5

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

The description is highly concise, using a short paragraph with bullet points. Every sentence adds necessary information without redundancy.

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

Completeness3/5

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

For a simple tool with two parameters and no output schema, the description covers input constraints adequately. However, it omits what the response contains, which would be helpful for an agent invoking the tool.

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

Parameters4/5

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

Schema coverage is 0%, so the description adds value by specifying city format (English) and days limit (max 3). This compensates for missing schema descriptions, though more details on valid values would help.

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

Purpose4/5

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

The description clearly states it retrieves weather forecasts for a specified city over a number of days. However, it does not differentiate from the sibling tool 'get_weather', leaving ambiguity about when to use each.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'get_weather' or 'temperature_convert'. The description lacks explicit context for selection.

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

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