Skip to main content
Glama
guillochon

mlb-api-mcp

get_mlb_schedule

Retrieve MLB game schedules by date range, team, or sport ID to access baseball game information and plan viewing.

Instructions

Get MLB schedule for a specific date range, sport ID, or team (ID or name).

Args: sport_id (int): Sport ID (default: 1 for MLB). start_date (str): Start date in 'YYYY-MM-DD' format. Required. end_date (str): End date in 'YYYY-MM-DD' format. Required. team (Optional[str]): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or location. If not provided, defaults to all teams.

Returns: dict: Schedule data for the specified parameters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYes
end_dateYes
sport_idNo
teamNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the core logic for the 'get_mlb_schedule' tool. It validates dates, resolves team IDs, fetches the schedule from the MLB API, and handles errors.
    def get_mlb_schedule(
        start_date: str,
        end_date: str,
        sport_id: int = 1,
        team: Optional[str] = None,
    ) -> dict:
        """
        Get MLB schedule for a specific date range, sport ID, or team (ID or name).
    
        Args:
            sport_id (int): Sport ID (default: 1 for MLB).
            start_date (str): Start date in 'YYYY-MM-DD' format. Required.
            end_date (str): End date in 'YYYY-MM-DD' format. Required.
            team (Optional[str]): Team ID or team name as a string. Can be numeric string, full name, abbreviation, or
              location. If not provided, defaults to all teams.
    
        Returns:
            dict: Schedule data for the specified parameters.
        """
        try:
            # Validate date range
            date_error = validate_date_range(start_date, end_date)
            if date_error:
                return date_error
            team_id = get_team_id_from_name(team) if team is not None else None
            schedule = mlb.get_schedule(
                start_date=start_date,
                end_date=end_date,
                sport_id=sport_id,
                team_id=team_id,
            )
            if not schedule:
                return {
                    "error": (
                        f"No games found for the given date range ({start_date} to {end_date}). The date range may "
                        "have resulted in nothing being returned."
                    )
                }
            return {"schedule": schedule}
        except Exception as e:
            return {"error": str(e)}
  • main.py:22-22 (registration)
    The call to setup_mlb_tools(mcp) which defines and registers all MLB tools, including 'get_mlb_schedule', with the MCP server instance.
    setup_mlb_tools(mcp)
  • Helper function to resolve team ID from team name, partial name, or ID string. Used in get_mlb_schedule to filter by team.
    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
  • Helper function for date range validation. Called at the start of get_mlb_schedule to ensure valid input dates.
    def validate_date_range(start_date: str, end_date: str) -> Optional[dict]:
        """
        Utility to check that start_date is before or equal to end_date.
        Returns an error dict if invalid, else None.
        """
        try:
            start = datetime.strptime(start_date, "%Y-%m-%d")
            end = datetime.strptime(end_date, "%Y-%m-%d")
            if start > end:
                return {"error": f"start_date ({start_date}) must be before or equal to end_date ({end_date})"}
        except Exception as e:
            return {"error": f"Invalid date format: {e}"}
        return None
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the tool returns schedule data, it doesn't describe important behavioral aspects like whether this is a read-only operation (implied but not stated), potential rate limits, authentication requirements, error conditions, or what format the schedule data takes beyond 'dict'. The description provides basic functionality but lacks operational context.

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 with a clear purpose statement followed by organized sections for Args and Returns. Every sentence earns its place by providing essential information. It could be slightly more concise by integrating the parameter details more fluidly, but the structure is effective and information-dense without waste.

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

Completeness4/5

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

Given the tool's moderate complexity (4 parameters, filtering logic), no annotations, but with an output schema present, the description provides good coverage. The parameter semantics are thoroughly explained, and the presence of an output schema means the description doesn't need to detail return values. However, it lacks some behavioral context that would be helpful for a tool with filtering capabilities.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing detailed semantic information for all 4 parameters. It explains what each parameter represents (sport_id defaults to 1 for MLB, start_date/end_date format requirements, team can be ID or name with multiple formats), their requirements (start_date and end_date are required), and default behaviors. This adds significant value beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('Get MLB schedule') and resources involved (date range, sport ID, team). It distinguishes itself from sibling tools like get_mlb_standings, get_mlb_teams, or get_mlb_boxscore by focusing specifically on schedule retrieval rather than standings, team lists, or game details.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (to get schedule data with specific filtering parameters). It doesn't explicitly mention when NOT to use it or name specific alternatives among the sibling tools, but the purpose is sufficiently distinct that the appropriate use case is evident from the description 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