MLB API MCP Server

MLB API MCP Server

A Model Context Protocol server for seamless MLB data access through AI applications.

33
Stars
9
Forks
33
Watchers
2
Issues
MLB API MCP Server provides comprehensive access to MLB statistics and baseball data via a FastMCP-based interface. It exposes a range of MLB functionalities—including live game data, player statistics, team information, and advanced metrics—as MCP tools accessible by AI workflows. Compatible with MCP-enabled AI clients, it enables structured, schema-validated querying and integrations for baseball data.

Key Features

Exposes MLB statistics and data as MCP tools
Supports player and team search functionalities
Provides live game boxscores, linescores, and play-by-play data
Access to advanced sabermetric metrics such as WAR, wOBA, and wRC+
Detailed game schedules, results, and standings with flexible filters
Team information and dynamic roster management
Draft and award recipient data retrieval
Tool-based, schema-validated endpoint for seamless AI integration
Automatic API documentation generation
Health check and server info endpoints

Use Cases

Incorporating up-to-date MLB statistics into AI chatbots or assistants
Enabling sports analytics platforms to access detailed baseball metrics
Creating fantasy sports applications using comprehensive player and team data
Building tools for journalists or analysts to query live or historical MLB data
Integrating advanced sabermetric analysis into coaching or scouting applications
Supporting AI-driven sports betting systems with accurate, real-time information
Generating baseball-related reports or dashboards for fans and professionals
Automating the retrieval of game scores and highlights for publishing content
Enabling voice assistants to answer baseball queries using structured data
Facilitating research projects requiring large-scale access to MLB datasets

README

MLB API MCP Server

CI Status License smithery badge Coverage

A Model Context Protocol (MCP) server that provides comprehensive access to MLB statistics and baseball data through a FastMCP-based interface.

Overview

This MCP server acts as a bridge between AI applications and MLB data sources, enabling seamless integration of baseball statistics, game information, player data, and more into AI workflows and applications.

Features

MLB Data Access

  • Current standings for all MLB teams with flexible filtering by league, season, and date
  • Game schedules and results with date range support
  • Player statistics including traditional and sabermetric stats (WAR, wOBA, wRC+)
  • Team information and rosters with various roster types
  • Live game data including boxscores, linescores, and play-by-play
  • Game highlights and scoring plays
  • Player and team search functionality
  • Draft information and award recipients
  • Game pace statistics and lineup information

MCP Tools

All MLB/statistics/game/player/team/etc. functionality is exposed as MCP tools, not as RESTful HTTP endpoints. These tools are accessible via the /mcp/ endpoint using the MCP protocol. For a list of available tools and their descriptions, visit /tools/ when the server is running.

Key MCP Tools

  • get_mlb_standings - Current MLB standings with league and season filters
  • get_mlb_schedule - Game schedules for specific dates, ranges, or teams
  • get_mlb_team_info - Detailed team information
  • get_mlb_player_info - Player biographical information
  • get_mlb_boxscore - Complete game boxscores
  • get_mlb_linescore - Inning-by-inning game scores
  • get_mlb_game_highlights - Video highlights for games
  • get_mlb_game_scoring_plays - Play-by-play data with event filtering
  • get_mlb_game_pace - Game duration and pace statistics
  • get_mlb_game_lineup - Detailed lineup information for games
  • get_multiple_mlb_player_stats - Traditional player statistics
  • get_mlb_sabermetrics - Advanced sabermetric statistics (WAR, wOBA, etc.)
  • get_mlb_roster - Team rosters with various roster types
  • get_mlb_search_players - Search players by name
  • get_mlb_search_teams - Search teams by name
  • get_mlb_players - All players for a sport/season
  • get_mlb_teams - All teams for a sport/season
  • get_mlb_draft - Draft information by year
  • get_mlb_awards - Award recipients
  • get_current_date - Current date
  • get_current_time - Current time

For the full list and detailed descriptions, see /tools/ or /docs when the server is running.

HTTP Endpoints

The following HTTP endpoints are available:

  • / - Redirects to /docs
  • /docs - Interactive API documentation and tool listing
  • /health/ - Health check endpoint
  • /mcp/info - MCP server information
  • /tools/ - List of all available MCP tools
  • /mcp/ (POST) - MCP protocol endpoint for MCP-compatible clients

Note: There are no RESTful HTTP endpoints for MLB/statistics/game/player/team/etc. All such functionality is accessed via MCP tools through the /mcp/ endpoint.

MCP Integration

  • Compatible with MCP-enabled AI applications
  • Tool-based interaction model with comprehensive endpoint descriptions
  • Automatic API documentation generation
  • Schema validation and type safety
  • Full response schema descriptions for better AI integration

