Skip to main content
Glama

get_mlb_teams

Retrieve all MLB teams for a specific sport using sport ID and optional season filter. Returns a dictionary of teams for easy integration with baseball data applications.

Instructions

Get all teams for a specific sport.

Args: sport_id (int): Sport ID (default: 1 for MLB). season (Optional[int]): Filter teams by a specific season (year).

Returns: dict: All teams for the specified sport.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
seasonNo
sport_idNo

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the logic for retrieving MLB teams using the mlbstatsapi.Mlb().get_teams() method. This is the core implementation of the tool.
    @mcp.tool() def get_mlb_teams(sport_id: int = 1, season: Optional[int] = None) -> dict: """ Get all teams for a specific sport. Args: sport_id (int): Sport ID (default: 1 for MLB). season (Optional[int]): Filter teams by a specific season (year). Returns: dict: All teams for the specified sport. """ try: params = {} if season is not None: params["season"] = season teams = mlb.get_teams(sport_id=sport_id, **params) return {"teams": teams} except Exception as e: return {"error": str(e)}
  • main.py:22-22 (registration)
    The call to setup_mlb_tools(mcp) in the main server initialization, which defines and registers all MLB tools including get_mlb_teams via the @mcp.tool() decorators.
    setup_mlb_tools(mcp)

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