Skip to main content
Glama
michaelkrasa

Alpha ESS MCP Server

by michaelkrasa

get_last_power_data

Retrieve real-time power data for Alpha ESS solar and battery systems. Returns structured snapshots with clear field names and units for monitoring energy performance.

Instructions

Get the latest real-time power data for a specific Alpha ESS system.
Returns structured snapshot with clear field names and units.
If no serial provided, auto-selects if only one system exists.

Args:
    serial: The serial number of the Alpha ESS system (optional)
    
Returns:
    dict: Enhanced response with structured real-time power data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:451-518 (handler)
    The primary handler function for the MCP tool 'get_last_power_data'. It handles serial auto-discovery, API call to client.getLastPowerData(serial), data structuring, error handling, and response formatting using @mcp.tool() decorator for registration.
    @mcp.tool()
    async def get_last_power_data(serial: Optional[str] = None) -> dict[str, Any]:
        """
        Get the latest real-time power data for a specific Alpha ESS system.
        Returns structured snapshot with clear field names and units.
        If no serial provided, auto-selects if only one system exists.
        
        Args:
            serial: The serial number of the Alpha ESS system (optional)
            
        Returns:
            dict: Enhanced response with structured real-time power data
        """
        client = None
        try:
            # Auto-discover serial if not provided
            if not serial:
                serial_info = await get_default_serial()
                if not serial_info['success'] or not serial_info['serial']:
                    return create_enhanced_response(
                        success=False,
                        message=f"Serial auto-discovery failed: {serial_info['message']}",
                        raw_data=None,
                        data_type="snapshot",
                        metadata={"available_systems": serial_info.get('systems', [])}
                    )
                serial = serial_info['serial']
    
            app_id, app_secret = get_alpha_credentials()
            client = alphaess(app_id, app_secret)
    
            # Get last power data
            power_data = await client.getLastPowerData(serial)
    
            # Structure the snapshot data
            structured = structure_snapshot_data(power_data)
    
            return create_enhanced_response(
                success=True,
                message=f"Successfully retrieved last power data for {serial}",
                raw_data=power_data,
                data_type="snapshot",
                serial_used=serial,
                metadata={
                    "snapshot_type": "real_time_power",
                    "units": {"power": "W", "soc": "%"}
                },
                structured_data=structured
            )
    
        except ValueError as e:
            return create_enhanced_response(
                success=False,
                message=f"Configuration error: {str(e)}",
                raw_data=None,
                data_type="snapshot"
            )
        except Exception as e:
            return create_enhanced_response(
                success=False,
                message=f"Error retrieving power data: {str(e)}",
                raw_data=None,
                data_type="snapshot"
            )
        finally:
            if client:
                await client.close()
  • Dataclass defining the structured Snapshot output schema used by get_last_power_data tool for real-time power data.
    class Snapshot:
        solar: Dict[str, Any]
        battery: Dict[str, Any]
        grid: Dict[str, Any]
        load: Dict[str, Any]
        ev_charging: Dict[str, Any]
        units: Dict[str, str]
  • Helper function that transforms raw API power data into the structured Snapshot dataclass instance used by the tool.
    def structure_snapshot_data(raw_data: Dict[str, Any]) -> Snapshot:
        """Structure real-time snapshot data with clear field names"""
        return Snapshot(
            solar={
                "total_power": raw_data.get('ppv', 0),
                "panels": {
                    "panel_1": raw_data.get('ppvDetail', {}).get('ppv1', 0),
                    "panel_2": raw_data.get('ppvDetail', {}).get('ppv2', 0),
                    "panel_3": raw_data.get('ppvDetail', {}).get('ppv3', 0),
                    "panel_4": raw_data.get('ppvDetail', {}).get('ppv4', 0)
                }
            },
            battery={
                "state_of_charge": raw_data.get('soc', 0),
                "power": raw_data.get('pbat', 0)  # Positive = charging, Negative = discharging
            },
            grid={
                "total_power": raw_data.get('pgrid', 0),  # Positive = importing, Negative = exporting
                "phases": {
                    "l1_power": raw_data.get('pgridDetail', {}).get('pmeterL1', 0),
                    "l2_power": raw_data.get('pgridDetail', {}).get('pmeterL2', 0),
                    "l3_power": raw_data.get('pgridDetail', {}).get('pmeterL3', 0)
                }
            },
            load={
                "total_power": raw_data.get('pload', 0),
                "phases": {
                    "l1_real": raw_data.get('prealL1', 0),
                    "l2_real": raw_data.get('prealL2', 0),
                    "l3_real": raw_data.get('prealL3', 0)
                }
            },
            ev_charging={
                "total_power": raw_data.get('pev', 0),
                "stations": {
                    "ev1": raw_data.get('pevDetail', {}).get('ev1Power', 0),
                    "ev2": raw_data.get('pevDetail', {}).get('ev2Power', 0),
                    "ev3": raw_data.get('pevDetail', {}).get('ev3Power', 0),
                    "ev4": raw_data.get('pevDetail', {}).get('ev4Power', 0)
                }
            },
            units={
                "power": "W",
                "soc": "%"
            }
        )
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: returns structured snapshot with clear field names/units, and auto-selects system if only one exists when serial is omitted. However, it doesn't mention rate limits, authentication requirements (implied by authenticate_alphaess sibling), or error handling for multiple systems without serial.

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 perfectly structured and concise: purpose statement first, return format second, parameter behavior third. Every sentence earns its place with no wasted words. The Args/Returns sections are clear and appropriately brief.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (so return values are documented elsewhere), no annotations, and simple parameters, the description is quite complete. It covers purpose, usage context, parameter semantics, and return format. The only minor gap is not explicitly mentioning authentication requirements, though this is somewhat implied by the sibling tools.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaningful context for the single parameter: explains that 'serial' is optional, identifies it as the system serial number, and describes the auto-selection behavior when omitted. This goes well beyond the bare schema, though it doesn't specify format constraints (e.g., length, pattern).

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 ('Get the latest real-time power data') and resource ('for a specific Alpha ESS system'), distinguishing it from siblings like get_one_day_power_data (which likely retrieves historical data) and get_alpha_ess_data (which is more generic). The verb+resource combination is precise and unambiguous.

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: for real-time power data, with optional serial parameter that auto-selects if only one system exists. However, it doesn't explicitly state when NOT to use it (e.g., vs. get_one_day_power_data for historical data) or name specific alternatives, keeping it from a perfect score.

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/michaelkrasa/alpha-ess-mcp-server'

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