足球数据API服务

一个通过API-Football服务提供足球数据的模型上下文协议(MCP)服务器,支持自然语言查询。

  • by dankniight
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 dankniight/api-football-mcp-server

使用说明

API-足球MCP服务器

模型上下文协议(MCP)服务器,通过API-football服务提供对足球/足球数据的访问。 这为语言模型与此API交互创建了一种标准化的方式,并为用户提供了一种用自然语言进行查询的方式。

建筑

graph TD
    LLM["`**LLM with MCP Client**
    Claude/GPT-4/etc.`"]
    
    subgraph Server ["`**MCP Server**
    Football Data Gateway`"]
        direction TB
        MCP["`**MCP Protocol Handler**
        Request Router & Response Manager`"]
        
        subgraph Functions ["`**Available Functions**`"]
            direction LR
            API1["`**get_leagues**
            Fetch league data`"]
            API2["`**get_teams**
            Fetch team data`"] 
            API3["`**get_players**
            Fetch player data`"]
            API4["`**get_fixtures**
            Fetch match data`"]
        end
        
        MCP --> Functions
    end
    
    ExtAPI["`**API-Football**
    External Sports Data API`"]
    
    %% Main connections
    LLM <===> MCP
    
    %% Function connections to external API
    API1 <--> ExtAPI
    API2 <--> ExtAPI
    API3 <--> ExtAPI
    API4 <--> ExtAPI
    
    %% Styling with improved colors
    classDef llm fill:#4CAF50,stroke:#2E7D32,stroke-width:3px,color:#fff
    classDef mcp fill:#2196F3,stroke:#1565C0,stroke-width:2px,color:#fff
    classDef functions fill:#FF9800,stroke:#F57C00,stroke-width:2px,color:#fff
    classDef external fill:#9C27B0,stroke:#6A1B9A,stroke-width:3px,color:#fff
    classDef server fill:#E3F2FD,stroke:#1976D2,stroke-width:2px,color:#1976D2
    
    class LLM llm
    class MCP mcp
    class API1,API2,API3,API4 functions
    class ExtAPI external
    class Server server

1.克隆和设置

克隆存储库:

git clone https://github.com/danknight/api-football-mcp-server.git
cd api-football-mcp-server

安装依赖项:

pip install -r requirements.txt

2.获取API密钥并设置环境

创建一个 .env 使用您的凭据文件:

API_FOOTBALL_KEY=your_api_key_here

注册 API-足球 以获取API密钥。

3.配置MCP客户端

在您的MCP客户端中注册此服务器(例如Cursor、Claude for Desktop)。

{
  "mcpServers": {
    "api-football": {
      "command": "python",
      "args": ["absolute/path/to/server.py"],
      "env": {
        "API_FOOTBALL_KEY": "YOUR_API_KEY"
      }
    }
  }
}

或者直接从命令行运行并使用 检查员:

python server.py

工具

MCP客户端可以使用以下工具:

联盟信息

工具名称 描述 参数
get_leagues 获取可用联赛 country (str,可选), season (int,可选)
get_league_info 获取详细的联盟信息 league_id (int)
get_countries 获取可用国家/地区 无
get_standings 获取联赛排名 league_id (int), season (int)

团队信息

工具名称 描述 参数
get_teams 让球队加入联盟 league_id (int), season (int,可选)
get_team_stats 获取团队的统计数据 team_id (int), league_id (int), season (int,可选)
get_team_id_by_name 按团队名称获取团队ID team_name (str), league_id (int,可选), season (int,可选)
get_team_transfers 获取团队的转会信息 team_id (int)

玩家信息

工具名称 描述 参数
get_players 让球员加入团队 team_id (int), season (int)
get_player_stats 获取玩家的统计数据 player_id (int), season (int)

比赛/赛程信息

工具名称 描述 参数
get_fixtures 获取赛程/比赛 league_id (int,可选), team_id (int,可选), season (int,可选), date (str,可选), next (int,可选), last (int,可选)
get_fixture_stats 获取夹具的统计数据 fixture_id (int)
get_predictions 获取赛程预测 fixture_id (int)
get_head_to_head 获取团队之间的直接统计数据 team1_id (int), team2_id (int)

球员统计

工具名称 描述 参数
get_top_scorers 在联盟中获得最高得分者 league_id (int), season (int)
get_top_assists 获得联盟中的顶级助理 league_id (int), season (int)

其他信息

工具名称 描述 参数
get_venue 获取会场信息 venue_id (int)
get_injuries 获取受伤信息 team_id (int), player_id (int), season (int)

使用示例

获取特定国家的联赛

get_leagues(country="England")

在特定联赛中组建球队

get_teams(league_id=39, season=2023)  # Premier League 2023

获取团队统计数据

get_team_stats(team_id=42, league_id=39, season=2023)  # Arsenal stats

为团队获取固定装置

get_fixtures(team_id=42, next=5)  # Next 5 Arsenal matches

在联盟中获得最高得分者

get_top_scorers(league_id=39, season=2023)  # Premier League top scorers

发展

运行测试

目前,尚未实施任何测试。要添加测试,请执行以下操作:

  1. 创建一个 tests/ 目录
  2. 按照命名约定添加测试文件 test_*.py
  3. 使用运行测试 python -m pytest

添加新工具

要添加新工具,请执行以下操作:

  1. 在中添加新功能 main.py 装饰有 @mcp.tool()
  2. 使用实现API调用 make_api_request()
  3. 用新的工具信息更新此README
  4. 使用MCP检查器测试工具