Skip to main content
Glama
guillochon

mlb-api-mcp

get_mlb_team_info

Retrieve detailed MLB team information by ID, name, abbreviation, or location. Access team data including statistics, season details, and additional fields through structured queries.

Instructions

Get information about a specific team by ID or name.

Args: team (str): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location. season (Optional[int]): Season year. sport_id (Optional[int]): Sport ID. hydrate (Optional[str]): Additional data to hydrate. fields (Optional[str]): Comma-separated list of fields to include.

Returns: dict: Team information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
teamYes
seasonNo
sport_idNo
hydrateNo
fieldsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_mlb_team_info' tool. It is decorated with @mcp.tool(), which registers the tool and infers the schema from the type hints and docstring. The function resolves the team name/ID using a helper, fetches team information from the MLB stats API, and returns the data or an error.
    @mcp.tool()
    def get_mlb_team_info(
        team: str,
        season: Optional[int] = None,
        sport_id: Optional[int] = None,
        hydrate: Optional[str] = None,
        fields: Optional[str] = None,
    ) -> dict:
        """
        Get information about a specific team by ID or name.
    
        Args:
            team (str): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location.
            season (Optional[int]): Season year.
            sport_id (Optional[int]): Sport ID.
            hydrate (Optional[str]): Additional data to hydrate.
            fields (Optional[str]): Comma-separated list of fields to include.
    
        Returns:
            dict: Team information.
        """
        try:
            params = {}
            if season is not None:
                params["season"] = season
            if sport_id is not None:
                params["sportId"] = sport_id
            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}'"}
            team_info = mlb.get_team(team_id, **params)
            return {"team_info": team_info}
        except Exception as e:
            return {"error": str(e)}
  • main.py:22-22 (registration)
    Invocation of setup_mlb_tools(mcp) in the main server file, which defines and registers the get_mlb_team_info tool (along with other MLB tools) on the MCP server instance.
    setup_mlb_tools(mcp)
  • get_team_id_from_name helper function: Maps a team string (name, partial name, or ID) to the numeric team ID by checking a local CSV file, used directly in the handler to resolve the 'team' parameter.
    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
  • get_team_abbreviation_from_name helper: Gets the 3-letter team abbreviation from name or ID, though not directly used in this tool.
    def get_team_abbreviation_from_name(team: str) -> Optional[str]:
        """
        Given a team name, partial name, or ID, return the 3-letter team abbreviation (e.g., 'NYY' for Yankees).
        Returns None if not found.
        """
        team_id = get_team_id_from_name(team)
        if team_id is None:
            return None
        team_info = mlb.get_team(team_id)
        return getattr(team_info, "abbreviation", None)
  • The function signature and docstring define the input schema (parameters like team: str, season: Optional[int], etc.) and output (dict with team_info or error), used by MCP for validation.
    def get_mlb_team_info(
        team: str,
        season: Optional[int] = None,
        sport_id: Optional[int] = None,
        hydrate: Optional[str] = None,
        fields: Optional[str] = None,
    ) -> dict:
        """
        Get information about a specific team by ID or name.
    
        Args:
            team (str): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location.
            season (Optional[int]): Season year.
            sport_id (Optional[int]): Sport ID.
            hydrate (Optional[str]): Additional data to hydrate.
            fields (Optional[str]): Comma-separated list of fields to include.
    
        Returns:
            dict: Team information.
        """
        try:
            params = {}
            if season is not None:
                params["season"] = season
            if sport_id is not None:
                params["sportId"] = sport_id
            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}'"}
            team_info = mlb.get_team(team_id, **params)
            return {"team_info": team_info}
        except Exception as e:
            return {"error": str(e)}
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 team information as a dict, which is helpful, but lacks critical details: it doesn't mention if this is a read-only operation (implied by 'Get' but not explicit), what permissions or authentication might be required, rate limits, error handling, or how the 'hydrate' and 'fields' parameters affect behavior. For a tool with 5 parameters and no annotations, this is insufficient.

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 appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by structured sections for args and returns. Every sentence adds value, with no redundancy. It could be slightly more concise by integrating the args list into the main text, but it's efficient overall.

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 complexity (5 parameters, no annotations, but an output schema exists), the description is partially complete. The output schema means the description doesn't need to detail return values, but it lacks behavioral context and full parameter guidance. It's adequate for basic use but has clear gaps for effective tool invocation, especially with 0% schema coverage and no annotations.

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

Parameters3/5

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

Schema description coverage is 0%, so the schema provides no parameter details. The description adds some semantics: it explains 'team' accepts ID or name in various formats, and lists other parameters with brief hints (e.g., 'season year' for 'season'). However, it doesn't fully compensate for the coverage gap—e.g., it doesn't explain valid formats for 'hydrate' or 'fields', or what 'sport_id' refers to. With 5 parameters, this leaves significant gaps.

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 information about a specific team by ID or name.' It specifies the verb ('Get information') and resource ('a specific team'), and distinguishes it from siblings like 'get_mlb_teams' (which likely lists teams) and 'get_mlb_search_teams' (which likely searches). However, it doesn't explicitly differentiate from 'get_mlb_roster' or 'get_mlb_standings', which might also provide team-related data, so it's not a perfect 5.

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 doesn't mention when to use 'get_mlb_team_info' over 'get_mlb_teams' (for listing teams) or 'get_mlb_search_teams' (for searching teams), nor does it specify prerequisites or exclusions. The agent must infer usage from the purpose alone.

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