MarvDann/api-football-mcp
If you are the rightful owner of api-football-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The API-Football MCP Server provides comprehensive Premier League football data from 1992 to the present, integrating with the API-Sports API-Football service.
APIāFootball MCP Server
A Model Context Protocol (MCP) server that provides Premier League data via APIāSportsā APIāFootball v3. Written in TypeScript with strict type checking, resilient error handling, and sensible caching for agent workflows.
Features
- Historical Coverage: Premier League historical data (commonly 2002āpresent for many endpoints; some tools support 1992+ when data is available)
- Real-time Data: Live match events, current standings, and fixture information
- Intelligent Caching: LRU cache with TTL for optimal performance
- Rate Limiting: Built-in rateālimit tracking and exponential backoff
- MCP Integration: Native Model Context Protocol support for LLM integration
- TypeScript: Strict TypeScript (noUncheckedIndexedAccess, exactOptionalPropertyTypes)
MCP Tools
Tool | Description | Parameters |
---|---|---|
get_standings | Get Premier League standings | season? (number) |
get_fixtures | Get match fixtures | season? , teamId? , date? , from? , to? , status? , round? |
get_team | Get team information and optional season squad | teamId? or name? , season? |
get_player | Get player profile and statistics | playerId? or name? , season? |
get_match_goals | Get goal events for a match | fixtureId (required) |
get_match_events | Get all events for a match | fixtureId (required) |
get_squad | Get a team's squad for a season | teamId (required), season (required) |
search_teams | Search for teams by name | query? , season? |
search_players | Search for players | query (required), team? , season? , page? |
get_live_matches | Get currently live matches | None |
get_rate_limit | Get current API rate-limit status | None |
Data Coverage Notes
- Historical coverage for the English Premier League via APIāFootball v3 is commonly available from the 2002 season onwards. Earlier seasons (preā2002) may be incomplete or unavailable depending on the specific endpoint.
- If you need seasonāspecific squads, use
season
withget_team
(internally uses the/players
endpoint) or the CLI--endpoint squad team=<id> season=<YYYY>
helper. - Fixture queries support
round
in the form"Regular Season - N"
in addition toseason
,date
, andfrom
/to
.
Installation
Prerequisites
- Node.js 22+
- pnpm package manager
- APIāFootball API key from APIāSports
Setup
-
Clone the repository
git clone https://github.com/MarvDann/api-football-mcp.git cd api-football-mcp
-
Install dependencies
pnpm install
-
Configure environment
# Set your API key as an environment variable export API_FOOTBALL_KEY=your_api_key_here # Or create a .env file echo "API_FOOTBALL_KEY=your_api_key_here" > .env
-
Build the project
pnpm run build
Usage
As MCP Server
The primary use case is as an MCP server for LLM integration:
# Start the MCP server
pnpm start
# Or run directly
node dist/server.js
MCP Client Configuration
Below are example configurations for popular MCP-capable agents. All examples launch this server over stdio. Replace ${API_FOOTBALL_KEY} with your key or rely on your shell environment.
- Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"api-football": {
"command": "node",
"args": ["dist/server.js"],
"env": {
"API_FOOTBALL_KEY": "${API_FOOTBALL_KEY}",
"NODE_ENV": "production",
"LOG_TO_FILE": "true",
"LOG_DIR": "./logs",
"LOG_ROTATE_INTERVAL": "1d"
}
}
}
}
- Claude Code (VS Code settings.json):
{
"claudeCode.mcpServers": [
{
"name": "api-football",
"command": "node",
"args": ["dist/server.js"],
"env": {
"API_FOOTBALL_KEY": "${API_FOOTBALL_KEY}",
"NODE_ENV": "production",
"LOG_TO_FILE": "true",
"LOG_DIR": "./logs"
}
}
]
}
- Cursor (settings JSON):
{
"mcpServers": {
"api-football": {
"command": "node",
"args": ["dist/server.js"],
"env": {
"API_FOOTBALL_KEY": "${API_FOOTBALL_KEY}",
"NODE_ENV": "production",
"LOG_TO_FILE": "true",
"LOG_DIR": "./logs"
}
}
}
}
- Gemini (CLI/desktop MCP support):
{
"mcpServers": {
"api-football": {
"command": "node",
"args": ["dist/server.js"],
"env": {
"API_FOOTBALL_KEY": "${API_FOOTBALL_KEY}",
"NODE_ENV": "production",
"LOG_TO_FILE": "true",
"LOG_DIR": "./logs"
}
}
}
}
- Codex CLI (local agent):
{
"mcpServers": {
"api-football": {
"command": "node",
"args": ["dist/server.js"],
"env": {
"API_FOOTBALL_KEY": "${API_FOOTBALL_KEY}",
"NODE_ENV": "production",
"LOG_TO_FILE": "true",
"LOG_DIR": "./logs"
}
}
}
}
Tools available to agents include: get_standings, get_fixtures, get_team, get_player, get_squad, get_match_goals, get_match_events, get_live_matches, search_teams, search_players, get_rate_limit.
CLI Tools
Server Management
# Start server with custom settings
node dist/cli/server.js start --log-level debug --verbose
# Check server health
node dist/cli/server.js health
# Validate configuration
node dist/cli/server.js validate --dry-run
# List available MCP tools
node dist/cli/server.js tools
# Show cache statistics
node dist/cli/server.js cache --verbose
API Client CLI
# Get current season standings
node dist/cli/api-client.js --endpoint standings
# Get fixtures for a specific date range
node dist/cli/api-client.js --endpoint fixtures season=2023 from=2023-01-01 to=2023-01-31
# Search for a team
node dist/cli/api-client.js --endpoint teams search="Arsenal"
# Get player information
node dist/cli/api-client.js --endpoint player id=276 --format table
# Get goal events for a fixture
node dist/cli/api-client.js --endpoint goals fixture=123456 --format table
# Check rate limit status
node dist/cli/api-client.js --endpoint rate-limit --format table
Cache Management CLI
# View cache statistics
node dist/cli/cache.js stats --format table
# List cached keys
node dist/cli/cache.js keys
# Find keys by pattern
node dist/cli/cache.js find "standings:*"
# Clear cache
node dist/cli/cache.js clear
# Get specific cached value
node dist/cli/cache.js get "standings:2023"
Configuration
Environment Variables
Variable | Description | Default |
---|---|---|
API_FOOTBALL_KEY | Required. Your API-Football API key | - |
NODE_ENV | Environment mode | development |
LOG_LEVEL | Logging level (debug, info, warn, error) | info |
LOG_FORMAT | Log format (json, text) | json |
LOG_TO_FILE | Enable file logging (pino) | false |
LOG_DIR | Directory for logs when LOG_TO_FILE=true | ./logs |
LOG_ROTATE_INTERVAL | Rotation interval (when rotating transport available) | 1d |
LOG_ROTATE_SIZE | Rotation size threshold (when available) | 10M |
CACHE_MAX_SIZE | Maximum cache entries | 1000 |
CACHE_TTL | Cache TTL in milliseconds | 300000 (5 minutes) |
API_TIMEOUT | API request timeout in milliseconds | 15000 (15 seconds) |
API_BASE_URL | API-Football base URL | https://v3.football.api-sports.io |
Cache Policies
The server uses different cache TTL values based on data type:
- Historical data (past seasons): 24 hours
- Current season data: 5 minutes
- Live match data: 30 seconds
- Static data (teams, players): 1 hour
Development
Scripts
# Development
pnpm run dev # Watch mode with hot reload
pnpm run build # Build TypeScript
pnpm run lint:check # Run ESLint (no fix)
pnpm run lint # Run ESLint with --fix
pnpm run test # Run all tests
# Offline test suite (no real API calls)
pnpm run test:offline # unit + contract + performance (mocked)
# Online tests (may hit API-Football; respect rate limits)
pnpm run test:online
# Run specific categories
pnpm run test:unit
pnpm run test:contract
pnpm run test:performance
pnpm run test:integration
# Type checking
pnpm run check-types # Type check without emitting
Project Structure
src/
āāā models/ # TypeScript interfaces
ā āāā league.ts # League data models
ā āāā team.ts # Team and venue models
ā āāā player.ts # Player and statistics models
ā āāā fixture.ts # Match and fixture models
ā āāā standing.ts # League standings models
ā āāā ...
āāā lib/
ā āāā api-client/ # API-Football HTTP client
ā āāā cache/ # LRU cache with TTL
ā āāā tools/ # MCP tool implementations
ā āāā server/ # Structured logger + helpers
āāā services/ # Business logic layer
āāā cli/ # Command-line interfaces
āāā config.ts # Configuration management
āāā server.ts # MCP server entry (built to dist/server.js)
tests/
āāā unit/ # Unit tests
āāā integration/ # Integration tests
āāā contract/ # API contract tests
āāā performance/ # Performance tests
Testing
The project follows Test-Driven Development (TDD):
# Run all tests
pnpm test
# Run specific test categories
pnpm run test:unit
pnpm run test:integration
pnpm run test:contract
pnpm run test:performance
# Run tests in watch mode
# Offline suite (does not require API key)
pnpm run test:offline
# Online tests (require API key, respect vendor rate limits)
pnpm run test:online
Code Quality
- ESLint: Standard style (no semicolons, 2 spaces). In tests, unused vars and nonānull assertions are relaxed. In src, unused args prefixed with
_
are allowed. - TypeScript: Strict mode enabled
- Vitest: Testing framework with coverage
- Automatic formatting: ESLint autofix on save in VS Code
API Reference
Data Models
Team
interface Team {
id: number
name: string
code: string
country: string
founded: number
national: boolean
logo: string
}
Player
interface Player {
id: number
name: string
firstname: string
lastname: string
age: number
birth: {
date: string
place: string
country: string
}
nationality: string
height: string
weight: string
injured: boolean
photo: string
}
Fixture
interface Fixture {
id: number
referee: string
timezone: string
date: string
timestamp: number
periods: {
first: number
second: number
}
venue: {
id: number
name: string
city: string
}
status: {
long: string
short: string
elapsed: number
}
}
Rate Limiting
The API-Football service has rate limits. The server handles this automatically:
- Reads rate limit headers from API responses
- Implements exponential backoff when limits are hit
- Queues requests to respect rate limits
- Caches responses to minimize API calls
Rate limit status can be monitored via:
node dist/cli/api-client.js --endpoint rate-limit --format table
Error Handling
The server provides comprehensive error handling:
- MCP Error Codes: Standard MCP error responses
- API Failures: Graceful handling of API errors
- Cache Fallbacks: Serve cached data when API is unavailable
- Request Validation: Parameter validation before API calls
- Structured Logging: Detailed error logging for debugging
Performance
Benchmarks
- Cache hits: < 10ms response time
- Cache miss with API call: < 200ms average
- Concurrent requests: Supports 100+ concurrent requests
- Memory usage: < 100MB typical usage
Optimization Features
- LRU Cache: Automatic eviction of least-recently-used entries
- Connection pooling: Reuse HTTP connections
- Compression: Gzip compression for API responses
- Batch operations: Multiple requests with concurrency control
Troubleshooting
Common Issues
-
API Key Invalid
Error: API key is required
Solution: Set
API_FOOTBALL_KEY
environment variable -
Rate Limit Exceeded
Warn: Rate limit hit, waiting 30000ms
Solution: Server automatically handles this, wait for reset
-
Cache Performance
# Check cache statistics node dist/cli/cache.js stats --format table # Clear cache if needed node dist/cli/cache.js clear
Debug Mode
Enable debug logging:
export LOG_LEVEL=debug
pnpm start
Contributing
- Follow TDD: Write tests before implementation
- Code Style: Use ESLint standard configuration
- Type Safety: Maintain strict TypeScript compliance
- Documentation: Update README for new features
- Testing: Ensure all tests pass before submitting
Pull Request Process
- Create feature branch from
main
- Write tests for new functionality
- Implement features with TypeScript
- Run full test suite:
pnpm test
- Check linting:
pnpm run lint
- Submit pull request with description
Constitution & Governance
This project follows an internal development constitution for MCP servers (.specify/memory/constitution.md):
- Protocol: JSONāRPC 2.0 over stdio via @modelcontextprotocol/sdk
- TypeScriptāfirst, strict type safety across tools and client integration
- Clear error formatting, retry with exponential backoff, and rateālimit awareness
- Documented tools, validated inputs, sanitized outputs, and caching strategy
Please keep changes aligned with these principles.
License
MIT License - see the file for details.
Support
- Issues: Report bugs via GitHub Issues
- API Reference: API-Football Documentation
- MCP Protocol: Model Context Protocol Specification
Built with ā¤ļø using TypeScript, Node.js, and the Model Context Protocol.
- Rate Limiting for Agents
- Use the
get_rate_limit
tool to inspect the current limit, remaining, and recommended wait time. - The server applies exponential backoff on 429 and tracks vendor headers. Tests space calls by ~3.5s.
- Best practices for agents:
- Batch related queries and cache where possible
- Pace calls (>= 3.5s apart) during exploration
- Handle 429 and retry after the suggested delay
- Prefer season filters to reduce payload sizes
- Use the