import json import datetime # Variables CURRENT_YEAR = datetime.datetime.now().year AVAILABLE_SESSION_TYPES = [ "fp1", "fp2", "fp3", "q", "s", "ss", "sq", "r", "practice 1", "practice 2", "practice 3", "sprint", "sprint qualifying", "qualifying", "race" ] DROPDOWN_SESSION_TYPES = [ "practice 1", "practice 2", "practice 3", "sprint", "sprint qualifying", "qualifying", "race" ] # Load in driver names DRIVER_NAMES: list[str] = json.load(open("assets/driver_names.json"))["drivers"] # Load in constructor team names CONSTRUCTOR_NAMES: list[str] = json.load(open("assets/constructors.json"))["constructors"] # Load in driver details DRIVER_DETAILS: dict[str, dict[str, str]] = json.load(open("assets/driver_details.json")) # Load in constructor details CONSTRUCTOR_DETAILS: dict[str, dict[str, str]] = json.load(open("assets/constructor_details.json")) MARKDOWN_INTRODUCTION = """ # 🏁 Formula 1 MCP server 🏎️ Welcome to the Formula 1 MCP server, your one-stop destination for comprehensive Formula 1 data and visualizations.
This application leverages the FastF1 library to provide detailed insights into Formula 1 races, drivers, and teams. ## Available Tools in Gradio UI ### Championship Standings - **Driver Championship**: Track driver positions, points, and wins - **Constructor Championship**: Monitor team performances and rankings ### Race Information - **Event Info**: Get detailed information about specific Grand Prix events - **Season Calendar**: View the complete race calendar for any season - **Session Results**: Access race, qualifying, and sprint session results ### Driver & Team Data - **Driver Info**: View detailed driver profiles and statistics - **Track Visualizations**: Explore interactive track maps with speed, gear, and corner data ## Usage There are different ways to interact with the MCP server: 1) (recommended) Add the MCP server to your `mcp.json` file. This is the most user-friendly way to interact with the MCP server. See the section below for the config file. 2) (not recommended) One can establish an MCP client by running `mcp_client.py` locally. This client is connected to the MCP server hosted on HuggingFace spaces. Warning: I personally had trouble getting this to work properly using local Ollama models. 3) (limited functionality) One can also use the Gradio interface directly to interact with the MCP server. However, I have limited the number of tools/functions available in the Gradio interface due to there not being a clean and nice way to implement the `OpenF1` tools in Gradio (literally just direct HTTP endpoints with tons of filters xD). ## MCP json configuration For MCP clients that support SSE transport (For Claude desktop see below), the following configuration can be used in your `mcp.json` file (or its equivalent): ```json { "mcpServers": { "gradio": { "url": "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse" } } } ``` For Claude Desktop, the following configuration can instead be used, but make sure you have Node.js installed: ```json { "mcpServers": { "gradio": { "command": "npx", "args": [ "mcp-remote", "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse", "--transport", "sse-only" ] } } } ``` """ OPENF1_TOOL_DESCRIPTION = """ ## OpenF1 Tools - API Endpoints. This UI Interface/Tab collects all the MCP tools that are based on the `OpenF1` API, which are a bit more advanced compared to the other UI tabs that are implemented using the FastF1 library. In essence, the tools listed below make it possible to access the `OpenF1` API directly within the MCP server, thus allowing a LLM to interact with the `OpenF1` API. The **_OpenF1_** API exposes several **_endpoints_** that can be used to access different types of real-time and historical data about Formula 1 races, drivers, and teams. Each of these endpoints have different **_filters_** that can be used to filter the data returned by the endpoint. The data passed and returned is entirely in JSON format. The implemented functions make it possible to: - Get all available endpoints - `get_api_endpoints()` - Get api string for a specific endpoint - `get_api_endpoint(endpoint)` - Get details about a specific endpoint - `get_endpoint_info(endpoint)` - Get information about a specific filter - `get_filter_info(filter_name)` - Get a filter string for a specific filter - `get_filter_string(filter_name, filter_value, operator)` - Apply filters to an API string - `apply_filters(api_string, *filters)` - Send a request to the OpenF1 API - `send_request(api_string)` """ MARKDOWN_OPENF1_EXAMPLES = """ ```https://api.openf1.org/v1/car_data?driver_number=55&session_key=9159&speed>=315``` ```https://api.openf1.org/v1/drivers?driver_number=1&session_key=9158``` ```https://api.openf1.org/v1/intervals?session_key=9165&interval<0.005``` ```https://api.openf1.org/v1/laps?session_key=9161&driver_number=63&lap_number=8``` ```https://api.openf1.org/v1/meetings?year=2023&country_name=Singapore``` ```https://api.openf1.org/v1/pit?session_key=9158&pit_duration<31``` """