Skip to main content
Glama

get_weather_by_name

Fetch weather data for any location by name to support stargazing planning and astronomical calculations with location-specific conditions.

Instructions

Fetches weather data for a specified location by its name using the QWeather API.

Args: place_name (str): The name of the location (e.g., city, region) for which weather data is requested.

Returns: Dict with keys "data", "_meta". "data" contains the weather data.

Raises: ValueError: If the QWEATHER_API_KEY environment variable is not set, preventing API access.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
place_nameYes

Implementation Reference

  • The main tool handler function for 'get_weather_by_name', decorated with @mcp.tool(). It validates the API key environment variable, calls the QWeather interaction helper, and formats the response.
    @mcp.tool()
    def get_weather_by_name(place_name: str):
        """
        Fetches weather data for a specified location by its name using the QWeather API.
    
        Args:
            place_name (str): The name of the location (e.g., city, region) for which weather data is requested.
    
        Returns:
            Dict with keys "data", "_meta". "data" contains the weather data.
    
        Raises:
            ValueError: If the `QWEATHER_API_KEY` environment variable is not set, preventing API access.
        """
        QWEATHER_API_KEY = os.getenv("QWEATHER_API_KEY", None)
        if QWEATHER_API_KEY is None:
            raise ValueError("QWEATHER_API_KEY environment variable not set.")
        result = qweather_get_weather_by_name(place_name, QWEATHER_API_KEY)
        return format_response(result)
  • Core helper function that performs QWeather API calls: POI lookup for coordinates, then real-time weather and 10-day forecast retrieval.
    def qweather_get_weather_by_name(city: str, api_token: str) -> dict:
        """
        Fetches both real-time and 10-day forecast weather data for a given city name.
        Args:
            city (str): The city name (e.g., "上海市闵行区").
            api_token (str): The QWeather API authentication token.
    
        Returns:
            dict: A dictionary containing:
                - "real_time": Real-time weather data.
                - "ten_days_forcasts": 10-day weather forecast data.
            Returns None if any API call fails.
        """
        res = qweather_get_poi(city, api_token)
        if not res:
            return None
        
        lat, lon = res['poi'][0]['lat'], res['poi'][0]['lon']
        
        real_time_data = qweather_get_weather_by_coord_real_time(lon, lat, api_token)
        ten_days_forcasts = qweather_get_weather_by_coord_in_ten_days(lon, lat, api_token)
        
        return {
            "real_time": real_time_data,
            "ten_days_forcasts": ten_days_forcasts
        }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the tool's dependency on an environment variable ('QWEATHER_API_KEY') and the error handling for missing keys, adding valuable context beyond basic functionality. However, it does not cover rate limits, authentication details, or response format specifics.

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 appropriately sized and front-loaded, starting with the core purpose, followed by structured sections for Args, Returns, and Raises. Every sentence adds value, with no redundant information, making it efficient and easy to parse.

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?

Given the tool's moderate complexity (1 parameter, no output schema, no annotations), the description is partially complete. It covers the purpose, parameter semantics, and error conditions, but lacks details on the return value structure beyond high-level keys, and does not address potential API limitations or usage scenarios relative to siblings.

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 schema description coverage is 0%, so the description must compensate. It adds meaning by explaining the parameter 'place_name' as 'The name of the location (e.g., city, region) for which weather data is requested,' including an example. This clarifies the parameter's purpose and format, though it could provide more detail on constraints or valid inputs.

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 the specific action ('Fetches weather data'), resource ('for a specified location'), and method ('by its name using the QWeather API'). It distinguishes from sibling tools like 'get_weather_by_position' by specifying the name-based approach, providing clear differentiation.

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 by mentioning the API and parameter, but does not explicitly state when to use this tool versus alternatives like 'get_weather_by_position' or other weather-related siblings. It provides some context with the API reference but lacks explicit guidance on tool 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/StarGazer1995/mcp-stargazing'

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