get_mlb_standings
Retrieve MLB standings for a specified season, league, or date using customizable parameters like standings type, hydration, and fields. Ideal for accessing up-to-date baseball statistics and league rankings.
Instructions
Get current MLB standings for a given season (year).
Args: season (Optional[int]): The year for which to retrieve standings. Defaults to current year. standingsTypes (Optional[str]): The type of standings to retrieve (e.g., 'regularSeason', 'wildCard', etc.). date (Optional[str]): Date in 'YYYY-MM-DD' format. hydrate (Optional[str]): Additional data to hydrate in the response. fields (Optional[str]): Comma-separated list of fields to include in the response. league (str): Filter by league. Accepts 'AL', 'NL', or 'both' (default: 'both').
Returns: dict: Standings for the specified league(s) and season.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | ||
| fields | No | ||
| hydrate | No | ||
| league | No | both | |
| season | No | ||
| standingsTypes | No |
Implementation Reference
- mlb_api.py:224-270 (handler)The handler function for 'get_mlb_standings' tool. It retrieves MLB standings for specified season and league (AL, NL, or both) using the mlbstatsapi library. The function signature defines the input schema, and it handles current year by default.@mcp.tool() def get_mlb_standings( season: Optional[int] = None, standingsTypes: Optional[str] = None, date: Optional[str] = None, hydrate: Optional[str] = None, fields: Optional[str] = None, league: str = "both", ) -> dict: """ Get current MLB standings for a given season (year). Args: season (Optional[int]): The year for which to retrieve standings. Defaults to current year. standingsTypes (Optional[str]): The type of standings to retrieve (e.g., 'regularSeason', 'wildCard', etc.). date (Optional[str]): Date in 'YYYY-MM-DD' format. hydrate (Optional[str]): Additional data to hydrate in the response. fields (Optional[str]): Comma-separated list of fields to include in the response. league (str): Filter by league. Accepts 'AL', 'NL', or 'both' (default: 'both'). Returns: dict: Standings for the specified league(s) and season. """ try: if season is None: season = datetime.now().year params = {} if standingsTypes is not None: params["standingsTypes"] = standingsTypes if date is not None: params["date"] = date if hydrate is not None: params["hydrate"] = hydrate if fields is not None: params["fields"] = fields league = league.upper() result = {} if league == "AL" or league == "BOTH": result["AL"] = mlb.get_standings(103, season=str(season), **params) if league == "NL" or league == "BOTH": result["NL"] = mlb.get_standings(104, season=str(season), **params) if not result: return {"error": "Invalid league parameter. Use 'AL', 'NL', or 'both'."} return {"standings": result} except Exception as e: return {"error": str(e)}
- main.py:21-23 (registration)Registration of the tool by calling setup_mlb_tools(mcp), which defines and registers all MLB tools including get_mlb_standings using the @mcp.tool() decorator.# Setup all MLB and generic tools setup_mlb_tools(mcp) setup_generic_tools(mcp)
- mlb_api.py:221-221 (registration)The setup function that contains the @mcp.tool() decorator and definition for get_mlb_standings, effectively registering it when called.def setup_mlb_tools(mcp):