MLB Stats MCP Server
Provides access to MLB statistics data through the MLB Stats API, including player stats, team information, game data, Statcast metrics, FanGraphs data, Baseball Reference statistics, and the ability to generate matplotlib visualizations of baseball data.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MLB Stats MCP Servershow me Aaron Judge's batting stats for this season"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MLB Stats MCP Server
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.
Project Structure
mlb_stats_mcp/- Main package directoryserver.py- Core MCP server implementationtools/- MCP tool implementationsmlb_statsapi_tools.py- MLB StatsAPI tool definitionsstatcast_tools.py- Statcast data tool definitionspybaseball_plotting_tools.py- Additionalpybaseballtools provided for generating matplotlib plots and returning base64 encoded imagespybaseball_supp_tools.py- Supplementalpybaseballfunctions for interfacing with fangraphs, baseball reference, and other data sources
utils/- Utility moduleslogging_config.py- Logging configurationimages.py- functions related to handling plot images
tests/- Test suite for verifying server functionality
pyproject.toml- Project configuration and dependencies.pre-commit-config.yaml- Pre-commit hooks configuration.github/- GitHub Actions workflows
Related MCP server: baseball-mcp
Tools
Setup
Install uv if you haven't already:
curl -LsSf https://astral.sh/uv/install.sh | shCreate and activate a virtual environment:
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On WindowsInstall dependencies:
uv pip install -e .Installing via Smithery
To install MLB Stats Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @etweisberg/mlb-mcp --client claudeRunning Tests
The project includes comprehensive pytest tests for the MCP server functionality:
uv run pytest -vTests verify all MLB StatsAPI tools work correctly with the MCP protocol, establishing connections, making API calls, and processing responses.
Environment Variables
The project uses environment variables stored in .env to configure settings.
Use ANTHROPIC_API_KEY to enable MCP Server.
Logging Configuration
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)
Claude Desktop Integration
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 file
Technologies Used
mcp[cli]- Machine-Learning Chat Protocol for tool definitionmlb-statsapi- Python wrapper for the MLB Stats APIhttpx- HTTP client for making API requestspytestandpytest-asyncio- Test frameworksuv- Fast Python package manager and installer
Linting
This project uses Ruff for linting and code formatting, with pre-commit hooks to ensure code quality.
Setup Pre-commit Hooks
Install pre-commit:
pip install pre-commitInitialize pre-commit hooks:
pre-commit installNow, the linting checks will run automatically whenever you commit code. You can also run them manually:
pre-commit run --all-filesLinting Configuration
Linting rules are configured in the pyproject.toml file under the [tool.ruff] section. The project follows PEP 8 style guidelines with some customizations.
CI Integration
GitHub Actions workflows automatically run tests, linting, and pre-commit checks on all pull requests and pushes to the main branch.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityBmaintenancePython MCP server that provides comprehensive access to MLB statistics and baseball data through a FastAPI-based interface. Acts as a bridge between AI applications and MLB data sources, enabling seamless integration of baseball statistics, game information, player data, and more.Last updated2458MIT
- AlicenseBqualityDmaintenanceEnables access to MLB Stats API data including game schedules, results, team information, and player lookups with fuzzy matching support through the Model Context Protocol.Last updated37MIT
- AlicenseAqualityDmaintenanceConnects Claude to the SportRadar MLB API to access real-time baseball data including game schedules, live scores, player statistics, team standings, injury reports, and play-by-play information through natural language queries.Last updated191MIT
- AlicenseAqualityDmaintenanceEnables users to query MLB Statcast, FanGraphs, and Baseball Reference data using natural language through an AI assistant. It provides comprehensive tools for analyzing player performance, pitch-level data, season leaderboards, and team standings.Last updated2434MIT
Related MCP Connectors
MLB Stats API MCP — official MLB statistics (keyless).
Provides access to live sports data and analytics from BALLDONTLIE: The Sports API
Read-only fantasy analysis for ESPN, Yahoo, and Sleeper leagues via MCP
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/etweisberg/mlb-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server