Logo de Mlb Api MCP

Mlb Api MCP

Communauté
guillochon

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

Éditeurguillochon
Dépôtmlb-api-mcp
LanguePython
Forks
12
Étoiles
59
Outils disponibles
0
Type de transportstdio
LicenceMIT
Liens
  • Connectez des outils à vos workflows IA

    Mlb Api MCP propose des fonctionnalités MCP utilisables par les clients et agents IA compatibles.

  • 0 outils disponibles

    Parcourez les actions invocables ci-dessous, avec leurs noms et descriptions lorsque le serveur les fournit.

  • Configuration prête à copier

    Utilisez les exemples de configuration pour configurer ce serveur dans votre client MCP préféré.

  • Indicateurs de popularité open source

    59 étoiles et 12 forks sur le dépôt associé.

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: 89.91% (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 runs automatically on every push/PR; results are published in the GitHub Actions job summary

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

Live-API Scan

The mocked test suite protects this repo's own logic but does not exercise the real upstream MLB Stats API / pybaseball services, whose response shapes are outside this repo's control. To verify the tools still work against live data (e.g. after upstream field renames or contract changes), run the one-time scan:

bash
# Invokes every registered tool against the real upstream API and prints a
# pass/fail summary plus the top-level return type of each result.
uv run python scripts/scan_live_tools.py

The scan writes a full JSON report to scripts/live_scan_report.json (gitignored). This is a manual verification pass, not part of the automated CI suite.

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

Utilisez le serveur MCP Mlb Api MCP avec plusieurs modèles IA

TypingMind connecte les outils MCP au niveau de l’espace de travail. Une fois Mlb Api MCP connecté, vous pouvez donc l’utiliser avec différents modèles IA dans TypingMind sans avoir à le configurer séparément pour chaque modèle. Cette intégration MCP s’exécute localement sur votre appareil via le connecteur MCP de TypingMind.

Guide de configuration du connecteur local

Choisissez cette méthode si le serveur MCP doit accéder à des fichiers locaux, à des applications ou à des ressources privées sur votre ordinateur.

1

Ouvrir les paramètres MCP

Dans TypingMind, accédez à « Paramètres », puis à « Paramètres avancés » et à « Model Context Protocol », et choisissez « Configurer connecteur ».

  1. Ouvrez TypingMind dans votre navigateur.
  2. Cliquez sur l’icône Paramètres.
  3. Accédez aux paramètres avancés.
  4. Ouvrez la section Model Context Protocol.
  5. Cliquez sur « Configurer connecteur » et choisissez « Cet appareil ».
Écran de configuration du connecteur MCP de TypingMind avec l’option « Cet appareil » sélectionnée
2

Exécuter la commande du connecteur

Choisissez « Cet appareil », copiez la commande depuis TypingMind et exécutez-la dans Terminal. Laissez le processus en cours d’exécution pendant que vous utilisez MCP.

  1. Copiez la commande de configuration affichée par TypingMind.
  2. Ouvrez Terminal sur macOS ou Windows Terminal sur Windows.
  3. Collez et exécutez la commande.
  4. Autorisez l’installation du paquet si Terminal vous demande de confirmer.
  5. Gardez la fenêtre de Terminal ouverte et le processus en cours d’exécution pendant que vous utilisez les outils MCP.
3

Ajoutez Mlb Api MCP en tant que serveur

Lorsque l’état du connecteur affiche « Prêt », cliquez sur « Éditer serveurs » et collez la configuration du serveur MCP.

  1. Attendez que l’état du connecteur affiche « Prêt ».
  2. Cliquez sur « Éditer serveurs ».
  3. Collez la configuration du serveur MCP Mlb Api MCP.
  4. Enregistrez la liste des serveurs.
  5. Actualisez pour vérifier que le connecteur est toujours prêt.
Paramètres MCP de TypingMind affichant un serveur actif et le bouton « Éditer serveurs »
{
  "mcpServers": {
    "mlb-api-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Utiliser la connexion avec différents modèles

Enregistrez la liste des serveurs, ouvrez « Plugins », activez les outils MCP de Mlb Api MCP, puis sélectionnez un modèle IA compatible dans TypingMind et utilisez les outils dans une discussion ou attribuez-les à un agent IA.

  1. Ouvrez la page Plugins dans TypingMind.
  2. Activez les outils MCP de Mlb Api MCP.
  3. Démarrez une discussion et choisissez le modèle IA que vous souhaitez utiliser.
  4. Utilisez les outils MCP dans le chat ou attribuez-les à un agent IA.
  5. Passez à un autre modèle IA selon vos besoins sans rétablir la connexion MCP.
Discussion TypingMind utilisant des outils MCP activés avec un modèle d’IA sélectionné
Pouvez-vous utiliser Mlb Api MCP pour m’aider dans cette tâche ?
Mlb Api MCP
Bien sûr. J’ai tout lu.
Voici ce que j’ai trouvé avec Mlb Api MCP.

Foire aux questions

À quoi sert le serveur MCP Mlb Api MCP ?

Mlb Api MCP est un serveur MCP qui permet aux applications IA compatibles d’accéder à des outils et à des informations contextuelles externes. Dans TypingMind, il vous suffit d’ajouter ce serveur MCP une seule fois pour rendre ses outils disponibles dans votre espace de travail IA.

Puis-je utiliser le serveur MCP Mlb Api MCP avec plusieurs modèles IA dans TypingMind ?

Oui. TypingMind connecte les outils MCP au niveau de l’espace de travail. Vous pouvez donc utiliser Mlb Api MCP avec différents modèles IA comme Claude, ChatGPT, Gemini ou d’autres modèles configurés dans TypingMind, sans avoir à configurer le serveur MCP séparément pour chaque modèle.

Pourquoi utiliser le connecteur MCP Mlb Api MCP avec TypingMind ?

TypingMind est l’une des meilleures interfaces de chat avec les LLM, car elle réunit plusieurs modèles IA, prompts, plugins, agents IA, clés API et outils MCP dans un seul espace de travail. Une fois Mlb Api MCP connecté, vous pouvez utiliser ses outils MCP avec vos modèles préférés tout en gardant vos discussions bien organisées dans TypingMind.

Comment connecter le serveur MCP Mlb Api MCP à TypingMind ?

Mlb Api MCP fonctionne via le connecteur MCP local de TypingMind. C’est l’option idéale lorsque le serveur MCP doit accéder à des fichiers locaux, des applications de bureau, des outils en ligne de commande ou des ressources privées sur votre ordinateur.

Quels outils le serveur MCP Mlb Api MCP propose-t-il dans TypingMind ?

Mlb Api MCP propose des fonctionnalités MCP que vous pouvez activer depuis la page Plugins de TypingMind et utiliser dans les discussions ou attribuer à des agents IA.

Dois-je partager mes clés API avec TypingMind pour utiliser le serveur MCP Mlb Api MCP ?

Non. TypingMind privilégie le fonctionnement local et vous permet de garder le contrôle de vos fournisseurs de modèles, clés API, prompts et paramètres MCP. Si Mlb Api MCP nécessite une authentification, ajoutez les en-têtes, les paramètres OAuth ou la configuration locale requis pour ce serveur MCP lors de la création de la connexion.

Serveurs MCP similaires

Tout voir

Créez votre propre espace IA dès maintenant

Abonnez-vous à notre newsletter pour être informé des nouvelles fonctionnalités et des prochains cadeaux à gagner 👇