MLB Stats MCP
Provides tools for accessing live and historical Major League Baseball data via the MLB Stats API, including players, season and career stats, game logs, league leaders, standings, teams, rosters, schedules, and box scores.
Click on "Deploy 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 How did Aaron Judge hit over his last 10 games?"
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
An MCP server that gives Claude (or any MCP client) live and historical Major League Baseball data: players, season and career stats, schedules, live box scores, standings and league leaders.
It uses the public MLB Stats API (statsapi.mlb.com), so there are no API keys or sign-up.
Ask things like:
"How did Aaron Judge's 2026 compare to his career averages?"
"Who's pitching for the Dodgers tonight, and what are their ERAs?"
"Show me the AL standings and who's leading the wild card."
"Top 10 home run hitters in the NL this season."
Tools
Tool | What it does |
| Name → |
| Bio: age, height, bats/throws, debut, birthplace |
| Hitting / pitching / fielding, by season, career or year-by-year |
| Game-by-game stats, most recent first, for recent form and streaks |
| Leaders for any stat category, AL / NL / MLB |
| Division standings with games back, streak, run differential |
| All 30 teams with ids, league, division, ballpark |
| Active, 40-man or full-season roster |
| Games for a date or range, with scores and probable pitchers |
| Line score by inning plus batting and pitching box score |
Team arguments accept "Yankees", "NYY", "New York Yankees" or "147".
Caching and retries
Responses are cached in memory, and each kind of data keeps its own lifetime, so repeated questions don't hit MLB again. A cached call takes about 1 ms, compared with about 1.2 s for a fresh one.
Data | Cached for |
Live games | 15 s |
Today's schedule | 1 min |
Standings, leaders, current-season stats | 5 min |
Rosters, player bios | 1 h |
Teams, finished games, past seasons | 24 h |
The cache keeps at most 1,000 entries and evicts the least recently used. Errors are never cached.
Timeouts, connection errors and HTTP 429 or 5xx responses are retried up to 3 times with
exponential backoff and jitter, and a Retry-After header is honored. Other 4xx errors fail right
away.
Related MCP server: StatsPlus MCP Server
Install
You need uv. It fetches Python for you.
Claude Code
claude mcp add mlb-stats -- uvx mlb-stats-mcpClaude Desktop, Cursor, Windsurf, VS Code and others
Add this to the client's MCP config. For Claude Desktop, that's Settings → Developer → Edit Config:
{
"mcpServers": {
"mlb-stats": {
"command": "uvx",
"args": ["mlb-stats-mcp"]
}
}
}Remote (no install)
If someone hosts the server (see below), clients can connect to the URL directly:
claude mcp add --transport http mlb-stats https://YOUR-HOST/mcpIn Claude.ai, go to Settings → Connectors → Add custom connector and paste the same URL.
Development
git clone https://github.com/prnv-13/mlb-stats-mcp
cd mlb-stats-mcp
uv sync
uv run pytest # offline unit tests (MLB API is faked)
uv run scripts/smoke_test.py # calls every tool over stdio against the live API
uv run mlb-stats-mcp --transport http # serves http://127.0.0.1:8000/mcp
npx @modelcontextprotocol/inspector # GUI for poking at tools
claude mcp add mlb-dev -- uv run --directory "$PWD" mlb-stats-mcp # use your local copy in Claude CodeLayout:
src/mlb_stats_mcp/
config.py every constant: URLs, timeouts, cache TTLs, retry policy, limits
cli.py entry point: stdio (default) or --transport http
server.py build_server(): server identity, instructions, tool registration
mlb/ data layer, the only code that talks to MLB
client.py MLBClient: caching + retries around HTTP
cache.py TTLCache: generic TTL + LRU cache
endpoints.py API paths
errors.py MLBApiError
tools/ the MCP tools, one module per area
teams.py players.py leaders.py games.py standings.py
common.py shared types, annotations, date and season helpers
tests/ offline pytest suite, mirrors src/ (mlb/, tools/)
scripts/smoke_test.py end-to-end test, works on stdio or an HTTP URL
Dockerfile for hosting the HTTP versionRequests flow one way: cli → server → tools/* → mlb.MLBClient → statsapi.mlb.com.
To add a tool, write an async function in the right tools/ module (type hints and the
docstring become its schema), then add it to ALL_TOOLS in tools/__init__.py.
Publishing guide
There are two ways people can use your MCP. You can do both.
1. Publish a package so anyone can run uvx mlb-stats-mcp
Create accounts on pypi.org and test.pypi.org, then create an API token on each (Account settings → API tokens).
Build:
uv build # creates dist/*.whl and dist/*.tar.gzDo a test run on TestPyPI:
uv publish --publish-url https://test.pypi.org/legacy/ --token pypi-XXXX uvx --index-url https://test.pypi.org/simple/ --index-strategy unsafe-best-match mlb-stats-mcp --helpPublish for real:
uv publish --token pypi-XXXXFor each new release, bump
versioninpyproject.toml, runuv build, thenuv publish.
To skip handling tokens, set up Trusted Publishing on PyPI and publish from a GitHub Action instead.
2. Host it so people only need a URL
The server runs as a stateless Streamable HTTP server, so any container host works. Examples are
Render, Railway, Fly.io and Google Cloud Run (many have free tiers). The Dockerfile reads PORT
from the platform.
docker build -t mlb-stats-mcp .
docker run -p 8000:8000 mlb-stats-mcp
# → http://localhost:8000/mcpOn Render or Railway, connect the GitHub repo and pick "Docker". Users then add
https://your-app.onrender.com/mcp.
The server needs no auth because it only reads public data. If you open it to the internet, consider putting rate limiting in front of it, and keep in mind that heavy traffic hits MLB's API from your server's IP address.
3. Get listed so people can find it
Official MCP Registry (registry.modelcontextprotocol.io):
brew install mcp-publisher mcp-publisher init # generates server.json from this repo mcp-publisher login github mcp-publisher publishThe registry checks that you own the PyPI package by looking for the
mcp-name:comment near the top of this README.Community lists: open a PR to awesome-mcp-servers, and submit to directories such as Smithery, Glama and mcp.so.
Data and terms
The data comes from MLB Advanced Media's Stats API. It's © MLB and is offered for individual, non-commercial, non-bulk use. This project isn't affiliated with MLB. Don't use it to build a paid product or to bulk-scrape the API.
License
MIT
Available Tools
10 toolsget_gameARead-onlyIdempotent
Get a game's live or final line score plus each team's batting and pitching box score.
Args:
game_pk: Game id from get_schedule.
Inputs: game_pk (required). Returns: object
get_league_leadersARead-onlyIdempotent
Get the league leaders for a statistic.
Args:
category: Stat category, e.g. homeRuns, battingAverage, runsBattedIn, stolenBases,
onBasePlusSlugging, hits, earnedRunAverage, strikeouts, wins, saves, walksAndHitsPerInningPitched.
season: Season year; defaults to the current one.
group: "hitting" or "pitching". Needed for categories shared by both (e.g. strikeouts
for pitchers vs. batters). Defaults to the API's choice.
league: "AL", "NL" or "MLB" (both leagues).
limit: How many leaders to return (1-50).
Inputs: group, limit, league, season, +1 more. Returns: object
get_player_game_logARead-onlyIdempotent
Get a player's game-by-game stats, most recent game first. Use for recent form, hot or cold streaks, and "how did he do last night / this week" questions.
Args:
player_id: MLB player id from search_players.
group: "hitting" or "pitching".
season: Season year; defaults to the current one.
last_n: Number of most recent games to return (1-162).
Inputs: player_id (required), group, last_n, season. Returns: object
get_player_infoARead-onlyIdempotent
Get a player's biography: team, position, age, height, handedness, debut, birthplace.
Args:
player_id: MLB player id from search_players.
Inputs: player_id (required). Returns: object
get_player_statsARead-onlyIdempotent
Get a player's batting, pitching or fielding stats.
Args:
player_id: MLB player id from search_players.
group: "hitting", "pitching" or "fielding".
stat_type: "season" (one season), "career" (career totals) or "yearByYear" (every season).
season: Season year for stat_type="season"; defaults to the current one.
Inputs: player_id (required), group, season, stat_type. Returns: object
get_scheduleARead-onlyIdempotent
Get MLB games (with scores and probable pitchers) for a date or date range.
Args:
date: Date as YYYY-MM-DD; defaults to today (US Eastern).
end_date: Optional end of range (YYYY-MM-DD). Keep ranges short (a few weeks at most).
team: Optional team filter: name, abbreviation or id.
Inputs: date, team, end_date. Returns: object
get_standingsBRead-onlyIdempotent
Get division standings: wins, losses, win %, games back, streak and run differential.
Args:
season: Season year; defaults to the current one.
league: "AL", "NL" or "MLB" (both).
Inputs: league, season. Returns: object
get_team_rosterARead-onlyIdempotent
Get a team's roster.
Args:
team: Team name, abbreviation or id, e.g. "Dodgers", "LAD" or "119".
roster_type: "active" (26-man), "40Man", or "fullSeason" (everyone who played that season).
season: Season year; defaults to the current one.
Inputs: team (required), season, roster_type. Returns: object
list_teamsARead-onlyIdempotent
List all 30 MLB teams with their ids, abbreviations, league, division and ballpark.
Inputs: no named parameters. Returns: result
search_playersARead-onlyIdempotent
Find MLB players by name and return their player_id (needed by other player tools).
Args:
name: Full or partial name, e.g. "Ohtani" or "Aaron Judge".
active_only: Only return currently active players.
Inputs: name (required), active_only. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool maps to a distinct resource and action: team listing vs. roster, player lookup vs. bio vs. stats vs. game log, league leaders, schedule, single game, and standings. The descriptions explicitly explain boundaries (e.g., search_players yields the player_id consumed by the player tools; get_schedule vs. get_game is list vs. single game). No two tools appear to do the same thing.
All tools follow a snake_case verb_noun pattern (get_player_stats, get_team_roster, get_league_leaders), with 'list_teams' appropriately using list for the only enumeration endpoint and 'search_players' for the lookup. No camelCase or vague-verb deviations.
Ten tools is right-sized for an MLB stats server: one per core entity/operation (teams, roster, player lookup, bio, stats, game log, leaders, schedule, game, standings) with no redundant entries.
The surface covers the core fan/analyst workflow end to end: discover teams and players, then pull bios, season/career stats, game logs, leaders, schedules, box scores, and standings. Gaps are minor: no transactions, injuries, or team-level aggregate stats, and schedule lookups are discouraged for long ranges.
Maintenance
Related MCP Connectors
Provides easy access to MLB, Baseball Savant, Statcast, and Fangraphs baseball data. Query detaile…
MLB Stats API MCP — official MLB statistics (keyless).
Live sports stats and pre-computed analysis for AI assistants across NBA, MLB, NFL, and NHL.
NBA, NFL, NHL and combined sports scores as agent tools.
Related MCP Servers
- 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.2436MIT
- AlicenseAqualityDmaintenanceExposes the StatsPlus API as tools for MCP-compatible clients, enabling users to query player/team statistics, contracts, ratings, and game history via natural language.155MIT
- AlicenseNot gradedqualityDmaintenanceProvides comprehensive baseball analytics through 32 tools covering pitching, batting, defensive metrics, and visualizations via the Model Context Protocol, enabling natural language queries for advanced Statcast and MLB statistics.MIT
- AlicenseNot gradedqualityCmaintenanceProvides access to official MLB statistics via a keyless API, enabling AI agents to query MLB data through natural language or direct tools.292 npmMIT