OpenF1 MCP服务器
连接到的模型上下文协议(MCP)服务器 openF1.org API获取公式1数据。此服务器使用stdio传输方法进行通信。
特性
MCP服务器提供工具来获取各种一级方程式数据:
- 驾驶员 -获取驾驶员信息,按季节或驾驶员编号筛选
- 团队 -获取特定赛季的球队数据
- 种族 -按季节或轮次获取比赛信息
- 会话 -获取练习、资格赛和比赛环节
- 结果 -获取按时段或车手筛选的比赛结果
- 圈 -从会话中获取逐圈数据
- 从事某项工作的时间 -获取轮胎限位信息
- 停车加油 -检修坑停止数据
- 天气 -获取会话期间的天气状况
- 事件 -获取惩罚和碰撞数据
- 汽车数据 -访问遥测数据(油门、刹车、DRS等)
- 职位 -在会话期间获取实时位置数据
安装
- 克隆或下载此项目
- 安装依赖项:
pip install -r requirements.txt用法
运行服务器
使用stdio传输启动MCP服务器:
python -m src.server通过Claude连接
要将此服务器与Claude Desktop一起使用,请将其添加到您的 claude_desktop_config.json:
macOS/Linux: ~/.config/claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"openf1": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/openf1_mcp"
}
}
}可用工具
list_drivers
获取F1车手。可选择按季节或驾驶员编号进行筛选。
参数:
season(可选):按季节年份过滤(例如2024年)driver_number(可选):按驾驶员编号筛选
list_teams
获取F1车队。可选择按季节过滤。
参数:
season(可选):按季节年份过滤(例如2024年)
list_race
获取F1比赛。可选择按季节或整数过滤。
参数:
season(可选):按季节和年份过滤round_number(可选):按整数筛选
list_sessions
获取F1赛段(练习、排位赛、比赛)。
参数:
season(可选):按季节和年份过滤round_number(可选):按整数筛选
list_results
获取比赛结果。可选择按会话或驱动程序进行筛选。
参数:
session_key(可选):按会话密钥筛选driver_number(可选):按驾驶员编号筛选
list_laps
从会话中获取圈数数据。
参数:
session_key(可选):用于筛选的会话密钥driver_number(可选):按驾驶员编号筛选
list_strets
获取胎龄数据(轮胎胎龄)。
参数:
session_key(可选):用于筛选的会话密钥driver_number(可选):按驾驶员编号筛选
list_pit_stops
从会话中获取进站数据。
参数:
session_key(可选):用于筛选的会话密钥driver_number(可选):按驾驶员编号筛选
get_weather
获取会话的天气数据。
参数:
session_key:会话密钥
事故列表
获取事件数据(碰撞、处罚等)。
参数:
session_key(可选):会话密钥driver_number(可选):按驾驶员编号筛选
get_car_data
获取汽车遥测数据(油门、刹车、DRS等)。
参数:
session_key(可选):会话密钥driver_number(可选):按驾驶员编号筛选
list_positions
获取位置数据(会话期间的实时位置)。
参数:
session_key(可选):会话密钥driver_number(可选):按驾驶员编号筛选
api参考
本项目使用openF1.org API,该API提供:
- 不要求进行验证
- 免费使用
- 来自F1的开源数据
有关API的更多信息,请访问 openf1.org
项目结构
openf1_mcp/
├── src/
│ ├── __init__.py
│ ├── server.py # Main MCP server implementation
│ ├── openf1_client.py # OpenF1 API client
├── tests/
│ ├── __init__.py
│ ├── conftest.py # Pytest configuration
│ ├── test_openf1_client.py # Client unit tests
│ ├── test_server.py # Server unit tests
│ └── test_integration.py # Integration tests
├── requirements.txt # Python dependencies
├── pytest.ini # Pytest configuration
├── run_tests.py # Test runner script
└── README.md # This file测试
该项目包括综合单元和集成测试。
运行测试
仅限单元测试:
python -m pytest tests/覆盖范围的单元测试:
python -m pytest tests/ --cov=src --cov-report=html集成测试(需要API访问权限):
python -m pytest tests/ --integration使用测试运行器脚本:
python run_tests.py # Run unit tests
python run_tests.py --integration # Run all tests including integration
python run_tests.py --coverage # Run unit tests with coverage report
python run_tests.py --integration --coverage # Run all tests with coverage测试文件
tests/test_openf1_client.py-OpenF1 API客户端测试tests/test_server.py-MCP服务器和工具注册测试tests/test_integration.py-使用真正的API进行集成测试
发展
要使用其他工具扩展服务器,请执行以下操作:
- 添加新方法
OpenF1Client在src/openf1_client.py - 在中添加相应的工具定义
OpenF1MCPServer.get_tools()在src/server.py - 在中添加新工具的处理
_run_tool()方法 - 在中添加测试
tests/test_openf1_client.py和tests/test_server.py
许可证
这个项目是开源的,可以在MIT许可证下使用。
