Skip to main content
Glama
cobanov

teslamate-mcp

get_most_visited_locations

Retrieve the top visited locations for each Tesla vehicle using data from the TeslaMate database, enabling detailed insights into travel patterns.

Instructions

Get the most visited locations for each car.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • main.py:22-28 (handler)
    Factory function that creates an anonymous handler for each tool. The handler executes the SQL query specified in the tool definition by calling db_manager.execute_query_sync(sql_file). This is the core logic for running the get_most_visited_locations 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
  • ToolDefinition dataclass instance that defines the schema for the tool: name, description, and the SQL file path used for execution.
    ToolDefinition( name="get_most_visited_locations", description="Get the most visited locations for each car. Shows frequently visited places with visit counts and durations.", sql_file="most_visited_locations.sql", ),
  • main.py:31-38 (registration)
    Dynamically creates and registers the handler function for each tool, including get_most_visited_locations, with the MCP FastMCP server using the 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)
  • Executes the SQL query loaded from the tool's sql_file synchronously against the PostgreSQL database, returning results as a list of dictionaries.
    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()
  • Loads the SQL query content from the file path (e.g., 'most_visited_locations.sql') in the configured 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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cobanov/teslamate-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server