get_mlb_boxscore
Retrieve detailed MLB game statistics by providing a game ID, with options to filter by specific timecodes or data fields for targeted analysis.
Instructions
Get boxscore for a specific game by game_id.
Args: game_id (int): The game ID. timecode (Optional[str]): Specific timecode for the boxscore snapshot. fields (Optional[str]): Comma-separated list of fields to include.
Returns: dict: Boxscore information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| game_id | Yes | ||
| timecode | No | ||
| fields | No |
Implementation Reference
- mlb_api.py:370-393 (handler)The handler function for the 'get_mlb_boxscore' tool. It retrieves the boxscore for a given game ID using the mlbstatsapi.Mlb().get_game_box_score method, with optional timecode and fields parameters. Errors are caught and returned as a dict.@mcp.tool() def get_mlb_boxscore(game_id: int, timecode: Optional[str] = None, fields: Optional[str] = None) -> dict: """ Get boxscore for a specific game by game_id. Args: game_id (int): The game ID. timecode (Optional[str]): Specific timecode for the boxscore snapshot. fields (Optional[str]): Comma-separated list of fields to include. Returns: dict: Boxscore information. """ try: params = {} if timecode is not None: params["timecode"] = timecode if fields is not None: params["fields"] = fields boxscore = mlb.get_game_box_score(game_id, **params) return boxscore except Exception as e: return {"error": str(e)}
- main.py:22-22 (registration)Registers the get_mlb_boxscore tool (and other MLB tools) by calling setup_mlb_tools(mcp), which defines the tool functions decorated with @mcp.tool().setup_mlb_tools(mcp)
- main.py:12-12 (registration)Imports the setup_mlb_tools function used to register the MLB tools including get_mlb_boxscore.from mlb_api import setup_mlb_tools