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()
Behavior4/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. It discloses key behavioral traits: it fetches data from Cricbuzz, returns comprehensive stats in a dictionary format, and explains how the optional match_format parameter affects output (returns all stats if not provided, format-specific if specified). It does not mention rate limits, authentication needs, or error handling, but covers core functionality adequately.

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, Args section, and Returns section. It is appropriately sized and front-loaded, with every sentence adding value. It could be slightly more concise by integrating the optional parameter effect into the Args section, but overall it is efficient.

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 no annotations, 0% schema coverage, and no output schema, the description provides good completeness. It covers purpose, parameters, return format, and data source. It lacks details on error cases, rate limits, or authentication, but for a read-only data-fetching tool, it is sufficiently complete to guide an agent.

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?

Schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the schema: it explains that player_name is required and match_format is optional, specifies valid values for match_format ('Test', 'ODI', 'T20'), and describes the effect of match_format on output. This fully documents both parameters with clear semantics.

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 tool's purpose: 'Get comprehensive cricket player statistics including batting and bowling data from Cricbuzz.' It specifies the verb ('Get'), resource ('cricket player statistics'), and scope ('comprehensive...including batting and bowling data'), distinguishing it from sibling tools like get_icc_rankings or get_match_details.

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

Usage Guidelines3/5

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

The description implies usage through the 'Args' and 'Returns' sections, suggesting when to use it (for player stats) and how parameters affect results (match_format optional). However, it lacks explicit guidance on when to use this tool versus alternatives like get_icc_rankings or get_match_details, and does not mention any prerequisites or exclusions.

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

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