File size: 5,117 Bytes
44e58a6
 
3b19a8f
6269c32
 
 
3b19a8f
 
 
c6542ed
3b19a8f
 
 
 
c6542ed
44e58a6
 
 
6269c32
44e58a6
6269c32
 
44e58a6
6269c32
95e43e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655dcc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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.
<br>
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 information about a specific endpoint - `get_api_endpoint(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```

"""