# MLB Stats MCP

> MLB Stats connects your AI agent to a deep database of Major League Baseball information. Access real-time play-by-play feeds, detailed player profiles, historical statistics, team standings, and full league schedules instantly. It lets your agent act like a professional sabermetrician without leaving the chat window.

## Overview
- **Category:** data-analytics
- **Price:** Free
- **Tags:** baseball, mlb, sports-data, real-time-stats, player-analytics

## Description

When you connect your agent to MLB Stats, you're hooking it up to a deep database covering everything from live action to decades of player performance. It lets your AI client run complex sabermetric analysis without leaving the chat window. You don’t need an actual sports data platform; you just ask your agent what you want, and it calls the right tool.

**Real-Time Action & Performance Tracking**

You pull real-time boxscores, minute-by-minute play-by-play feeds, and current game status updates using `get_live_game_feed` for any active baseball contest. To dig into specific numbers—like a player's batting average or team ERA—you use `get_stats`, just gotta tell it what stat type and who you want data on. If you need to know the general profile of an athlete or whole franchise, `get_person` pulls that detailed information using their unique ID. To make sure your stats query is accurate, you first check the valid strings with `list_stat_types`. You can also confirm which sports levels are covered by checking the data types available via `list_sports`.

**Context and Structure Tools**

You gotta know what you're looking at before you pull the numbers. Your agent uses `list_leagues` to show every professional baseball league in the database, whether it’s MLB or a minor affiliate. If you wanna drill down further, `list_divisions` shows all existing divisions within those leagues. For team context, `list_teams` gives basic info on every major club and their minor league affiliates, while `list_venues` keeps track of the physical ballparks where games are played. You can narrow your focus by checking available player positions using `list_positions` or finding out what game state codes mean with `list_game_status`. If you’re just looking for a general list of players who play in those spots, `list_positions` gives you the code (like C for catcher or P for pitcher).

**Scheduling and Rankings**

To plan your analysis around specific dates, use `get_schedule`; it pulls the planned list of games and basic info across any date range you provide. If you need to know where teams stand in the pecking order, `get_standings` pulls current or historical league rankings, letting you filter by season or type. You can get a snapshot of all team placements using this tool. Finally, if you just wanna see what’s happening today and nothing else, you check `list_game_status` to confirm the valid codes (like 'Final' or 'In Progress') before calling any live data functions.

## Tools

### list_divisions
Lists all existing divisions within the league system.

### list_game_status
Shows valid codes for game states (e.g., Final, In Progress).

### list_leagues
Lists all professional baseball leagues available in the database.

### get_live_game_feed
Retrieves real-time play-by-play, boxscores, and status updates from an ongoing game.

### get_person
Gets detailed information about a specific MLB player or team using their identifier.

### list_positions
Provides a list of recognized player position codes (e.g., C, P, IF).

### get_schedule
Retrieves the planned list of games and basic info for any specified date range.

### list_sports
Lists all sports data types supported by the server (MLB and MiLB levels).

### get_standings
Pulls current or historical league standings, filtered by season and type.

### list_stat_types
Returns a valid list of strings you can use when requesting statistics.

### get_stats
Retrieves specific statistical data for any player or team (e.g., batting average, ERA).

### list_teams
Retrieves basic information about all MLB teams and their minor league affiliates.

### list_venues
Lists the physical ballparks or venues where games are played.

## Prompt Examples

**Prompt:** 
```
List all MLB teams and their IDs for the current season.
```

**Response:** 
```
I've retrieved the team list. Some examples include the Arizona Diamondbacks (ID: 109), Atlanta Braves (ID: 144), and Baltimore Orioles (ID: 110). Would you like to see the full list or details for a specific team?
```

**Prompt:** 
```
Show me the American League East standings for 2023.
```

**Response:** 
```
Fetching 2023 AL East standings... The Baltimore Orioles finished first with 101 wins, followed by the Tampa Bay Rays with 99 wins. Would you like the full breakdown including wild card status?
```

**Prompt:** 
```
Get the hitting stats for Shohei Ohtani (ID 660271) for the 2023 season.
```

**Response:** 
```
In 2023, Shohei Ohtani had a .304 batting average, 44 home runs, and 95 RBIs over 135 games. He also posted a 1.066 OPS. Would you like to see his pitching stats for the same year?
```

## Capabilities

### Retrieve live play-by-play feeds
Your AI client pulls real-time boxscores, game status updates, and minute-by-minute action from any active baseball game.

### Fetch detailed player information
The agent retrieves a specific athlete's profile, including team affiliation and basic details, using the person's ID.

### Calculate historical or current statistics
You get statistical data—like batting averages or ERA—for any player or team by specifying the stat type and time frame.

