get_total_distance_and_efficiency
Retrieve lifetime distance traveled and energy efficiency statistics for Tesla vehicles from TeslaMate data.
Instructions
Get the total distance and efficiency for each car. Provides lifetime statistics for distance traveled and energy efficiency.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:22-28 (handler)Factory function that creates the anonymous handler for executing the specific tool's SQL query 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-39 (registration)Dynamic registration of all tools, including get_total_distance_and_efficiency, by creating and decorating their handler functions with mcp.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:97-101 (schema)Tool schema definition specifying the name, description, and SQL query file for the get_total_distance_and_efficiency tool.ToolDefinition( name="get_total_distance_and_efficiency", description="Get the total distance and efficiency for each car. Provides lifetime statistics for distance traveled and energy efficiency.", sql_file="total_distance_and_efficiency.sql", ),
- main_remote.py:118-127 (handler)Async handler function that executes predefined tools, including get_total_distance_and_efficiency, by resolving the tool definition and running its 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 (registration)Registration of tool schemas (name and description) for all predefined tools, including get_total_distance_and_efficiency, in the list_tools method 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": {}}, ) )