Skip to main content
Glama
guillochon

mlb-api-mcp

get_mlb_search_teams

Search for MLB teams by name or ID to retrieve detailed team information and statistics from baseball data sources.

Instructions

Search for teams by name or ID.

Args: team_name (str): Team name or ID to search for. search_key (str): Search key ("name", "id", or "all").

Returns: dict: Team search results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
team_nameYes
search_keyNoname

Implementation Reference

  • The handler function implementing the 'get_mlb_search_teams' tool. It loads MLB team data from 'current_mlb_teams.csv' and searches for matches based on team_name and search_key ('name', 'id', or 'all'), returning matching teams as a list of dicts or an error.
    @mcp.tool()
    def get_mlb_search_teams(team_name: str, search_key: str = "name") -> dict:
        """
        Search for teams by name or ID.
    
        Args:
            team_name (str): Team name or ID to search for.
            search_key (str): Search key ("name", "id", or "all").
    
        Returns:
            dict: Team search results.
        """
        try:
            import csv
    
            # Load teams from CSV
            teams = []
            with open("current_mlb_teams.csv", "r") as f:
                reader = csv.DictReader(f)
                for row in reader:
                    teams.append(row)
    
            # Search for teams
            results = []
            for team in teams:
                if search_key == "id":
                    if team_name == team["team_id"]:
                        results.append(team)
                elif search_key == "name":
                    if team_name.lower() in team["team_name"].lower():
                        results.append(team)
                else:  # search_key == "all"
                    if team_name == team["team_id"] or team_name.lower() in team["team_name"].lower():
                        results.append(team)
    
            return {"teams": results}
        except Exception as e:
            return {"error": str(e)}
  • main.py:12-23 (registration)
    The import and call to setup_mlb_tools(mcp) which registers all MLB tools, including 'get_mlb_search_teams', to the MCP server instance.
    from mlb_api import setup_mlb_tools
    
    # Suppress websockets deprecation warnings
    warnings.filterwarnings("ignore", category=DeprecationWarning, module="websockets")
    warnings.filterwarnings("ignore", category=DeprecationWarning, module="uvicorn.protocols.websockets")
    
    # Create FastMCP server instance
    mcp = FastMCP("MLB API MCP Server")
    
    # Setup all MLB and generic tools
    setup_mlb_tools(mcp)
    setup_generic_tools(mcp)
  • The input schema and documentation for the tool, defining parameters team_name (required str) and search_key (optional str, default 'name'), and return type dict.
    """
    Search for teams by name or ID.
    
    Args:
        team_name (str): Team name or ID to search for.
        search_key (str): Search key ("name", "id", or "all").
    
    Returns:
        dict: Team search results.
    """

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