Installation

Installing via Smithery

To install MLB API Server for Claude Desktop automatically via Smithery:

bash
npx -y @smithery/cli install @guillochon/mlb-api-mcp --client claude

Option 1: Local Installation

  1. Install uv if you haven't already:
bash
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Clone the repository:
bash
git clone https://github.com/guillochon/mlb-api-mcp.git
cd mlb-api-mcp
  1. Create and activate a virtual environment:
bash
uv venv
source .venv/bin/activate  # On Unix/macOS
# or
.venv\Scripts\activate  # On Windows
  1. Install dependencies:
bash
uv pip install -e .

Option 2: Docker Installation

  1. Clone the repository:
bash
git clone https://github.com/guillochon/mlb-api-mcp.git
cd mlb-api-mcp
  1. Build the Docker image:
bash
docker build -t mlb-api-mcp .
  1. Run the container (default timezone is UTC, uses Python 3.12):
bash
docker run -p 8000:8000 mlb-api-mcp

Setting the Timezone

To run the container in your local timezone, pass the TZ environment variable (e.g., for New York):

bash
docker run -e TZ=America/New_York -p 8000:8000 mlb-api-mcp

Replace America/New_York with your desired IANA timezone name.

The server will be available at http://localhost:8000 with:

  • MCP Server: http://localhost:8000/mcp/
  • Documentation: http://localhost:8000/docs

Docker Options

You can also run the container with additional options:

bash
# Run in detached mode
docker run -d -p 8000:8000 --name mlb-api-server mlb-api-mcp

# Run with custom port mapping
docker run -p 3000:8000 mlb-api-mcp

# View logs
docker logs mlb-api-server

# Stop the container
docker stop mlb-api-server

# Remove the container
docker rm mlb-api-server

Usage

Starting the Server

Run the MCP server locally:

bash
# For stdio transport (default, for MCP clients like Smithery)
uv run python main.py

# For HTTP transport (for web access)
uv run python main.py --http

The server will start with:

  • MCP Server on http://localhost:8000/mcp/
  • Interactive API documentation available at http://localhost:8000/docs

MCP Client Integration

This server can be integrated into any MCP-compatible application. The server provides tools for:

  • Retrieving team standings and schedules
  • Getting comprehensive player and team statistics
  • Accessing live game data and historical records
  • Searching for players and teams
  • Fetching sabermetric statistics like WAR
  • And much more...

API Documentation

Once the server is running, visit http://localhost:8000/docs for comprehensive API documentation including:

  • Available HTTP endpoints
  • List of all available MCP tools at /tools/
  • Tool descriptions and parameters
  • Interactive testing interface
  • Parameter descriptions and examples

Dependencies

  • mcp[cli]: MCP-compliant server framework with CLI support
  • FastAPI: Web framework for HTTP transport
  • python-mlb-statsapi: Official MLB Statistics API wrapper
  • uvicorn[standard]: ASGI server for running the app
  • websockets: WebSocket support (latest version to avoid deprecation warnings)
  • python-dotenv: Environment variable management
  • httpx: HTTP client for API requests

Development

This project uses:

  • Python 3.10+ (Docker uses Python 3.12)
  • FastMCP for the web framework
  • uv for fast Python package management
  • Hatchling for build management
  • MLB Stats API for comprehensive baseball data access
  • Ruff for linting and formatting

Setup Pre-commit Hooks

  1. Install pre-commit:
bash
pip install pre-commit
  1. Initialize pre-commit hooks:
bash
pre-commit install

Now, the linting checks will run automatically whenever you commit code. You can also run them manually:

bash
pre-commit run --all-files

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is open source. Please check the license file for details.

Testing

This project includes comprehensive test coverage with pytest and coverage reporting.

Running Tests

bash
# Run all tests with coverage (default)
uv run pytest

# Run tests with verbose output
uv run pytest -v

# Run specific test file
uv run pytest tests/test_mlb_api.py

# Run specific test function
uv run pytest tests/test_mlb_api.py::test_get_mlb_standings

# Run tests without coverage
uv run tests/run_coverage.py test

# Generate HTML coverage report
uv run tests/run_coverage.py html

# Clean up coverage files
uv run tests/run_coverage.py clean

Coverage

  • Current Coverage: 86.27% (exceeds 80% threshold)
  • Coverage Source: mlb_api.py and generic_api.py
  • Reports: Terminal output, HTML (htmlcov/index.html), and XML (coverage.xml)
  • CI Integration: Coverage checking and badge updates run automatically on every push/PR

