Skip to main content
Glama
alex-rimerman

Statcast MCP Server

team_season_batting_stats

Retrieve comprehensive batting statistics for an entire MLB team's roster during a specific season, including individual player data like plate appearances, home runs, averages, and WAR.

Instructions

Full-season actual batting stats for one MLB team (entire roster).

Uses FanGraphs when available; if that fails or returns no rows, falls back to scraping Baseball Reference's team page (same numbers as the site: PA, HR, AVG/OBP/SLG, OPS+, WAR, etc.).

Args: team: 3-letter team abbreviation — same as Baseball Reference (e.g. PHI, NYY, LAD, ARI). season: Calendar year of the season (e.g. 2025). min_plate_appearances: Minimum PA to include on the FanGraphs pull (default 1). Ignored for the BRef fallback, which lists everyone who appeared. player_name: Optional. Restrict to one player (e.g. Bryce Harper).

Use this for “Phillies lineup stats”, “Yankees 2024 hitters”, etc. For league leaderboards without a team filter, use season_batting_stats instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
teamYes
seasonYes
min_plate_appearancesNo
player_nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler function `team_season_batting_stats` is defined and registered using the `@mcp.tool()` decorator. It fetches batting stats using pybaseball or fallback scraping and returns a formatted string.
    @mcp.tool()
    def team_season_batting_stats(
        team: str,
        season: int,
        min_plate_appearances: int = 1,
        player_name: str | None = None,
    ) -> str:
        """Full-season **actual** batting stats for one MLB team (entire roster).
    
        Uses **FanGraphs** when available; if that fails or returns no rows, falls back to
        scraping **Baseball Reference**'s team page (same numbers as the site: PA, HR,
        AVG/OBP/SLG, OPS+, WAR, etc.).
    
        Args:
            team: 3-letter team abbreviation — same as Baseball Reference
                (e.g. ``PHI``, ``NYY``, ``LAD``, ``ARI``).
            season: Calendar year of the season (e.g. 2025).
            min_plate_appearances: Minimum PA to include on the FanGraphs pull (default 1).
                Ignored for the BRef fallback, which lists everyone who appeared.
            player_name: Optional. Restrict to one player (e.g. ``Bryce Harper``).
    
        Use this for “Phillies lineup stats”, “Yankees 2024 hitters”, etc. For **league**
        leaderboards without a team filter, use ``season_batting_stats`` instead.
        """
        from pybaseball import batting_stats
    
        abbr = _normalize_team_abbr(team)
        data: pd.DataFrame | None = None
        fg_note = ""
        try:
            data = batting_stats(
                season, season, team=abbr, qual=min_plate_appearances
            )
            if data is None or getattr(data, "empty", True):
                fg_note = "FanGraphs returned no rows."
                data = None
        except Exception as e:
            fg_note = str(e)
            data = None
    
        source = "FanGraphs"
        if data is None or data.empty:
            try:
                data = _team_batting_from_bref(abbr, season)
                source = "Baseball Reference"
                if fg_note:
                    source += f" — {fg_note}"
            except Exception as e2:
                return (
                    f"Could not load team batting stats for {abbr} {season}. "
                    f"FanGraphs: {fg_note}. Baseball Reference: {e2}"
                )
    
        if player_name:
            try:
                data = _filter_player_rows(data, player_name)
            except ValueError as e:
                return str(e)
            if data.empty:
                return (
                    f"No batting row for {player_name!r} on team {abbr} in {season} "
                    "(check spelling and team)."
                )
    
        header = f"**Source:** {source}\n**Team:** {abbr} | **Season:** {season}\n\n"
        return header + _fmt(data, max_rows=200)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. Discloses data sources (FanGraphs primary, BRef fallback), fallback trigger conditions ('if that fails or returns no rows'), and behavioral quirk (min_plate_appearances ignored for BRef). Lists representative output fields (PA, HR, AVG/OBP/SLG, OPS+, WAR). Minor gap: doesn't explicitly state read-only nature or rate limits, though implied by 'stats' retrieval pattern.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Efficient structure: scope sentence → data source/fallback paragraph → Args section → usage guidelines. Every sentence earns its place; no tautology or filler. Markdown bolding and code blocks enhance scannability. Front-loaded with the essential 'what' before implementation details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Comprehensive for a 4-parameter tool with output schema (so return values need minimal description). Covers scope, data sources, all parameters (given 0% schema coverage), sibling alternatives, and use case examples. The mention of specific stat categories (OPS+, WAR) provides appropriate context for what 'batting stats' entails without needing to replicate the output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% (no property descriptions), requiring full compensation. The 'Args' section documents all 4 parameters with precise semantics: team abbreviations with examples (PHI, NYY), season as calendar year, min_plate_appearances with default value and fallback caveat, and player_name as optional filter with example. Fully compensates for empty schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with specific scope: 'Full-season **actual** batting stats for one MLB team (entire roster)'—clear verb (stats), resource (MLB team), and scope. Explicitly distinguishes from sibling `season_batting_stats` ('For **league** leaderboards... use ``season_batting_stats`` instead') and implicitly from `team_season_pitching_stats` via resource specificity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use examples ('Phillies lineup stats', 'Yankees 2024 hitters') and explicit alternative for the wrong use case (league leaderboards → `season_batting_stats`). Also documents fallback behavior (FanGraphs → Baseball Reference) so users understand data provenance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/alex-rimerman/statcast-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server