Skip to main content
Glama

get_weather_by_position

Retrieve weather data for any location using geographic coordinates to support stargazing planning and astronomical observations.

Instructions

Fetches weather data for a specified location by its geographic coordinates (latitude and longitude) using the QWeather API.

Args: lat (float): The latitude of the location for which weather data is requested. lon (float): The longitude of the location 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
latYes
lonYes

Implementation Reference

  • The primary handler function for the 'get_weather_by_position' MCP tool. Decorated with @mcp.tool() for registration and execution. Validates API key, calls the qweather helper function, and formats the response.
    @mcp.tool()
    def get_weather_by_position(lat: float, lon: float):
        """
        Fetches weather data for a specified location by its geographic coordinates (latitude and longitude) using the QWeather API.
    
        Args:
            lat (float): The latitude of the location for which weather data is requested.
            lon (float): The longitude of the location 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_position(lat, lon, QWEATHER_API_KEY)
        return format_response(result)
  • Supporting helper function that fetches real-time weather and 10-day forecasts from QWeather API using the provided coordinates and API token. Called by the main handler.
    def qweather_get_weather_by_position(lat, lon, api_token):
        """Get weather data by position.
        Args:
            lat (float): Latitude.
            lon (float): Longitude.
            api_token (str): The QWeather API authentication token.
        Returns:
           dict: A dictionary containing the following keys:
            "real_time": Real-time weather data.
            "ten_days_forcasts": 10-day weather forecast data."
            """
        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
        }
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the API dependency (QWeather) and authentication requirement (QWEATHER_API_KEY environment variable), which are important behavioral traits. However, it doesn't mention rate limits, error handling beyond ValueError, or response format details beyond the basic structure.

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

Conciseness4/5

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

The description is appropriately sized and well-structured with clear sections (Args, Returns, Raises). Every sentence adds value, though the 'Args' and 'Returns' sections could be slightly more concise while maintaining clarity.

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 2-parameter tool with no annotations and no output schema, the description provides adequate coverage of purpose, parameters, and basic behavior. However, it lacks details about the actual weather data structure in the response, error scenarios beyond missing API key, and performance characteristics that would be helpful for an agent.

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 has 0% description coverage, so the description must compensate. It provides clear semantic meaning for both parameters (latitude and longitude of the location) beyond what the bare schema offers. The description explains what these coordinates represent and their purpose in the API call.

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 geographic coordinates using the QWeather API'). It distinguishes from sibling 'get_weather_by_name' by specifying coordinate-based lookup versus name-based lookup.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (when you have geographic coordinates) and implicitly distinguishes it from 'get_weather_by_name' (which uses location names). However, it doesn't explicitly state when NOT to use this tool or mention all alternatives among siblings.

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