Skip to main content
Glama
tarun7r

cricket-mcp-server

get_player_stats

Retrieve detailed cricket player statistics, including batting and bowling data, from Cricbuzz. Specify a player name and optionally filter by match format (Test, ODI, T20). Returns ICC rankings, performance metrics, and basic player info.

Instructions

Get comprehensive cricket player statistics including batting and bowling data from Cricbuzz.

Args: player_name (str): The name of the cricket player. match_format (str, optional): The match format to get stats for. Can be "Test", "ODI", or "T20". If not provided, all stats are returned.

Returns: dict: A dictionary containing complete player statistics including: - Basic info (name, country, role, image) - ICC rankings for batting and bowling - Detailed batting stats (matches, runs, average, strike rate, centuries, fifties) - Detailed bowling stats (balls, runs, wickets, best figures, economy, five-wicket hauls) If match_format is specified, returns stats for that format only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
match_formatNo
player_nameYes

Implementation Reference

  • Handler function decorated with @mcp.tool() for registration. Scrapes Cricbuzz player profile, extracts stats using BeautifulSoup, supports optional match_format filter, returns detailed player data.
    @mcp.tool()
    def get_player_stats(player_name: str, match_format: str = None) -> dict:
        """
        Get comprehensive cricket player statistics including batting and bowling data from Cricbuzz.
        
        Args:
            player_name (str): The name of the cricket player.
            match_format (str, optional): The match format to get stats for. Can be "Test", "ODI", or "T20". 
                                          If not provided, all stats are returned.
        
        Returns:
            dict: A dictionary containing complete player statistics including:
                  - Basic info (name, country, role, image)
                  - ICC rankings for batting and bowling
                  - Detailed batting stats (matches, runs, average, strike rate, centuries, fifties)
                  - Detailed bowling stats (balls, runs, wickets, best figures, economy, five-wicket hauls)
                  If match_format is specified, returns stats for that format only.
        """
        query = f"{player_name} cricbuzz"
        profile_link = None
        try:
            results = search(query, num_results=5)
            for link in results:
                if "cricbuzz.com/profiles/" in link:
                    profile_link = link
                    print(f"Found profile: {profile_link}")
                    break
                    
            if not profile_link:
                return {"error": "No player profile found"}
        except Exception as e:
            return {"error": f"Search failed: {str(e)}"}
        
        # Get player profile page
        try:
            response = requests.get(profile_link, headers=HEADERS, timeout=10)
            response.raise_for_status()
            c = response.text
        except requests.exceptions.ConnectionError as e:
            return {"error": f"Connection error: {str(e)}"}
        except requests.exceptions.Timeout as e:
            return {"error": f"Request timeout: {str(e)}"}
        except requests.exceptions.HTTPError as e:
            return {"error": f"HTTP error: {str(e)}"}
        except Exception as e:
            return {"error": f"Failed to fetch player profile: {str(e)}"}
        
        cric = BeautifulSoup(c, "lxml")
        profile = cric.find("div", id="playerProfile")
        pc = profile.find("div", class_="cb-col cb-col-100 cb-bg-white")
        
        # Name, country and image
        name = pc.find("h1", class_="cb-font-40").text
        country = pc.find("h3", class_="cb-font-18 text-gray").text
        image_url = None
        images = pc.findAll('img')
        for image in images:
            image_url = image['src']
            break  # Just get the first image
    
        # Personal information and rankings
        personal = cric.find_all("div", class_="cb-col cb-col-60 cb-lst-itm-sm")
        role = personal[2].text.strip()
        
        icc = cric.find_all("div", class_="cb-col cb-col-25 cb-plyr-rank text-right")
        # Batting rankings
        tb = icc[0].text.strip()   # Test batting
        ob = icc[1].text.strip()   # ODI batting
        twb = icc[2].text.strip()  # T20 batting
        
        # Bowling rankings
        tbw = icc[3].text.strip()  # Test bowling
        obw = icc[4].text.strip()  # ODI bowling
        twbw = icc[5].text.strip() # T20 bowling
    
        # Summary of the stats
        summary = cric.find_all("div", class_="cb-plyr-tbl")
        batting = summary[0]
        bowling = summary[1]
    
        # Batting statistics
        bat_rows = batting.find("tbody").find_all("tr")
        batting_stats = {}
        for row in bat_rows:
            cols = row.find_all("td")
            format_name = cols[0].text.strip().lower()  # e.g., "Test", "ODI", "T20"
            batting_stats[format_name] = {
                "matches": cols[1].text.strip(),
                "runs": cols[3].text.strip(),
                "highest_score": cols[5].text.strip(),
                "average": cols[6].text.strip(),
                "strike_rate": cols[7].text.strip(),
                "hundreds": cols[12].text.strip(),
                "fifties": cols[11].text.strip(),
            }
    
        # Bowling statistics
        bowl_rows = bowling.find("tbody").find_all("tr")
        bowling_stats = {}
        for row in bowl_rows:
            cols = row.find_all("td")
            format_name = cols[0].text.strip().lower()  # e.g., "Test", "ODI", "T20"
            bowling_stats[format_name] = {
                "balls": cols[3].text.strip(),
                "runs": cols[4].text.strip(),
                "wickets": cols[5].text.strip(),
                "best_bowling_innings": cols[9].text.strip(),
                "economy": cols[7].text.strip(),
                "five_wickets": cols[11].text.strip(),
            }
    
        # Create player stats dictionary
        player_data = {
            "name": name,
            "country": country,
            "image": image_url,
            "role": role,
            "rankings": {
                "batting": {
                    "test": tb,
                    "odi": ob,
                    "t20": twb
                },
                "bowling": {
                    "test": tbw,
                    "odi": obw,
                    "t20": twbw
                }
            },
            "batting_stats": batting_stats,
            "bowling_stats": bowling_stats
        }
    
        if match_format:
            match_format = match_format.lower()
            if match_format in batting_stats:
                return {
                    "name": name,
                    "country": country,
                    "role": role,
                    "batting_stats": batting_stats[match_format],
                    "bowling_stats": bowling_stats.get(match_format, {})
                }
            else:
                return {"error": f"No {match_format} stats found for {player_name}"}
    
        return player_data
  • Type hints and comprehensive docstring defining input schema (player_name required str, optional match_format) and output dict structure with player info, rankings, batting/bowling stats.
    def get_player_stats(player_name: str, match_format: str = None) -> dict:
        """
        Get comprehensive cricket player statistics including batting and bowling data from Cricbuzz.
        
        Args:
            player_name (str): The name of the cricket player.
            match_format (str, optional): The match format to get stats for. Can be "Test", "ODI", or "T20". 
                                          If not provided, all stats are returned.
        
        Returns:
            dict: A dictionary containing complete player statistics including:
                  - Basic info (name, country, role, image)
                  - ICC rankings for batting and bowling
                  - Detailed batting stats (matches, runs, average, strike rate, centuries, fifties)
                  - Detailed bowling stats (balls, runs, wickets, best figures, economy, five-wicket hauls)
                  If match_format is specified, returns stats for that format only.
        """
  • The @mcp.tool() decorator registers the function as an MCP tool.
    @mcp.tool()
Install Server

Other Tools

Related 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/tarun7r/cricket-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server