MCP server that acts as a proxy to the freely available MLB API, which provides player info, stats, and game information.
A Model Context Protocol (MCP) server that provides comprehensive access to MLB statistics and baseball data through a FastMCP-based interface.
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.
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.
get_mlb_standings
- Current MLB standings with league and season filtersget_mlb_schedule
- Game schedules for specific dates, ranges, or teamsget_mlb_team_info
- Detailed team informationget_mlb_player_info
- Player biographical informationget_mlb_boxscore
- Complete game boxscoresget_mlb_linescore
- Inning-by-inning game scoresget_mlb_game_highlights
- Video highlights for gamesget_mlb_game_scoring_plays
- Play-by-play data with event filteringget_mlb_game_pace
- Game duration and pace statisticsget_mlb_game_lineup
- Detailed lineup information for gamesget_multiple_mlb_player_stats
- Traditional player statisticsget_mlb_sabermetrics
- Advanced sabermetric statistics (WAR, wOBA, etc.)get_mlb_roster
- Team rosters with various roster typesget_mlb_search_players
- Search players by nameget_mlb_search_teams
- Search teams by nameget_mlb_players
- All players for a sport/seasonget_mlb_teams
- All teams for a sport/seasonget_mlb_draft
- Draft information by yearget_mlb_awards
- Award recipientsget_current_date
- Current dateget_current_time
- Current timeFor the full list and detailed descriptions, see /tools/
or /docs
when the server is running.
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 clientsNote: 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.
To install MLB API Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @guillochon/mlb-api-mcp --client claude
curl -LsSf https://astral.sh/uv/install.sh | sh
git clone https://github.com/guillochon/mlb-api-mcp.git
cd mlb-api-mcp
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On Windows
uv pip install -e .
git clone https://github.com/guillochon/mlb-api-mcp.git
cd mlb-api-mcp
docker build -t mlb-api-mcp .
docker run -p 8000:8000 mlb-api-mcp
To run the container in your local timezone, pass the TZ
environment variable (e.g., for New York):
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:
http://localhost:8000/mcp/
http://localhost:8000/docs
You can also run the container with additional options:
# 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
Run the MCP server locally:
# 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:
http://localhost:8000/mcp/
http://localhost:8000/docs
This server can be integrated into any MCP-compatible application. The server provides tools for:
Once the server is running, visit http://localhost:8000/docs
for comprehensive API documentation including:
/tools/
This project uses:
pip install pre-commit
pre-commit install
Now, the linting checks will run automatically whenever you commit code. You can also run them manually:
pre-commit run --all-files
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is open source. Please check the license file for details.
This project includes comprehensive test coverage with pytest and coverage reporting.
# 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
mlb_api.py
and generic_api.py
htmlcov/index.html
), and XML (coverage.xml
)The test suite includes:
When adding new functionality:
tests/test_mlb_api.py
Example test structure:
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