get_lap_times
Retrieve lap time data for Formula 1 sessions to analyze driver performance and session results by specifying season, round, and session type.
Instructions
Get lap times for a specific session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | Yes | Season year (e.g., 2024) | |
| round_number | Yes | Round number (1-24) | |
| session | Yes | Session type | |
| driver | No | Driver abbreviation (optional, e.g., 'VER', 'HAM') |
Implementation Reference
- f1_mcp_server/server.py:466-506 (handler)The main handler function for the get_lap_times tool, which fetches lap times using FastF1.
async def get_lap_times(arguments: Dict[str, Any]) -> List[TextContent]: """Get lap times for a session.""" year = arguments["year"] round_number = arguments["round_number"] session_type = arguments["session"] driver_filter = arguments.get("driver") try: session = fastf1.get_session(year, round_number, session_type) session.load() laps = session.laps # Filter by driver if specified if driver_filter: laps = laps[laps["Driver"] == driver_filter.upper()] # Convert lap times to readable format lap_data = [] for _, lap in laps.iterrows(): lap_data.append( { "lap_number": ( int(lap["LapNumber"]) if pd.notna(lap["LapNumber"]) else None ), "driver": lap["Driver"], "team": lap["Team"], "lap_time": ( str(lap["LapTime"]) if pd.notna(lap["LapTime"]) else None ), "sector_1": ( str(lap["Sector1Time"]) if pd.notna(lap.get("Sector1Time")) else None ), "sector_2": ( str(lap["Sector2Time"]) if pd.notna(lap.get("Sector2Time")) else None ), "sector_3": ( - f1_mcp_server/server.py:152-168 (registration)Tool definition and registration for get_lap_times.
Tool( name="get_lap_times", description="Get lap times for a specific session", inputSchema={ "type": "object", "properties": { "year": { "type": "integer", "description": "Season year (e.g., 2024)", }, "round_number": { "type": "integer", "description": "Round number (1-24)", }, "session": { "type": "string", "description": "Session type",