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 }

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