get_charging_by_location
Analyze Tesla vehicle charging patterns and statistics grouped by location to understand charging behavior and optimize energy usage.
Instructions
Get the charging by location for each car. Shows charging patterns and statistics grouped by location.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.py:42-46 (schema)ToolDefinition specifying the name, description, and SQL query file for the get_charging_by_location tool.ToolDefinition( name="get_charging_by_location", description="Get the charging by location for each car. Shows charging patterns and statistics grouped by location.", sql_file="charging_by_location.sql", ),
- main.py:22-28 (handler)Factory function that creates the anonymous handler executed when the tool is called, which runs the SQL query corresponding to the tool.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-39 (registration)Dynamically creates and registers the handler function for get_charging_by_location (and all tools) with the FastMCP server using mcp.tool() decorator.# 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/database.py:27-34 (helper)Core helper method invoked by the tool handler to load and execute the SQL query from 'charging_by_location.sql' file and return results as list of dicts.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()