Skip to main content
Glama
Machine-To-Machine

Formula One MCP Server (Python)

get_telemetry

Retrieve telemetry data for a Formula One lap by specifying year, event, session, driver, and optional lap number. If no lap number is given, the fastest lap is returned.

Instructions

Get telemetry data for a specific Formula One lap

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yearYesSeason year (e.g., 2023)
event_identifierYesEvent name or round number (e.g., 'Monaco' or '7')
session_nameYesSession name (e.g., 'Race', 'Qualifying', 'Sprint', 'FP1', 'FP2', 'FP3')
driver_identifierYesDriver identifier (number, code, or name; e.g., '44', 'HAM', 'Hamilton')
lap_numberNoLap number (optional, gets fastest lap if not provided)

Implementation Reference

  • The actual implementation of get_telemetry: calls fastf1 to load session/laps, picks the driver's specific lap number or fastest lap, retrieves telemetry data, serializes it with json_serial, and returns status+data
    def get_telemetry(
        year, event_identifier, session_name, driver_identifier, lap_number=None
    ):
        """
        Get telemetry data for a specific lap or fastest lap.
    
        Args:
            year (int or str): The year of the F1 season
            event_identifier (str): Event name or round number
            session_name (str): Session type (Race, Qualifying, Sprint, etc.)
            driver_identifier (str): Driver number, code, or name
            lap_number (int, optional): Specific lap number or None for fastest lap
    
        Returns:
            dict: Status and telemetry data or error information
        """
        try:
            year = int(year)
            session = fastf1.get_session(year, event_identifier, session_name)
            session.load()
    
            # Get laps for the specified driver
            driver_laps = session.laps.pick_driver(driver_identifier)
    
            if len(driver_laps) == 0:
                return {
                    "status": "error",
                    "message": f"No laps found for driver {driver_identifier}",
                }
    
            # Get the specific lap or fastest lap
            if lap_number:
                matching_laps = driver_laps[driver_laps["LapNumber"] == int(lap_number)]
                if len(matching_laps) == 0:
                    return {
                        "status": "error",
                        "message": (
                            f"Lap number {lap_number} not found for driver "
                            f"{driver_identifier}"
                        ),
                    }
                lap = matching_laps.iloc[0]
            else:
                lap = driver_laps.pick_fastest()
                if lap is None:
                    return {
                        "status": "error",
                        "message": "No valid fastest lap found for driver "
                        f"{driver_identifier}",
                    }
    
            # Get telemetry data
            telemetry = lap.get_telemetry()
    
            # Convert to JSON serializable format
            telemetry_dict = telemetry.to_dict(orient="records")
            clean_data = []
    
            for item in telemetry_dict:
                clean_item = {k: json_serial(v) for k, v in item.items()}
                clean_data.append(clean_item)
    
            # Add lap information
            lap_info = {
                "LapNumber": int(lap["LapNumber"])
                if not pd.isna(lap["LapNumber"])
                else None,
                "LapTime": str(lap["LapTime"]) if not pd.isna(lap["LapTime"]) else None,
                "Compound": lap["Compound"] if not pd.isna(lap["Compound"]) else None,
                "TyreLife": int(lap["TyreLife"]) if not pd.isna(lap["TyreLife"]) else None,
            }
    
            result = {"lapInfo": lap_info, "telemetry": clean_data}
    
            return {"status": "success", "data": result}
        except Exception as e:
            return {"status": "error", "message": str(e)}
  • Input schema registration for the 'get_telemetry' tool: defines properties year (number), event_identifier (string), session_name (string), driver_identifier (string), lap_number (optional number)
    types.Tool(
        name="get_telemetry",
        description=("Get telemetry data for a specific Formula One lap"),
        inputSchema={
            "type": "object",
            "properties": {
                "year": {
                    "type": "number",
                    "description": "Season year (e.g., 2023)",
                },
                "event_identifier": {
                    "type": "string",
                    "description": (
                        "Event name or round number (e.g., 'Monaco' or '7')"
                    ),
                },
                "session_name": {
                    "type": "string",
                    "description": (
                        "Session name (e.g., 'Race', 'Qualifying', "
                        "'Sprint', 'FP1', 'FP2', 'FP3')"
                    ),
                },
                "driver_identifier": {
                    "type": "string",
                    "description": (
                        "Driver identifier (number, code, or name; "
                        "e.g., '44', 'HAM', 'Hamilton')"
                    ),
                },
                "lap_number": {
                    "type": "number",
                    "description": (
                        "Lap number (optional, gets fastest lap if not "
                        "provided)"
                    ),
                },
            },
            "required": [
                "year",
                "event_identifier",
                "session_name",
                "driver_identifier",
            ],
        },
    ),
  • Handler dispatch block: routes the name 'get_telemetry' to the get_telemetry function, validates lap_number, and passes sanitized arguments
    elif name == "get_telemetry":
        lap_number = arguments.get("lap_number")
        if lap_number is not None:
            try:
                lap_number = int(lap_number)
                if lap_number <= 0:
                    raise ValueError("Lap number must be positive")
            except (ValueError, TypeError) as e:
                raise ValueError(f"Invalid lap number: {lap_number}") from e
    
        result = get_telemetry(
            sanitized_args["year"],
            str(arguments["event_identifier"]),
            str(arguments["session_name"]),
            str(arguments["driver_identifier"]),
            lap_number,
        )
  • Import of get_telemetry from f1_data module into server.py
    get_telemetry,
  • The json_serial helper used by get_telemetry to convert non-JSON serializable objects (timestamps, numpy types, NaN) to JSON-safe values
    def json_serial(obj: Any) -> str | int | float | None:
        """
        Convert non-JSON serializable objects to strings.
    
        Args:
            obj: Object to be serialized to JSON
    
        Returns:
            JSON serializable representation of the object
        """
        if isinstance(obj, datetime | pd.Timestamp):
            return obj.isoformat()
        if isinstance(obj, np.integer):
            return int(obj)
        if isinstance(obj, np.floating):
            return float(obj)
        if pd.isna(obj) or obj is None:
            return None
        return str(obj)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose behavioral traits. However, it only states the action and resource, omitting information about permissions, rate limits, data format, or potential errors. The agent lacks context about what 'telemetry data' entails or any side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that directly conveys the tool's purpose without any extraneous words. It is well-structured and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of an output schema and the moderate complexity (5 parameters), the description fails to explain what telemetry data is returned (e.g., speed, throttle, braking), nor does it cover return format or units. This is insufficient for an agent to correctly interpret the tool's response.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, providing descriptions for each parameter. The tool description adds little beyond 'specific lap', which is already implied by the 'lap_number' parameter description. Baseline score of 3 is appropriate as the description does not enhance parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'telemetry data for a specific Formula One lap'. It is specific enough to differentiate from sibling tools like 'get_driver_info' or 'get_session_results', though it does not explicitly compare to them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites, context, or exclusions. For example, it doesn't clarify that this tool is for detailed telemetry versus aggregated performance data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Machine-To-Machine/f1-mcp-server'

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