get_mlb_players
Retrieve comprehensive MLB player data by sport ID and optional season filter for baseball statistics integration.
Instructions
Get all players for a specific sport.
Args: sport_id (int): Sport ID (default: 1 for MLB). season (Optional[int]): Filter players by a specific season (year).
Returns: dict: All players for the specified sport.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sport_id | No | ||
| season | No |
Implementation Reference
- mlb_api.py:598-618 (handler)The handler function for the 'get_mlb_players' MCP tool. Decorated with @mcp.tool() which registers the tool and infers the schema from type annotations and docstring. Fetches all MLB players using mlbstatsapi.Mlb().get_people().@mcp.tool() def get_mlb_players(sport_id: int = 1, season: Optional[int] = None) -> dict: """ Get all players for a specific sport. Args: sport_id (int): Sport ID (default: 1 for MLB). season (Optional[int]): Filter players by a specific season (year). Returns: dict: All players for the specified sport. """ try: params = {} if season is not None: params["season"] = season players = mlb.get_people(sport_id=sport_id, **params) return {"players": players} except Exception as e: return {"error": str(e)}
- main.py:21-23 (registration)Top-level registration of MLB tools (including get_mlb_players) by invoking setup_mlb_tools(mcp) in the main MCP server initialization.# Setup all MLB and generic tools setup_mlb_tools(mcp) setup_generic_tools(mcp)
- main.py:12-12 (registration)Import of the MLB tools setup function used for registration.from mlb_api import setup_mlb_tools