Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
eventTypeNo
fieldsNo
game_idYes
timecodeNo

Implementation Reference

  • 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)

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