Skip to main content
Glama

get_water_level_condition

Retrieve flood warning water level conditions for specific districts or states in Malaysia to monitor potential flooding risks.

Instructions

Retrieve the water level conditions associated with flood warnings for a specified district or state. If both district and state are provided, the district takes precedence. If district or state is not specified, use an empty string for that field.

Args:
    district: The name of the district within the specified state for which to retrieve flood warning conditions.
    state: The name of the state in Malaysia for which to retrieve flood warning conditions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
districtNo
stateNo

Implementation Reference

  • The core handler function implementing the tool logic. It processes input district/state, queries the Malaysian government flood-warning API for active (ON) water level statuses, handles errors/no data, formats results using format_water_level helper, and returns joined summaries.
    async def get_water_level_condition(district: str = "", state: str = "") -> str:
        """Retrieve the water level conditions associated with flood warnings for a specified district or state.
        If both district and state are provided, the district takes precedence.
        If district or state is not specified, use an empty string for that field.
    
        Args:
            district: The name of the district within the specified state for which to retrieve flood warning conditions.
            state: The name of the state in Malaysia for which to retrieve flood warning conditions.
        """
    
        contain_str = ""
        district = district.strip()
        state = state.strip()
        if district:
            contain_str = f"{district}@district"
        elif state:
            contain_str = f"{state}@state"
    
        water_level_url = f"{GOV_API_BASE}/flood-warning"
        water_level_data = await make_api_request(water_level_url, {
                                                "meta": "true",
                                                "sort": "-water_level_update_datetime,-rainfall_update_datetime",
                                                "icontains": contain_str,
                                                "filter": "ON@water_level_status",
                                                "limit": 20
                                            })
    
        if not water_level_data or "data" not in water_level_data:
            return "Unable to fetch water level data for this state or district."
    
        if not water_level_data["data"]:
            return "No active water level data for this state or district."
    
        water_levels = [format_water_level(warn) for warn in water_level_data["data"]]
        return "\n---\n".join(water_levels)
  • weather.py:9-9 (registration)
    The @mcp.tool() decorator registers the get_water_level_condition function as a tool on the FastMCP server instance.
    @mcp.tool()
  • Supporting helper function that formats the API response data for water level stations into a detailed human-readable string used in the tool output.
    def format_water_level(water_level_res: dict) -> str:
        """Format water level and rainfail data into a readable string."""
        return f"""
    Monitoring Station ID: {water_level_res.get('station_id', 'Unknown')}
    Monitoring Station Name: {water_level_res.get('station_name', 'Unknown')}
    Latitude: {water_level_res.get('latitude', 'Unknown')}
    Longitude: {water_level_res.get('longitude', 'Unknown')}
    District: {water_level_res.get('district', 'Unknown')}
    State: {water_level_res.get('state', 'Unknown')}
    Sub-basin: {water_level_res.get('sub_basin', 'Unknown')}
    Main River Basin: {water_level_res.get('main_basin', 'Unknown')}
    Current Water Level: {water_level_res.get('water_level_current', 'Unknown')}
    Current Water Level Indicator: {water_level_res.get('water_level_indicator', 'Unknown')}
    Current Water Level Increment: {water_level_res.get('water_level_increment', 'Unknown')}
    Current Water Level Trend (rising, falling, or steady): {water_level_res.get('water_level_trend', 'Unknown')}
    Water Level - Normal (Reference): {water_level_res.get('water_level_normal_level', 'Unknown')}
    Water Level - Alert (Reference): {water_level_res.get('water_level_alert_level', 'Unknown')}
    Water Level - Warning (Reference): {water_level_res.get('water_level_warning_level', 'Unknown')}
    Water Level - Danger (Reference): {water_level_res.get('water_level_danger_level', 'Unknown')}
    Current Water Level Updated Datetime: {water_level_res.get('water_level_update_datetime', 'Unknown')}
    Clean Rainfall: {water_level_res.get('rainfall_clean', 'Unknown')}
    Latest 1 Hour Rainfall: {water_level_res.get('rainfall_latest_1hr', 'Unknown')}
    Total Rainfall Today: {water_level_res.get('rainfall_total_today', 'Unknown')}
    Rainfall Indicator: {water_level_res.get('rainfall_indicator', 'Unknown')}
    Rainfall Updated Datetime: {water_level_res.get('rainfall_update_datetime', 'Unknown')}
    """
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. While it describes the retrieval action and parameter precedence, it lacks critical behavioral details such as whether this is a read-only operation, what authentication might be required, rate limits, error conditions, or the format of returned data. For a tool with zero annotation coverage, this is a significant gap.

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 front-loaded with the core purpose in the first sentence. The parameter explanations are necessary given the schema coverage gap. However, the formatting with 'Args:' could be slightly more integrated, and some sentences could be more concise (e.g., the second sentence about precedence is clear but slightly wordy).

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 complexity (2 parameters, no annotations, no output schema), the description is moderately complete. It covers purpose and parameter semantics well but lacks behavioral transparency and output details. Without annotations or output schema, the description should ideally provide more context about what the tool returns and any behavioral constraints to be fully complete.

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 explicitly defines both parameters: 'district: The name of the district within the specified state for which to retrieve flood warning conditions' and 'state: The name of the state in Malaysia for which to retrieve flood warning conditions.' This clarifies the geographic scope and relationship between parameters, fully compensating for the schema's lack of descriptions.

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 the water level conditions associated with flood warnings for a specified district or state.' It specifies the verb (retrieve), resource (water level conditions), and context (flood warnings). However, it doesn't explicitly differentiate from sibling tools like 'get_warning' or 'get_weather_forecast' beyond the specific resource focus.

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 usage: 'If both district and state are provided, the district takes precedence. If district or state is not specified, use an empty string for that field.' This gives explicit guidance on parameter precedence and handling of unspecified fields. However, it doesn't mention when to use this tool versus alternatives like 'get_warning' or provide exclusion criteria.

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