get_all_charging_sessions_summary
Retrieve a summary of all charging sessions for each vehicle in your TeslaMate database to analyze energy usage and charging patterns.
Instructions
Get the summary of all charging sessions for each car.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:22-28 (handler)Generic factory function that creates the handler for each tool by executing the corresponding SQL query file synchronously via the database manager.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:31-38 (registration)Loop that dynamically creates a handler instance using the tool's SQL file and registers it with the MCP server using FastMCP.tool() decorator. This registers the get_all_charging_sessions_summary tool.# Register all tools from definitions 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:17-21 (schema)ToolDefinition dataclass instance defining the tool's name, description, and the SQL query file to execute.ToolDefinition( name="get_all_charging_sessions_summary", description="Get the summary of all charging sessions for each car. Returns charging statistics including total sessions, energy consumed, and costs.", sql_file="all_charging_sessions_summary.sql", ),
- src/database.py:27-34 (helper)Executes the SQL query loaded from the specified file path, fetching all results as list of dictionaries. Called by the tool handler.def execute_query_sync(self, sql_file_path: str) -> List[Dict[str, Any]]: """Execute SQL query synchronously""" sql_query = self.read_sql_file(sql_file_path) with psycopg.connect(self.connection_string, row_factory=dict_row) as conn: with conn.cursor() as cur: cur.execute(sql_query) return cur.fetchall()
- src/database.py:21-26 (helper)Reads the content of the SQL file from the queries directory.def read_sql_file(self, file_path: str) -> str: """Read SQL query from file""" full_path = self.queries_dir / file_path with open(full_path, "r") as file: return file.read()