Skip to main content
Glama

get_warning

Retrieve weather warnings within a specific date range to monitor and prepare for adverse weather conditions. Use start and end timestamps to filter relevant alerts.

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_endNo
datetime_startNo

Implementation Reference

  • The handler function for the 'get_warning' tool. It is decorated with @mcp.tool() which serves as both the implementation and registration. Fetches weather warnings from the Malaysian government API within the given datetime range, validates inputs, formats the results using format_warning helper, and returns a concatenated string of warnings.
    @mcp.tool() 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)
  • Supporting helper utility that formats individual weather warning data into a human-readable string, used by 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')} """
  • General helper for making API requests to the government data 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
  • Validation and utility helpers for datetime used in get_warning input validation and default values.
    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

Other Tools

Related 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