get_monthly_driving_summary
Retrieve a detailed monthly driving summary for each Tesla vehicle from the TeslaMate database to analyze driving patterns and consumption data.
Instructions
Get the monthly driving summary for each car.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.py:77-81 (schema)Defines the schema and metadata for the 'get_monthly_driving_summary' tool, including name, description, and the SQL query file it uses.ToolDefinition( name="get_monthly_driving_summary", description="Get the monthly driving summary for each car. Provides monthly statistics for distance, energy usage, and costs.", sql_file="monthly_driving_summary.sql", ),
- main.py:22-28 (handler)Factory function that creates the core handler logic for executing the tool's SQL query. This is used to generate the specific handler for 'get_monthly_driving_summary'.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)Registers all tools, including 'get_monthly_driving_summary', with the MCP server by applying the @mcp.tool() decorator to the generated handler function.# 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)
- main_remote.py:118-127 (handler)Async handler function for predefined tools in the remote HTTP MCP server, which executes the SQL for 'get_monthly_driving_summary' based on tool name.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)Registers 'get_monthly_driving_summary' (and other predefined tools) 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": {}}, ) )