Skip to main content
Glama

get_multiple_mlb_player_stats

Retrieve MLB player statistics by specifying player IDs, season, stat group, type, and optional event type for detailed baseball data analysis and integration.

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
eventTypeNo
groupNo
player_idsYes
seasonNo
typeNo

Implementation Reference

  • Main handler function for get_multiple_mlb_player_stats tool, decorated with @mcp.tool(). Handles input parameters, calls helper function get_multiple_player_stats, and returns player stats or 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)}
  • main.py:12-23 (registration)
    Imports and calls setup_mlb_tools(mcp), which defines and registers the get_multiple_mlb_player_stats tool using the @mcp.tool() decorator.
    from mlb_api import setup_mlb_tools # Suppress websockets deprecation warnings warnings.filterwarnings("ignore", category=DeprecationWarning, module="websockets") warnings.filterwarnings("ignore", category=DeprecationWarning, module="uvicorn.protocols.websockets") # Create FastMCP server instance mcp = FastMCP("MLB API MCP Server") # Setup all MLB and generic tools setup_mlb_tools(mcp) setup_generic_tools(mcp)
  • Helper utility function that queries the MLB stats API for multiple players' stats based on stats types, groups, and season. Called by the main handler.
    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
  • Function signature defining the input schema (parameters) and output type for the tool, used by MCP for validation.
    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:

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