Skip to main content
Glama
guillochon

mlb-api-mcp

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

Implementation Reference

  • 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

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