Skip to main content
Glama
alex-rimerman

Statcast MCP Server

team_season_pitching_stats

Retrieve full-season pitching statistics for an MLB team, including rotation and bullpen data from FanGraphs or Baseball Reference. Specify team abbreviation, season year, and optional pitcher name to access ERA, wins, strikeouts, WAR, and other metrics.

Instructions

Full-season actual pitching stats for one MLB team (rotation + bullpen).

Uses FanGraphs when available; otherwise scrapes Baseball Reference's team pitching table (W, L, ERA, G, GS, SV, IP, SO, WAR, etc.).

Args: team: 3-letter abbreviation (e.g. PHI, NYY). season: Season year (e.g. 2025). min_innings: Minimum IP for the FanGraphs pull (default 1). Ignored for BRef fallback (full staff). player_name: Optional. One pitcher (e.g. Zack Wheeler).

Split rotation vs bullpen by sorting on GS in the table (starters vs relievers). For league-wide pitching only, use season_pitching_stats.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
teamYes
seasonYes
min_inningsNo
player_nameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The implementation of the team_season_pitching_stats tool, which fetches and formats team pitching statistics from FanGraphs or Baseball Reference.
    @mcp.tool()
    def team_season_pitching_stats(
        team: str,
        season: int,
        min_innings: int = 1,
        player_name: str | None = None,
    ) -> str:
        """Full-season **actual** pitching stats for one MLB team (rotation + bullpen).
    
        Uses **FanGraphs** when available; otherwise scrapes **Baseball Reference**'s team
        pitching table (W, L, ERA, G, GS, SV, IP, SO, WAR, etc.).
    
        Args:
            team: 3-letter abbreviation (e.g. ``PHI``, ``NYY``).
            season: Season year (e.g. 2025).
            min_innings: Minimum IP for the FanGraphs pull (default 1). Ignored for BRef
                fallback (full staff).
            player_name: Optional. One pitcher (e.g. ``Zack Wheeler``).
    
        Split **rotation vs bullpen** by sorting on ``GS`` in the table (starters vs relievers).
        For league-wide pitching only, use ``season_pitching_stats``.
        """
        from pybaseball import pitching_stats
    
        abbr = _normalize_team_abbr(team)
        data: pd.DataFrame | None = None
        fg_note = ""
        try:
            data = pitching_stats(season, season, team=abbr, qual=min_innings)
            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_pitching_from_bref(abbr, season)
                source = "Baseball Reference"
                if fg_note:
                    source += f" — {fg_note}"
            except Exception as e2:
                return (
                    f"Could not load team pitching 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 pitching row for {player_name!r} on team {abbr} in {season}."
                )
    
        header = f"**Source:** {source}\n**Team:** {abbr} | **Season:** {season}\n\n"
        return header + _fmt(data, max_rows=200)
    
    
    # ---------------------------------------------------------------------------
    # Tools — Statcast Leaderboards (Expected Stats & Exit Velocity)
    # ---------------------------------------------------------------------------
    
    
    @mcp.tool()
    def statcast_batter_expected_stats(
        year: int,
        min_plate_appearances: int = 50,
        player_name: str | None = None,
    ) -> str:
        """Get expected batting stats (xBA, xSLG, xwOBA vs actual) from Statcast.
    
        Returns xBA, xSLG, xwOBA and the gap from actual stats — what a batter
        *deserves* based on quality of contact.
    
        Args:
            year: Season year (e.g. 2024).
            min_plate_appearances: Minimum PA to qualify (default 50).
            player_name: Optional. If set (e.g. 'Aaron Judge'), returns only that
                player's row — use this so a star is not cut off by the 50-row
                leaderboard limit.
    
        Great for identifying lucky/unlucky hitters or a single player's expected line.
        """
        from pybaseball import statcast_batter_expected_stats as _fn
    
        try:
            data = _fn(year, minPA=min_plate_appearances)
        except Exception as e:
            return f"Error fetching expected batting stats: {e}"
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 source priority (FanGraphs primary, BRef fallback), filtering logic differences (min_innings ignored for BRef), and result interpretation methodology (GS sorting for rotation/bullpen). Does not mention rate limits or auth requirements, preventing a 5.

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?

Uses structured Args section with backtick formatting for code examples. Every sentence adds value: data source disclosure, parameter semantics, usage guidance, and result interpretation. No wasted words despite comprehensive coverage.

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?

Given output schema exists (per context signals), description appropriately focuses on conceptual behavior, data sources, and usage patterns rather than return value structure. Covers all 4 parameters comprehensively and explains business logic (rotation/bullpen split).

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%, requiring full compensation. Description excellently documents all 4 parameters: team (3-letter abbrev with examples), season (year format), min_innings (default value and behavioral note about BRef ignorance), and player_name (optional with example).

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?

Description opens with specific verb+resource ('Full-season actual pitching stats for one MLB team') and explicitly distinguishes from sibling 'season_pitching_stats' by contrasting team-specific vs league-wide scope. Clear differentiation of rotation vs bullpen adds further 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?

Explicitly states when-not-to-use and alternative: 'For league-wide pitching only, use `season_pitching_stats`' provides clear guidance. Also clarifies FanGraphs vs Baseball Reference fallback behavior and how to interpret results (splitting rotation/bullpen via GS sorting).

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