Skip to main content
skill CX Codex

mlb-data — Claude Code skill: what it does, how to install

Connects your coding agent to live and historical MLB data from ESPN and the official MLB API. Useful for pulling scores, rosters, injuries, and pitch analytics without API keys.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add machina-sports/sports-skills --skill mlb-data -a claude-code
Open on GitHub

What mlb-data does

The skill queries public ESPN endpoints and the official MLB Stats API via the sports-skills CLI tool. It pulls live game scores, division standings, 30-team rosters, schedules, injury reports, and game summaries. It also accesses pitch-level tracking with velocity, spin rate, plate coordinates, exit velocity, and launch angle.

Commands prefixed with get_mlbstats_ access historical schedules dating back to 1901 and split player stats by game log or career totals. Because ESPN and MLB maintain separate identifier systems for games and players, joining records requires matching game dates and team names. Queries on play-by-play data support post-fetch filtering through --fields and --limit flags.

Running this package requires Python 3.10 or newer with the sports-skills CLI installed. It needs no API keys. The skill handles Major League Baseball only, so it will fail to return data for minor leagues, college tournaments, or international baseball.

What it helps with

  • retrieve live scores and full play-by-play summaries for MLB games
  • inspect pitch-level velocity, spin rate, and exit velocity
  • query historical MLB schedules dating back to 1901
  • check injury lists and depth charts across active rosters

Example prompts for the agent

  • Check the live scoreboard for today's MLB games
  • Fetch pitch velocity and exit velocity for gamePk 775296
  • Find player Ronald Acuna and pull his career stats

How to install mlb-data

1Skills CLI (Vercel)

npx skills add machina-sports/sports-skills --skill mlb-data -a claude-code

2Manually: put the files in place

~/.claude/skills/mlb-data/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/mlb-data/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about mlb-data

How do I install mlb-data in Claude Code?

Run npx skills add machina-sports/sports-skills --skill mlb-data -a claude-code. You also need Python 3.10+ installed along with pip install sports-skills.

What does mlb-data do?

It provides Major League Baseball data by querying public ESPN endpoints and the official MLB Stats API. It supplies live scores, 30-team rosters, injury logs, historical schedules back to 1901, and pitch analytics.

Does mlb-data require an API key?

No API keys are required because it pulls from public ESPN and MLB Stats endpoints. Your system only needs Python 3.10 or newer and the sports-skills package.

Source text

SKILL.md · MIT
---
name: mlb-data
description: |
  MLB data via ESPN public endpoints and the official MLB Stats API — scores, standings, rosters, schedules, game summaries, injuries, leaders, and news, plus an analytics backend: pitch-level velocity/spin/exit-velocity, career splits by stat group, league leaders, and schedules to 1901. Zero config, no API keys.

  Use when: user asks about MLB scores, standings, team rosters, schedules, game stats, box scores, play-by-play, injuries, transactions, depth charts, team/player statistics, MLB news, pitch speeds/spin/exit velocity, career stats, league leaders, or historical MLB seasons.
  Don't use when: user asks about minor league baseball, college baseball, or international baseball. For other sports use: nfl-data (NFL), nba-data (NBA), wnba-data (WNBA), nhl-data (NHL), football-data (soccer), tennis-data (tennis), golf-data (golf), cricket-data (cricket), cfb-data (college football), cbb-data (college basketball), fastf1 (F1). For betting odds use polymarket or kalshi. For news use sports-news.
license: MIT
metadata:
  author: machina-sports
  version: "0.1.0"
---

# MLB Data

Before writing queries, consult `references/api-reference.md` for endpoints, ID conventions, and data shapes.

## Setup

Before first use, check if the CLI is available:
```bash
which sports-skills || pip install sports-skills
```
If `pip install` fails with a Python version error, the package requires Python 3.10+. Find a compatible Python:
```bash
python3 --version  # check version
# If < 3.10, try: python3.12 -m pip install sports-skills
# On macOS with Homebrew: /opt/homebrew/bin/python3.12 -m pip install sports-skills
```
No API keys required.

## Quick Start

Prefer the CLI — it avoids Python import path issues:
```bash
sports-skills mlb get_scoreboard
sports-skills mlb get_standings --season=2025
sports-skills mlb get_teams
```

