Skip to main content
Glama
guillochon

mlb-api-mcp

get_mlb_roster

Retrieve MLB team rosters by team name or ID, with options to filter by date, season, roster type, and specific data fields.

Instructions

Get team roster for a specific team (ID or name), with optional filters.

Args: team (str): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location. date (Optional[str]): Date in 'YYYY-MM-DD' format. If not provided, defaults to today. rosterType (Optional[str]): Filter by roster type (e.g., 40Man, fullSeason, etc.). season (Optional[str]): Filter by single season (year). hydrate (Optional[str]): Additional data to hydrate in the response. fields (Optional[str]): Comma-separated list of fields to include.

Returns: dict: Team roster information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
teamYes
dateNo
rosterTypeNo
seasonNo
hydrateNo
fieldsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_mlb_roster' tool, decorated with @mcp.tool() for automatic registration in the MCP server. It resolves the team ID using a helper, constructs parameters, calls mlb.get_team_roster(), and handles errors. The docstring and type hints define the input schema.
    @mcp.tool()
    def get_mlb_roster(
        team: str,
        date: Optional[str] = None,
        rosterType: Optional[str] = None,
        season: Optional[str] = None,
        hydrate: Optional[str] = None,
        fields: Optional[str] = None,
    ) -> dict:
        """
        Get team roster for a specific team (ID or name), with optional filters.
    
        Args:
            team (str): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location.
            date (Optional[str]): Date in 'YYYY-MM-DD' format. If not provided, defaults to today.
            rosterType (Optional[str]): Filter by roster type (e.g., 40Man, fullSeason, etc.).
            season (Optional[str]): Filter by single season (year).
            hydrate (Optional[str]): Additional data to hydrate in the response.
            fields (Optional[str]): Comma-separated list of fields to include.
    
        Returns:
            dict: Team roster information.
        """
        try:
            if date is None:
                date = datetime.now().strftime("%Y-%m-%d")
            params = {}
            if rosterType is not None:
                params["rosterType"] = rosterType
            if season is not None:
                params["season"] = season
            params["date"] = date
            if hydrate is not None:
                params["hydrate"] = hydrate
            if fields is not None:
                params["fields"] = fields
            team_id = get_team_id_from_name(team)
            if team_id is None:
                return {"error": f"Could not find team ID for '{team}'"}
            roster = mlb.get_team_roster(team_id, **params)
            return roster
        except Exception as e:
            return {"error": str(e)}
  • Helper utility function used by get_mlb_roster to resolve a team name (full, partial, or ID string) to a numeric team ID by checking a local CSV file.
    def get_team_id_from_name(team: str) -> Optional[int]:
        """Helper to get team ID from team name, partial name, or stringified ID."""
        # Accept stringified integer as ID
        try:
            return int(team)
        except (ValueError, TypeError):
            pass
        import csv
    
        team_lower = team.lower().strip()
        with open("current_mlb_teams.csv", "r") as f:
            reader = csv.DictReader(f)
            # First, try exact match
            for row in reader:
                if team_lower == row["team_name"].lower().strip():
                    return int(row["team_id"])
            f.seek(0)
            next(reader)  # skip header
            # Then, try substring match
            for row in reader:
                if team_lower in row["team_name"].lower():
                    return int(row["team_id"])
        return None
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns a dict with team roster information, but lacks details on permissions, rate limits, error handling, or data freshness. For a read operation with 6 parameters, this is insufficient to inform the agent about operational constraints or expected behavior beyond basic output.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It front-loads the purpose, then details args and returns in clear sections. Each sentence adds value, with no redundant information. It could be slightly more concise by integrating the purpose with parameter explanations, but overall it's efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, no annotations, output schema exists), the description is moderately complete. It covers the purpose and parameter semantics adequately, and the output schema handles return values. However, it lacks behavioral context (e.g., error cases, performance) and usage guidelines, which are gaps for a tool with multiple optional filters and sibling alternatives.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It effectively adds meaning by explaining each parameter's purpose and format (e.g., team can be 'numeric string, full name, abbreviation, or location', date format 'YYYY-MM-DD', fields as 'comma-separated list'). This clarifies usage beyond the bare schema, though it doesn't cover all nuances like valid values for rosterType or hydrate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get team roster for a specific team (ID or name), with optional filters.' It specifies the verb ('Get'), resource ('team roster'), and scope ('specific team'), distinguishing it from siblings like get_mlb_team_info or get_mlb_teams. However, it doesn't explicitly differentiate from get_mlb_players, which might overlap in functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions optional filters but doesn't specify scenarios where this tool is preferred over siblings like get_mlb_players or get_mlb_team_info, nor does it mention prerequisites or exclusions. This leaves the agent without contextual usage cues.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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