Skip to main content
Glama

get_mlb_players

Retrieve MLB player data by specifying sport ID and optional season. Access comprehensive player statistics for baseball analytics.

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
NameRequiredDescriptionDefault
seasonNo
sport_idNo

Implementation Reference

  • The handler function implementing the logic for the 'get_mlb_players' tool. It fetches all MLB players using the mlbstatsapi library and handles errors. Registered via the @mcp.tool() decorator.
    @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:22-23 (registration)
    The setup_mlb_tools(mcp) call registers all MLB tools, including 'get_mlb_players', on the MCP server instance.
    setup_mlb_tools(mcp) setup_generic_tools(mcp)
  • mlb_api.py:598-617 (registration)
    The @mcp.tool() decorator on the handler function registers the tool with the MCP framework when setup_mlb_tools is executed.
    @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)}

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