### Determine league structure
The agent lists all active leagues, divisions, and teams, allowing you to narrow down your search scope before pulling data.

### Check current standings and rankings
You pull the latest team rankings for a given league or division, including wins and losses.

## Use Cases

### Investigating player decline in a specific role
A journalist needs to prove that a star pitcher's ERA has consistently risen over three seasons. They tell their agent: 'Get the pitching stats for Player X from 2021, 2022, and 2023.' The agent calls `get_stats` multiple times with year filters, giving the journalist a clean data table ready for an article.

### Drafting fantasy team analysis mid-game
A user is checking their fantasy lineup. They ask: 'What are the live updates for the Yankees game right now?' The agent calls `get_live_game_feed` and provides real-time boxscores, allowing the manager to adjust their strategy instantly without opening a dedicated sports app.

### Building a team affiliation map
A developer needs to list every minor league affiliate for a major club. They start by running `list_teams` and then use the output IDs, chaining calls to understand the full organizational hierarchy of the MLB system.

### Checking regional standings quickly
A user only cares about the NL East race for 2018. Instead of browsing multiple league pages, they ask: 'Show me the 2018 American League East standings.' The agent runs `get_standings` and delivers the exact leaderboard.

## Benefits

- Real-Time Action: Use `get_live_game_feed` to get boxscores or play-by-play updates the second a pitch happens. You don't have to refresh any website.
- Deep Player Data: Instead of finding stats on five different pages, call `get_stats`. Specify the player ID and stat type, and you pull the exact number—hitting, pitching, fielding, etc.
- Contextual Awareness: Before pulling data, use tools like `list_leagues` or `list_teams`. This ensures your agent knows which division or league you're talking about, preventing bad queries.
- Historical Analysis: Need to compare 2019 stats vs. 2023 stats? Use `get_stats` across different years with minimal input, building complex reports instantly.
- Structured Planning: Plan around games using `get_schedule` for specific dates or check the current race with `get_standings`. It organizes the chaos of a season into clear data points.

## How It Works

The bottom line is: you ask a question in plain English; the server runs the specific database query needed, and you get the answer back instantly.

1. Subscribe to the MLB Stats server in your AI client's settings.
2. Tell your agent what data you need (e.g., 'What were the 2023 stats for the Braves?').
3. The agent interprets the request, calls the necessary tool (`get_stats` or `list_teams`), and returns structured data directly to your chat.

## Frequently Asked Questions

**How do I get live game feeds using `get_live_game_feed`?**
You must provide the specific game ID and date. The feed is real-time, so make sure the game is actually in progress for the data to return anything useful.

**Do I need `list_teams` before calling `get_stats`?**
It helps, but it's not always mandatory. Using `list_teams` first ensures you have the correct, current team ID to prevent stat retrieval failures.

**Can I get standings for a season that isn't the current one with `get_standings`?**
Yes, `get_standings` accepts historical parameters. Just specify the year and league when you run the query.

**What is the difference between `get_person` and `get_stats`?**
`get_person` gives basic profile data (name, team). You use `get_stats` to get metrics—the actual numbers like batting average or home runs.

**What if I want stats for a league that isn't in the main MLB system?**
Check `list_sports` first. This tells you exactly what levels of minor leagues (MiLB) or other sports are available to pull data from.

**If I need to filter stats by type, should I use `list_stat_types` before calling `get_stats`?**
Yes. You must run `list_stat_types` first. This returns a list of valid strings for the stats parameter, ensuring your agent passes an accepted value like 'HR' or 'ERA'. Using the correct type string prevents data retrieval errors.

**What happens if I exceed the query limit when calling `get_live_game_feed`?**
If you send too many requests, the server returns a rate-limit error. Your AI client should detect this 429 status code and implement an exponential backoff strategy. Don't hammer the endpoint; wait longer between calls.

**How do I know which leagues are supported before running `get_standings`?**
Run `list_leagues` to see all currently active league identifiers. You must use one of these IDs when calling `get_standings`. This prevents the agent from guessing and ensures your request targets a valid organizational structure.

**How can I get the play-by-play data for a game currently in progress?**
Use the `get_live_game_feed` tool with the specific `gamePk` (game ID). This provides the most detailed real-time feed, including play-by-play and boxscores.

**Can I retrieve historical statistics for a specific season?**
Yes! The `get_stats` and `get_standings` tools both accept a `season` parameter (e.g., 2023) to filter data for that specific year.

**How do I find the schedule for a specific team?**
You can use `get_schedule` with a date range. While the schedule tool returns all games, you can ask your AI agent to filter the results for a specific team name or ID found via `list_teams`.