get_mlb_game_scoring_plays
Retrieve scoring plays and specific events from MLB games using game_id, with optional filters for event type, timecode, and fields. Ideal for accessing detailed baseball game data.
Instructions
Get plays for a specific game by game_id, with optional filtering by eventType.
Args: game_id (int): The game ID. eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run'). timecode (Optional[str]): Specific timecode for the play-by-play snapshot. fields (Optional[str]): Comma-separated list of fields to include.
Returns: dict: Game plays, optionally filtered by eventType.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| eventType | No | ||
| fields | No | ||
| game_id | Yes | ||
| timecode | No |
Implementation Reference
- mlb_api.py:485-516 (handler)The handler function that executes the get_mlb_game_scoring_plays tool. It fetches play-by-play data for a game using mlb.get_game_play_by_play and filters by eventType if specified.@mcp.tool() def get_mlb_game_scoring_plays( game_id: int, eventType: Optional[str] = None, timecode: Optional[str] = None, fields: Optional[str] = None ) -> dict: """ Get plays for a specific game by game_id, with optional filtering by eventType. Args: game_id (int): The game ID. eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run'). timecode (Optional[str]): Specific timecode for the play-by-play snapshot. fields (Optional[str]): Comma-separated list of fields to include. Returns: dict: Game plays, optionally filtered by eventType. """ try: params = {} if timecode is not None: params["timecode"] = timecode if fields is not None: params["fields"] = fields plays = mlb.get_game_play_by_play(game_id, **params) if eventType: filtered_plays = [ play for play in plays.allplays if getattr(play.result, "eventType", None) == eventType ] return {"plays": filtered_plays} else: return {"plays": plays.allplays} except Exception as e: return {"error": str(e)}
- mlb_api.py:485-516 (registration)The @mcp.tool() decorator registers the get_mlb_game_scoring_plays function as an MCP tool within setup_mlb_tools.@mcp.tool() def get_mlb_game_scoring_plays( game_id: int, eventType: Optional[str] = None, timecode: Optional[str] = None, fields: Optional[str] = None ) -> dict: """ Get plays for a specific game by game_id, with optional filtering by eventType. Args: game_id (int): The game ID. eventType (Optional[str]): Filter plays by this event type (e.g., 'scoring_play', 'home_run'). timecode (Optional[str]): Specific timecode for the play-by-play snapshot. fields (Optional[str]): Comma-separated list of fields to include. Returns: dict: Game plays, optionally filtered by eventType. """ try: params = {} if timecode is not None: params["timecode"] = timecode if fields is not None: params["fields"] = fields plays = mlb.get_game_play_by_play(game_id, **params) if eventType: filtered_plays = [ play for play in plays.allplays if getattr(play.result, "eventType", None) == eventType ] return {"plays": filtered_plays} else: return {"plays": plays.allplays} except Exception as e: return {"error": str(e)}
- main.py:22-22 (registration)Calls setup_mlb_tools(mcp) to register all MLB tools including get_mlb_game_scoring_plays.setup_mlb_tools(mcp)