Test Structure

The test suite includes:

  • Unit tests for all MCP tools (MLB API and Generic API)
  • Error handling tests for API failures
  • Edge case tests for boundary conditions
  • Mock-based tests to avoid external API calls

Adding New Tests

When adding new functionality:

  1. Add corresponding test cases to tests/test_mlb_api.py
  2. Include both success and error scenarios
  3. Use mocking to avoid external dependencies
  4. Ensure coverage remains above 80%

Example test structure:

python
def test_new_function_success(mcp):
    """Test successful execution of new function"""
    new_function = get_tool(mcp, 'new_function')
    with patch('mlb_api.external_api_call', return_value={'data': 'success'}):
        result = new_function(param='value')
        assert 'data' in result

def test_new_function_error_handling(mcp):
    """Test error handling in new function"""
    new_function = get_tool(mcp, 'new_function')
    with patch('mlb_api.external_api_call', side_effect=Exception("API Error")):
        result = new_function(param='value')
        assert 'error' in result

Star History

Star History Chart

Repository Owner

guillochon
guillochon

User

Repository Details

Language Python
Default Branch main
Size 89 KB
Contributors 4
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

Python
99.06%
Dockerfile
0.94%

Tags

Topics

mcp-server

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • Balldontlie MCP Server

    Balldontlie MCP Server

    Sports data access via Model Context Protocol for LLMs

    Balldontlie MCP Server provides an MCP-compliant interface to the Balldontlie API, offering NBA, NFL, and MLB data to downstream AI models and applications. It supports retrieving information about teams, players, and games, and includes features like schedule generation for various leagues. The server is easily installable via Claude Desktop, Smithery, or LibreChat, and integrates with LLMs to allow natural-language sports queries.

    • 18
    • MCP
    • mikechao/balldontlie-mcp
  • Teamwork MCP Server

    Teamwork MCP Server

    Seamless Teamwork.com integration for Large Language Models via the Model Context Protocol

    Teamwork MCP Server is an implementation of the Model Context Protocol (MCP) that enables Large Language Models to interact securely and programmatically with Teamwork.com. It offers standardized interfaces, including HTTP and STDIO, allowing AI agents to perform various project management operations. The server supports multiple authentication methods, an extensible toolset architecture, and is designed for production deployments. It provides read-only capability for safe integrations and robust observability features.

    • 11
    • MCP
    • Teamwork/mcp
  • TeslaMate MCP Server

    TeslaMate MCP Server

    Query your TeslaMate data using the Model Context Protocol

    TeslaMate MCP Server implements the Model Context Protocol to enable AI assistants and clients to securely access and query Tesla vehicle data, statistics, and analytics from a TeslaMate PostgreSQL database. The server exposes a suite of tools for retrieving vehicle status, driving history, charging sessions, battery health, and more using standardized MCP endpoints. It supports local and Docker deployments, includes bearer token authentication, and is intended for integration with MCP-compatible AI systems like Claude Desktop.

    • 106
    • MCP
    • cobanov/teslamate-mcp
  • Campertunity MCP Server

    Campertunity MCP Server

    Model Context Protocol server for AI-driven camping and outdoor recreation data

    Implements the Model Context Protocol (MCP) to provide AI models with structured access to camping and outdoor recreation data. Offers tools for searching, filtering, and booking campgrounds and sites based on a wide range of criteria. Enhances data accuracy with AI and aggregates information from multiple sources, enabling dynamic, real-time queries and bookings. Ideal for integrating intelligent camping experiences into AI-driven applications.

    • 11
    • MCP
    • campertunity/mcp-server
  • FirstCycling MCP Server

    FirstCycling MCP Server

    Professional cycling data API for conversational AI via MCP.

    FirstCycling MCP Server provides structured access to comprehensive professional cycling data through the Model Context Protocol. It enables retrieval of cyclist profiles, race results, historical race data, and team information, supporting detailed sports analysis and research. The server integrates the FirstCycling API for real-time data scraping and exposes specialized MCP tools for querying race and rider statistics.

    • 17
    • MCP
    • r-huijts/firstcycling-mcp
  • Lara Translate MCP Server

    Lara Translate MCP Server

    Context-aware translation server implementing the Model Context Protocol.

    Lara Translate MCP Server enables AI applications to seamlessly access professional translation services via the standardized Model Context Protocol. It supports features such as language detection, context-aware translations, and translation memory integration. The server acts as a secure bridge between AI models and Lara Translate, managing credentials and facilitating structured translation requests and responses.

    • 76
    • MCP
    • translated/lara-mcp
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results