Skip to main content
Glama
liusicheng

MCP Weather Server

by liusicheng

get_weather

Retrieve current weather conditions for any city worldwide. Provide the city name in English to get temperature, humidity, wind, and other real-time weather data.

Instructions

获取指定城市的当前天气信息。

参数:
    city: 城市名称(英文),如 Beijing、Tokyo、London

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes

Implementation Reference

  • server.py:26-56 (handler)
    The get_weather handler function registered as an MCP tool via @mcp.tool(). It fetches current weather from wttr.in API for a given city and returns temperature, humidity, feels-like, description, and wind speed.
    @mcp.tool()
    async def get_weather(city: str) -> dict:
        """获取指定城市的当前天气信息。
    
        参数:
            city: 城市名称(英文),如 Beijing、Tokyo、London
        """
        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()
                current = data["current_condition"][0]
    
                return {
                    "city": city,
                    "temperature_celsius": current["temp_C"],
                    "humidity_percent": current["humidity"],
                    "feels_like_celsius": current["FeelsLikeC"],
                    "description": current["weatherDesc"][0]["value"],
                    "wind_speed_kmh": current["windspeedKmph"],
                }
        except httpx.TimeoutException:
            return {"error": f"查询 {city} 超时,请稍后重试"}
        except Exception as e:
            return {"error": f"查询失败: {str(e)}"}
  • server.py:26-27 (registration)
    Registration of get_weather as an MCP tool using the @mcp.tool() decorator on the FastMCP server instance.
    @mcp.tool()
    async def get_weather(city: str) -> dict:
  • Input schema for get_weather: parameter 'city' (str) with docstring describing the expected format. Output type is dict as per return type annotation.
    @mcp.tool()
    async def get_weather(city: str) -> dict:
        """获取指定城市的当前天气信息。
    
        参数:
            city: 城市名称(英文),如 Beijing、Tokyo、London
        """
  • Duplicate handler for get_weather in the Streamable HTTP remote server version (server_remote.py). Same logic as server.py version.
    @mcp.tool()
    async def get_weather(city: str) -> dict:
        """获取指定城市的当前天气信息。
    
        参数:
            city: 城市名称(英文),如 Beijing、Tokyo、London
        """
        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()
                current = data["current_condition"][0]
    
                return {
                    "city": city,
                    "temperature_celsius": current["temp_C"],
                    "humidity_percent": current["humidity"],
                    "feels_like_celsius": current["FeelsLikeC"],
                    "description": current["weatherDesc"][0]["value"],
                    "wind_speed_kmh": current["windspeedKmph"],
                }
        except httpx.TimeoutException:
            return {"error": f"查询 {city} 超时,请稍后重试"}
        except Exception as e:
            return {"error": f"查询失败: {str(e)}"}
Behavior2/5

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

No annotations are provided, so the description carries full burden. It only states the core functionality without disclosing behavioral traits such as rate limits, data source, units, or error handling. This is insufficient for a tool with no annotations.

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 concise, front-loaded with the action, and uses a clear bullet-style parameter list. Every sentence adds value without unnecessary words.

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

Completeness4/5

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

For a simple tool with one parameter and no output schema, the description covers the essential purpose and parameter format. However, missing details like output format (e.g., temperature, units) slightly reduce completeness.

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?

The description adds meaning beyond the input schema by specifying that the city name must be in English (e.g., Beijing, Tokyo, London). The schema only defines 'city' as a string with no further info, so this guidance is valuable.

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

Purpose5/5

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

The description clearly states '获取指定城市的当前天气信息' (get current weather for a specified city), which is a specific verb+resource combination. It distinguishes from siblings 'get_forecast' and 'temperature_convert' by focusing on current weather.

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

Usage Guidelines3/5

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

The description implies usage for current weather queries with city name in English, but does not explicitly state when to use this tool vs. alternatives like 'get_forecast' or 'temperature_convert'. No when-not or alternative guidance is provided.

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