get_unusual_power_consumption
Identify anomalies in vehicle power consumption to detect potential issues by analyzing TeslaMate data for unusual usage patterns.
Instructions
Get the unusual power consumption for each car. Identifies anomalies in power usage that might indicate issues.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:22-28 (handler)Factory function that creates the core handler for the tool. The inner 'handler' function executes the SQL query from 'unusual_power_consumption.sql' using the database manager synchronously.def create_tool_handler(sql_file: str): """Factory function to create tool handlers""" def handler() -> List[Dict[str, Any]]: return db_manager.execute_query_sync(sql_file) return handler
- main.py:32-38 (registration)Registers the handler for 'get_unusual_power_consumption' (and all tools) with the FastMCP server using stdio transport by dynamically creating and decorating the tool function.for tool_def in TOOL_DEFINITIONS: tool_func = create_tool_handler(tool_def.sql_file) tool_func.__doc__ = tool_def.description tool_func.__name__ = tool_def.name # Register the tool with the MCP server mcp.tool()(tool_func)
- src/tools.py:102-106 (registration)ToolDefinition entry that registers 'get_unusual_power_consumption' with its description and the SQL file containing the query logic.ToolDefinition( name="get_unusual_power_consumption", description="Get the unusual power consumption for each car. Identifies anomalies in power usage that might indicate issues.", sql_file="unusual_power_consumption.sql", ),
- main_remote.py:118-127 (handler)Async handler function for predefined tools including 'get_unusual_power_consumption' in the remote HTTP MCP server. Retrieves the tool definition and executes the SQL query asynchronously.async def execute_predefined_tool(tool_name: str) -> List[Dict[str, Any]]: """Execute a predefined tool by name""" if not app_context: raise RuntimeError("Application context not initialized") tool = get_tool_by_name(tool_name) return await app_context.db_manager.execute_query_async( tool.sql_file, app_context.db_pool )
- main_remote.py:178-186 (schema)Defines the input schema (empty object, parameterless tool) and registers the tool description in the list_tools endpoint for the remote MCP server.# Add all predefined tools for tool_def in TOOL_DEFINITIONS: tools.append( types.Tool( name=tool_def.name, description=tool_def.description, inputSchema={"type": "object", "properties": {}}, ) )