## CRITICAL: Before Any Query

CRITICAL: Before calling any data endpoint, verify:
- Season year is derived from the system prompt's `currentDate` — never hardcoded.
- If only a team name is provided, call `get_teams` to resolve the team ID before using team-specific commands.

## Choosing the Season

Derive the active season from the system prompt's date — not just the calendar year.

- **If the user specifies a season**, use it as-is.
- **If the user says "current", "this season", or doesn't specify**: The MLB season runs late March/April through October. If the current month is January–March, the last completed season was the prior calendar year. From April onward, use the current calendar year.

## Commands

| Command | Description |
|---|---|
| `get_scoreboard` | Live/recent MLB scores |
| `get_standings` | Standings by league and division |
| `get_teams` | All 30 MLB teams |
| `get_team_roster` | Full roster for a team |
| `get_team_schedule` | Schedule for a specific team |
| `get_game_summary` | Detailed box score and scoring plays |
| `get_leaders` | MLB statistical leaders |
| `get_news` | MLB news articles |
| `get_play_by_play` | Full play-by-play for a game |
| `get_win_probability` | Win probability chart data |
| `get_schedule` | Games on a specific date (no season filter; see `get_team_schedule`) |
| `get_injuries` | Injury reports across all teams |
| `get_transactions` | Recent transactions |
| `get_futures` | Futures/odds markets |
| `get_depth_chart` | Depth chart for a team |
| `get_team_stats` | Team statistical profile |
| `get_player_stats` | Player statistical profile |
| `find_mlb_player` | Search MLB's player registry by name |
| `get_mlbstats_schedule` | Games via the MLB Stats API — history to 1901, carries gamePk ids |
| `get_mlbstats_player_stats` | Season/career/year-by-year splits by stat group via MLB Stats API; `stat_type=game_log` gives one split per game |
| `get_mlbstats_play_by_play` | Pitch-level PBP — velocity, spin, plate coords, exit velo, launch angle |
| `get_mlbstats_boxscore` | Full box score with per-player batting/pitching via MLB Stats API |
| `get_mlbstats_standings` | Standings by division via MLB Stats API |
| `get_mlbstats_leaders` | League leaders for any stat category via MLB Stats API |

See `references/api-reference.md` for full parameter lists and return shapes.

## Shaping Play-by-Play Results

`get_mlbstats_play_by_play` and `get_mlbstats_player_stats` accept `sort_by`, `descending`, `limit` and `fields`.
`fields` is the quickest way to drop the per-pitch lists when you only need the
at-bat outcomes:

```bash
sports-skills mlb get_mlbstats_play_by_play --game_pk=775296 --fields=event,rbi
```

- `sort_by`: one column to sort by. Numbers (and numeric strings) sort numerically; missing values always go last.
- `descending`: `true` (default) or `false`; only used with `sort_by`.
- `limit`: positive integer, applied after sorting.
- `fields`: comma-separated keep-list. `inning`, `half`, `batter`, `pitcher` (play-by-play) or `season`, `team`, `game_pk`, `game_date` (player stats; stat keys such as `homeRuns` are addressable directly) and the `sort_by` column are always kept.
- An unknown `sort_by`/`fields` column returns an error listing the valid columns.
- With any of these set, the response adds `total_rows` (matching rows before `limit`) and `returned_rows`. With none set, output is unchanged. They are applied after the fetch, so they never change the upstream request or its replay entry.

## Using ESPN and the MLB Stats API Together

The `get_mlbstats_*` commands read statsapi.mlb.com — MLB's own open API. It
carries the analytics layer ESPN does not: per-pitch velocity/spin/location,
exit velocity and launch angle on balls in play, career splits by stat group,
and schedules back to 1901. The two sources use unrelated id systems:

- **Game ids.** MLB uses `gamePk` (e.g. `775296`); ESPN uses event ids
  (e.g. `401570367`). No shared column — join on the game date plus teams.
- **Team abbreviations.** Two teams differ: ESPN `ARI`/`CHW` vs MLB `AZ`/`CWS`.
  Every `get_mlbstats_*` team filter accepts either spelling, and rows carry
  both (`team_abbreviation`, `team_abbreviation_espn`).
