Skip to main content
Glama
Machine-To-Machine

Formula One MCP Server (Python)

get_event_schedule

Retrieves the Formula One race calendar for a specified season year. Provide a year to get all event dates and locations.

Instructions

Get Formula One race calendar for a specific season

Input Schema

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

Implementation Reference

  • The core handler function for 'get_event_schedule'. It validates the year using validate_year(), calls fastf1.get_event_schedule(year_int), converts the resulting DataFrame to a JSON-serializable list of dicts, and returns {'status': 'success', 'data': result} or {'status': 'error', 'message': ...} on failure.
    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)}",
            }
  • Tool registration with input schema for 'get_event_schedule'. Defines the tool name, description, and inputSchema requiring a 'year' property of type 'number'.
    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"],
        },
    ),
  • Registration of 'get_event_schedule' in the list_tools() function returning the Tool object with name, description, and inputSchema.
    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"],
        },
    ),
  • The validate_year() helper function used by get_event_schedule to ensure the year is a valid integer between 1950 and current_year+1.
    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
  • The json_serial() helper used by get_event_schedule to convert non-JSON-serializable objects (datetime, Timestamp, numpy types, NaN) to serializable 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)
Behavior3/5

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

No annotations are provided, so the description must disclose all behavioral traits. It states a simple read operation but does not mention any specifics such as data freshness, caching, rate limits, or whether the calendar includes future races only.

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, front-loaded sentence with no unnecessary words. It efficiently conveys the tool's purpose.

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

Completeness4/5

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

For a simple one-parameter tool with no output schema, the description is largely adequate. However, it could hint at the return format (e.g., 'list of events with dates') to help the agent set expectations.

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%, and the description adds no additional meaning beyond the schema's description of the 'year' parameter. The description reiterates 'specific season' but does not provide format or constraints beyond what the schema already offers.

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

Purpose5/5

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

The description clearly states the verb 'Get', the resource 'Formula One race calendar', and the scope 'for a specific season'. It distinguishes from siblings like get_event_info (specific event) and get_championship_standings (standings) by focusing on the full schedule.

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

Usage Guidelines3/5

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

The description implies that this tool is for retrieving an entire season's calendar, but it does not explicitly state when to use this over alternatives like get_event_info or get_session_results. No exclusions or prerequisites are mentioned.

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