get_session_results
Retrieve Formula 1 session results for practice, qualifying, or race by specifying year, round number, and session type.
Instructions
Get results for a specific F1 session (practice, qualifying, or race)
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 |
Implementation Reference
- f1_mcp_server/server.py:257-317 (handler)The asynchronous function `get_session_results` that fetches session data using FastF1, processes it into a list of dictionaries, and returns the result wrapped in a `TextContent` object.
async def get_session_results(arguments: Dict[str, Any]) -> List[TextContent]: """Get session results.""" year = arguments["year"] round_number = arguments["round_number"] session_type = arguments["session"] try: session = fastf1.get_session(year, round_number, session_type) session.load() results = session.results # Convert results to readable format results_data = [] for _, driver in results.iterrows(): results_data.append( { "position": ( int(driver["Position"]) if pd.notna(driver["Position"]) else None ), "driver_number": ( int(driver["DriverNumber"]) if pd.notna(driver["DriverNumber"]) else None ), "driver": driver["Abbreviation"], "full_name": driver["FullName"], "team": driver["TeamName"], "time": str(driver["Time"]) if pd.notna(driver["Time"]) else None, "status": driver["Status"] if "Status" in driver else None, "points": ( float(driver["Points"]) if pd.notna(driver.get("Points", 0)) else 0 ), } ) result = { "year": year, "round": round_number, "session": session_type, "event_name": session.event["EventName"], "location": session.event["Location"], "results": results_data, } return [ TextContent( type="text", text=f"F1 {year} Round {round_number} {session_type} Results:\n\n" + json.dumps(result, indent=2), ) ] except Exception as e: return [ TextContent(type="text", text=f"Error getting session results: {str(e)}") ] - f1_mcp_server/server.py:87-111 (schema)The `Tool` definition for `get_session_results`, which defines the input schema (year, round_number, session).
Tool( name="get_session_results", description="Get results for a specific F1 session (practice, qualifying, or race)", inputSchema={ "type": "object", "properties": { "year": { "type": "integer", "description": "Season year (e.g., 2024)", }, "round_number": { "type": "integer", "description": "Round number (1-24)", "minimum": 1, "maximum": 24, }, "session": { "type": "string", "description": "Session type", "enum": ["FP1", "FP2", "FP3", "Q", "R"], }, }, "required": ["year", "round_number", "session"], }, ), - f1_mcp_server/server.py:188-189 (registration)The call handler logic inside `call_tool` that routes the `get_session_results` tool name to its handler function.
elif name == "get_session_results": return await get_session_results(arguments)