- **Player ids.** MLB person ids (`660271`) and ESPN athlete ids are unrelated.
  Resolve names with `find_mlb_player`; ASCII spellings match accented names
  ("acuna" finds "Ronald Acuña Jr.").
- **Postponed games repeat.** A postponed or suspended game is listed twice
  under one `game_pk` in `get_mlbstats_schedule`: the original date has
  `rescheduled: true` (and `rescheduled_to`), the make-up has
  `rescheduled_from`. Drop `rescheduled` rows when counting games.
- **Schedule times.** `start_time` is UTC; `venue_timezone` is the ballpark's
  IANA zone (e.g. `America/New_York`, `null` if MLB omits it) and `local_date`
  is MLB's official (local) date.
- **Postseason `game_type` filters by date.** `game_type="worldseries"` with a
  date outside the World Series returns no games plus a `warnings` entry; drop
  `game_type`, or pass `team` + `season` with it to list the round's dates.
- **Leaders come grouped.** A category like `homeRuns` exists for hitting,
  catching, and pitching (home runs *allowed*); rows are labelled with
  `stat_group` — pass `stat_group=` to get just one.

Responses include MLB's `copyright` notice, passed through from the API.

## Examples

Example 1: Today's scores
User says: "What are today's MLB scores?"
Actions:
1. Call `get_scoreboard()`
Result: All live and recent MLB games with scores by inning and status

Example 2: Division standings
User says: "Show me the AL East standings"
Actions:
1. Derive season year from `currentDate`
2. Call `get_standings(season=<derived_year>)`
3. Filter results for American League East
Result: AL East standings with W-L, PCT, GB, run differential

Example 3: Team roster
User says: "Who's on the Yankees roster?"
Actions:
1. Call `get_team_roster(team_id="10")`
Result: Full Yankees roster with name, position, bats/throws, height, weight

Example 4: Game box score
User says: "Show me the full box score for last night's Dodgers game"
Actions:
1. Call `get_scoreboard(date="<yesterday>")` to find the event_id
2. Call `get_game_summary(event_id=<id>)` for full box score
Result: Complete box score with batting/pitching stats per player

Example 5: Injury report
User says: "Who's on the IL for the Yankees?"
Actions:
1. Call `get_injuries()`
2. Filter results for New York Yankees (team_id=10)
Result: Yankees IL list with player name, position, IL type, and injury detail

Example 6: Player statistics
User says: "Show me Shohei Ohtani's stats"
Actions:
1. Derive season year from `currentDate`
2. Call `get_player_stats(player_id="39832", season_year=<derived_year>)`
Result: Season stats by category (batting, pitching) with value, rank, and per-game averages

Example 7: World Series odds
User says: "Who's favored to win the World Series?"
Actions:
1. Call `get_futures(limit=10)`
Result: Top World Series contenders with odds values

## Commands that DO NOT exist — never call these

- ~~`get_odds`~~ / ~~`get_betting_odds`~~ — not available. For prediction market odds, use the polymarket or kalshi skill.
- ~~`search_teams`~~ — does not exist. Use `get_teams` instead.
- ~~`get_box_score`~~ — does not exist. Use `get_game_summary` instead.
- ~~`get_player_ratings`~~ — does not exist. Use `get_player_stats` instead.

If a command is not listed in the Commands table above, it does not exist.

## Error Handling

When a command fails, **do not surface raw errors to the user**. Instead:
1. Catch silently and try alternatives
2. If team name given instead of ID, use `get_teams` to find the ID first
3. Only report failure with a clean message after exhausting alternatives

## Troubleshooting

Error: `sports-skills` command not found
Cause: Package not installed
Solution: Run `pip install sports-skills`

Error: Team not found by ID
Cause: Wrong or outdated ESPN team ID used
Solution: Call `get_teams` to get the current list of all 30 MLB teams with their IDs

Error: No data returned for a future game
Cause: ESPN only returns data for completed or in-progress games
Solution: Use `get_schedule` to see upcoming game details; `get_scoreboard` only covers active/recent games

Error: Offseason — scoreboard returns 0 events
Cause: No games scheduled during the offseason (November–March)
Solution: Use `get_standings` or `get_news` instead; MLB offseason transactions are available via `get_transactions`

© machina-sports · MIT · machina-sports/sports-skills

Similar skills

All skills for Data and databases →

From the same set22

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor