Skip to main content
Glama
guillochon

mlb-api-mcp

get_multiple_mlb_player_stats

Retrieve MLB player statistics for multiple players by specifying IDs, season, stat group, and type to analyze performance data.

Instructions

Get player stats by comma separated player_ids, group, type, season, and optional eventType.

Args: player_ids (str): Comma-separated list of player IDs. group (Optional[str]): Stat group (e.g., hitting, pitching). type (Optional[str]): Stat type (e.g., season, career). season (Optional[int]): Season year. eventType (Optional[str]): Event type filter.

Returns: dict: Player statistics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
player_idsYes
groupNo
typeNo
seasonNo
eventTypeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_multiple_mlb_player_stats' tool. It parses input parameters, determines stats and groups, calls the helper function to fetch data from MLB API, and returns the player stats or an error.
    @mcp.tool()
    def get_multiple_mlb_player_stats(
        player_ids: str,
        group: Optional[str] = None,
        type: Optional[str] = None,
        season: Optional[int] = None,
        eventType: Optional[str] = None,
    ) -> dict:
        """
        Get player stats by comma separated player_ids, group, type, season, and optional eventType.
    
        Args:
            player_ids (str): Comma-separated list of player IDs.
            group (Optional[str]): Stat group (e.g., hitting, pitching).
            type (Optional[str]): Stat type (e.g., season, career).
            season (Optional[int]): Season year.
            eventType (Optional[str]): Event type filter.
    
        Returns:
            dict: Player statistics.
        """
        try:
            player_ids_list = [pid.strip() for pid in player_ids.split(",")]
    
            # Use the helper function from the original code
            stats = ["season", "seasonAdvanced"] if type == "season" else ["career"]
            groups = [group] if group else ["hitting"]
    
            splits = get_multiple_player_stats(mlb, player_ids_list, stats, groups, season)
            return {"player_stats": splits}
        except Exception as e:
            return {"error": str(e)}
  • Key helper function that makes the actual API call to MLB stats API (/people endpoint with hydrate=stats) to retrieve stats for multiple players and processes the response into splits.
    def get_multiple_player_stats(
        mlb, person_ids: list, stats: list, groups: list, season: Optional[int] = None, **params
    ) -> dict:
        """
        returns stat data for a team
    
        Parameters
        ----------
        mlb : mlbstatsapi.Mlb
            The MLB stats API instance
        person_ids : list
            the person ids
        stats : list
            list of stat types. List of statTypes can be found at https://statsapi.mlb.com/api/v1/statTypes
        groups : list
            list of stat grous. List of statGroups can be found at https://statsapi.mlb.com/api/v1/statGroups
        season : str, optional
            Insert year to return team stats for a particular season, season=2018
        eventType : str, optional
            Notes for individual events for playLog, playlog can be filered by individual events.
            List of eventTypes can be found at https://statsapi.mlb.com/api/v1/eventTypes
    
        Returns
        -------
        dict
            returns a dict of stats
    
        See Also
        --------
        Mlb.get_stats : Get stats
        Mlb.get_team_stats : Get team stats
        Mlb.get_players_stats_for_game : Get player stats for a game
    
        Examples
        --------
        >>> mlb = Mlb()
        >>> stats = ['season', 'seasonAdvanced']
        >>> groups = ['hitting']
        >>> mlb.get_player_stats(647351, stats, groups)
        {'hitting': {'season': [HittingSeason], 'seasonadvanced': [HittingSeasonAdvanced] }}
        """
        from mlbstatsapi import mlb_module
    
        params["stats"] = stats
        params["group"] = groups
    
        hydrate_arr = []
        if groups:
            hydrate_arr.append(f"group=[{','.join(groups)}]")
        if stats:
            hydrate_arr.append(f"type=[{','.join(stats)}]")
        if season:
            hydrate_arr.append(f"season={season}")
    
        mlb_data = mlb._mlb_adapter_v1.get(
            endpoint=f"people?personIds={','.join(person_ids)}&hydrate=stats({','.join(hydrate_arr)})"
        )
        if 400 <= mlb_data.status_code <= 499:
            return {}
    
        splits = []
    
        for person in mlb_data.data["people"]:
            if person.get("stats"):
                splits.append(mlb_module.create_split_data(person["stats"]))
    
        return splits
  • main.py:21-23 (registration)
    The point where MLB tools, including 'get_multiple_mlb_player_stats', are registered to the MCP server instance by calling setup_mlb_tools(mcp). This setup function defines all @mcp.tool() decorated functions.
    # Setup all MLB and generic tools
    setup_mlb_tools(mcp)
    setup_generic_tools(mcp)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'Get[s] player stats' but doesn't mention whether this is a read-only operation, requires authentication, has rate limits, or what happens with invalid inputs. The description lacks behavioral traits beyond the basic action, leaving significant gaps for an agent.

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

Conciseness4/5

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

The description is well-structured and appropriately sized. It starts with a clear purpose statement, followed by an 'Args' section listing parameters with brief semantics, and a 'Returns' section. There's minimal waste, though the 'Args' and 'Returns' labels add slight redundancy. Overall, it's efficient and front-loaded.

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

Completeness3/5

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

Given the tool's moderate complexity (5 parameters, 1 required) and no annotations, the description is partially complete. It covers the purpose and parameters but lacks behavioral context and usage guidelines. The presence of an output schema (implied by 'Returns: dict') reduces the need to explain return values, but overall, it's adequate with clear gaps for a statistical query tool.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It lists all 5 parameters with brief explanations (e.g., 'Stat group (e.g., hitting, pitching)'), adding meaning beyond the schema. However, it doesn't provide full details like valid values for 'group' or 'type', or how 'player_ids' are formatted, leaving some ambiguity. With 0% coverage, this is a moderate improvement but incomplete.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get player stats by comma separated player_ids, group, type, season, and optional eventType.' It specifies the verb ('Get'), resource ('player stats'), and key parameters. However, it doesn't explicitly differentiate from sibling tools like 'get_mlb_player_info' or 'get_statcast_batter', which likely serve different statistical purposes.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools for MLB data (e.g., 'get_mlb_player_info', 'get_statcast_batter'), there's no indication of how this tool differs in scope or when it's preferred. The description merely lists parameters without contextual usage advice.

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/guillochon/mlb-api-mcp'

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