Taps into MLB's Stats API and the pybaseball library to pull player and game statistics, Statcast metrics, FanGraphs data, and Baseball Reference records. Beyond just fetching numbers, it includes plotting tools that generate matplotlib visualizations and return them as base64 encoded images, so you can ask for spray charts or pitch movement diagrams directly in your workflow. The toolset covers both current season queries and historical lookups. Runs over HTTP transport. Reach for this when you're doing baseball analysis and want structured access to the major stats databases without manually scraping or managing API clients yourself.
A Python project that creates a Model Context Protocol (MCP) server for accessing MLB statistics data through the MLB Stats API and pybaseball library for statcast, fangraphs, and baseball reference statistics. This server provides structured API access to baseball statistics that can be used with MCP-compatible clients.
mlb_stats_mcp/ - Main package directory
server.py - Core MCP server implementationtools/ - MCP tool implementations
mlb_statsapi_tools.py - MLB StatsAPI tool definitionsstatcast_tools.py - Statcast data tool definitionspybaseball_plotting_tools.py - Additional pybaseball tools provided for generating matplotlib plots and returning base64 encoded imagespybaseball_supp_tools.py - Supplemental pybaseball functions for interfacing with fangraphs, baseball reference, and other data sourcesutils/ - Utility modules
logging_config.py - Logging configurationimages.py - functions related to handling plot imagestests/ - Test suite for verifying server functionalitypyproject.toml - Project configuration and dependencies.pre-commit-config.yaml - Pre-commit hooks configuration.github/ - GitHub Actions workflowscurl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On Windows
uv pip install -e .
To install MLB Stats Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @etweisberg/mlb-mcp --client claude
The project includes comprehensive pytest tests for the MCP server functionality:
uv run pytest -v
Tests verify all MLB StatsAPI tools work correctly with the MCP protocol, establishing connections, making API calls, and processing responses.
The project uses environment variables stored in .env to configure settings.
Use ANTHROPIC_API_KEY to enable MCP Server.
The MLB Stats MCP Server supports configurable logging via environment variables:
MLB_STATS_LOG_LEVEL - Sets the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)MLB_STATS_LOG_FILE - Path to log file (if not set, logs to stdout)To connect this MCP server to Claude Desktop, add a configuration to your claude_desktop_config.json file. Here's a template configuration:
"mcp-baseball-stats": {
"command": "{PATH_TO_UV}",
"args": [
"--directory",
"{PROJECT_DIRECTORY}",
"run",
"python",
"-m",
"mlb_stats_mcp.server"
],
"env": {
"MLB_STATS_LOG_FILE": "{LOG_FILE_PATH}",
"MLB_STATS_LOG_LEVEL": "DEBUG"
}
}
Replace the following placeholders:
{PATH_TO_UV}: Path to your uv installation (e.g., ~/.local/bin/uv){PROJECT_DIRECTORY}: Path to your project directory{LOG_FILE_PATH}: Path where you want to store the log filemcp[cli] - Machine-Learning Chat Protocol for tool definitionmlb-statsapi - Python wrapper for the MLB Stats APIhttpx - HTTP client for making API requestspytest and pytest-asyncio - Test frameworksuv - Fast Python package manager and installerThis project uses Ruff for linting and code formatting, with pre-commit hooks to ensure code quality.
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
Linting rules are configured in the pyproject.toml file under the [tool.ruff] section. The project follows PEP 8 style guidelines with some customizations.
GitHub Actions workflows automatically run tests, linting, and pre-commit checks on all pull requests and pushes to the main branch.
io.github.infoinlet-marketplace/mcp-observability
betterdb-inc/monitor
com.mcparmory/datadog
thotischner/observability-mcp
io.github.tantiope/datadog-mcp
io.github.us-all/datadog