Skip to main content
Glama

get_warning

Retrieve weather warnings for Malaysia within a specified date range to monitor alerts and plan accordingly.

Instructions

Retrieve general weather warnings issued within a specified date range.

Args:
    datetime_start: The earliest timestamp in the form of <YYYY-MM-DD HH:mm:ss> (inclusive) from which to retrieve weather warnings. If omitted, defaults to the current date.
    datetime_end: The latest timestamp in the form of <YYYY-MM-DD HH:mm:ss> (inclusive) to stop retrieving the weather warnings. If omitted, defaults to the current date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datetime_startNo
datetime_endNo

Implementation Reference

  • weather.py:46-46 (registration)
    Registers the 'get_warning' tool using the @mcp.tool() decorator.
    @mcp.tool()
  • The handler function that implements the 'get_warning' tool logic: validates input datetimes, fetches data from the weather warning API, formats the warnings, and returns them as a joined string.
    async def get_warning(datetime_start: str = None, datetime_end: str = None) -> str:
        """Retrieve general weather warnings issued within a specified date range.
    
        Args:
            datetime_start: The earliest timestamp in the form of <YYYY-MM-DD HH:mm:ss> (inclusive) from which to retrieve weather warnings. If omitted, defaults to the current date.
            datetime_end: The latest timestamp in the form of <YYYY-MM-DD HH:mm:ss> (inclusive) to stop retrieving the weather warnings. If omitted, defaults to the current date.
        """
        if not datetime_start:
            datetime_start = current_date() + " 00:00:01"
        elif not validate_datetime(datetime_start):
            return "Wrong `datetime_start` format given. Accepted format is 'YYYY-MM-DD HH:mm:ss'."
    
        if not datetime_end:
            datetime_end = current_date() + " 23:59:59"
        elif not validate_datetime(datetime_end):
            return "Wrong `datetime_end` format given. Accepted format is 'YYYY-MM-DD HH:mm:ss'."
    
        warning_url = f"{GOV_API_BASE}/weather/warning"
        warning_data = await make_api_request(warning_url, {
                                                "meta": "true",
                                                "sort": "-warning_issue__issued",
                                                "timestamp_start": f"{datetime_start}@warning_issue__issued",
                                                "timestamp_end": f"{datetime_end}@warning_issue__issued",
                                            })
    
        if not warning_data or "data" not in warning_data:
            return "Unable to fetch warning data for this time period."
    
        if not warning_data["data"]:
            return "No active warning data for this time period."
    
        warnings = [format_warning(warn) for warn in warning_data["data"]]
        return "\n---\n".join(warnings)
  • Helper function to format individual weather warning data into a human-readable string, used within the get_warning handler.
    def format_warning(warning_res: dict) -> str:
        """Format a warning json response into a readable string."""
        warning_issue = warning_res["warning_issue"]
        return f"""
    Warning Issue Date: {warning_issue.get('issued', 'Unknown')}
    Title: {warning_issue.get('title_en', 'Unknown')}
    Is Valid From: {warning_res.get('valid_from', 'Unknown')}
    Is Valid To: {warning_res.get('valid_to', 'Unknown')}
    Heading: {warning_res.get('heading_en', 'Unknown')}
    Details: {warning_res.get('text_en', 'Unknown')}
    Instruction: {warning_res.get('instruction_en', 'Unknown')}
    """
  • Helper function to make asynchronous HTTP requests to the API, used by get_warning to fetch warning data.
    async def make_api_request(url: str, params: dict[str, str]) -> dict[str, Any] | None:
        """Make a request to the Malaysia Government API with proper error handling."""
        async with httpx.AsyncClient() as client:
            try:
                response = await client.get(url, params=params, timeout=30.0, follow_redirects=True)
                print(response)
                response.raise_for_status()
                return response.json()
            except Exception as ex:
                return None
  • Helper function to validate datetime format, used in get_warning for input validation.
    def validate_datetime(datetime_text: str) -> bool:
        """Validate date string format."""
        try:
            datetime.strptime(datetime_text, "%Y-%m-%d %H:%M:%S")
            return True
        except ValueError:
            return False
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the action ('retrieve') and date range filtering, but lacks critical behavioral details: it doesn't specify if this is a read-only operation, what permissions are needed, how results are returned (e.g., format, pagination), error handling, or rate limits. For a retrieval tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves beyond basic functionality.

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: the first sentence states the core purpose, followed by a structured 'Args:' section with bullet-like explanations for each parameter. Every sentence adds value—no redundancy or fluff. The structure makes it easy to scan, with key information presented efficiently.

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 (2 parameters, no output schema, no annotations), the description is partially complete. It excels in parameter semantics and purpose clarity but lacks usage guidelines and behavioral transparency. Without annotations or output schema, it should ideally cover more behavioral aspects (e.g., response format, safety). It's adequate as a minimum viable description but has clear gaps in context.

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

Parameters5/5

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

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains both parameters: datetime_start as 'The earliest timestamp... (inclusive) from which to retrieve weather warnings' with format details and default behavior, and datetime_end similarly. This fully compensates for the schema's lack of descriptions, providing clear semantics, formats, and defaults that are not in the schema properties.

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 the tool's purpose: 'Retrieve general weather warnings issued within a specified date range.' This specifies the verb ('retrieve'), resource ('general weather warnings'), and scope ('within a specified date range'). It distinguishes from siblings like get_earthquake_news or get_weather_forecast by focusing on warnings rather than news, conditions, or forecasts. However, it doesn't explicitly differentiate from all siblings (e.g., water level conditions might overlap with weather warnings), so it's not a perfect 5.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like get_earthquake_news or get_water_level_condition, nor does it specify scenarios where weather warnings are preferred over forecasts or other data sources. The only implied usage is for retrieving weather warnings by date, but no explicit when/when-not instructions or alternatives are 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/yting27/weather-my-mcp'

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