Skip to main content
Glama
notsedano

Formula One MCP Server

get_event_schedule

Retrieve the Formula One race calendar for a specific season to view event schedules and dates.

Instructions

Get Formula One race calendar for a specific season

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yearYesSeason year (e.g., 2023)

Implementation Reference

  • Core handler function that implements the get_event_schedule tool logic: validates year, fetches schedule from fastf1, serializes data to JSON-compatible format, and returns structured response.
    def get_event_schedule(year: Any) -> dict[str, Any]:
        """
        Get the event schedule for a specified Formula One season.
    
        Args:
            year (int or str): The year of the F1 season
    
        Returns:
            dict: Status and schedule data or error information
        """
        try:
            # Validate year
            year_int = validate_year(year)
    
            logger.debug(f"Fetching event schedule for {year_int}")
            schedule = fastf1.get_event_schedule(year_int)
    
            # Convert DataFrame to JSON serializable format
            result = []
            for _, row in schedule.iterrows():
                event_dict = row.to_dict()
                # Clean and convert non-serializable values
                clean_dict = {k: json_serial(v) for k, v in event_dict.items()}
                result.append(clean_dict)
    
            logger.info(f"Successfully retrieved {len(result)} events for {year_int}")
            return {"status": "success", "data": result}
        except Exception as e:
            logger.error(f"Error retrieving event schedule: {str(e)}", exc_info=True)
            return {
                "status": "error",
                "message": f"Failed to retrieve event schedule: {str(e)}",
            }
  • MCP tool registration in the server's list_tools() method, including name, description, and input schema.
    types.Tool(
        name="get_event_schedule",
        description=("Get Formula One race calendar for a specific season"),
        inputSchema={
            "type": "object",
            "properties": {
                "year": {
                    "type": "number",
                    "description": "Season year (e.g., 2023)",
                },
            },
            "required": ["year"],
        },
  • Input schema definition for the get_event_schedule tool, specifying required 'year' parameter as number.
        "type": "object",
        "properties": {
            "year": {
                "type": "number",
                "description": "Season year (e.g., 2023)",
            },
        },
        "required": ["year"],
    },
  • Dispatch handler in the MCP server's call_tool method that routes to get_event_schedule with sanitized arguments.
    if name == "get_event_schedule":
        if "year" not in sanitized_args:
            sanitized_args["year"] = int(arguments["year"])
        result = get_event_schedule(sanitized_args["year"])
  • Helper function used by get_event_schedule to validate and normalize the year input parameter.
    def validate_year(year: Any) -> int:
        """
        Validate that the provided year is valid for F1 data.
    
        Args:
            year: Year value to validate
    
        Returns:
            Valid year as integer
    
        Raises:
            ValueError: If year is invalid
        """
        try:
            year_int = int(year)
            # F1 started in 1950 and we don't want future years far ahead
            current_year = datetime.now().year
            if year_int < 1950 or year_int > current_year + 1:
                raise ValueError(f"Year must be between 1950 and {current_year + 1}")
            return year_int
        except (ValueError, TypeError) as e:
            raise ValueError(f"Invalid year format: {year}") from e

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

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