get_icc_rankings
Fetch official ICC cricket rankings for Test, ODI, and T20 formats. Retrieve top players and teams by category: batting, bowling, all-rounder, or teams.
Instructions
Fetches official ICC cricket rankings for various categories. Use this tool to answer questions about top players and teams in Test, ODI, and T20 formats.
For example, you can answer questions like:
"Who are the top 10 ODI batsmen?"
"Show me the test bowling rankings."
"What are the T20 team rankings?"
"icc ranking odi batsman"
Args: category (str): The ranking category. Must be one of: "batting", "bowling", "all-rounder", or "teams".
Returns: dict: A dictionary with rankings for Test, ODI, and T20 formats. Each format contains a list of players or teams with their position, name, country, and rating.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes |
Implementation Reference
- cricket_server.py:433-533 (handler)The handler function implementing the get_icc_rankings tool. It scrapes ICC rankings from Cricbuzz for categories like batting, bowling, all-rounder, or teams across Test, ODI, and T20 formats. The @mcp.tool() decorator handles automatic registration and schema generation from the docstring.@mcp.tool() def get_icc_rankings(category: str) -> dict: """ Fetches official ICC cricket rankings for various categories. Use this tool to answer questions about top players and teams in Test, ODI, and T20 formats. For example, you can answer questions like: - "Who are the top 10 ODI batsmen?" - "Show me the test bowling rankings." - "What are the T20 team rankings?" - "icc ranking odi batsman" Args: category (str): The ranking category. Must be one of: "batting", "bowling", "all-rounder", or "teams". Returns: dict: A dictionary with rankings for Test, ODI, and T20 formats. Each format contains a list of players or teams with their position, name, country, and rating. """ if category not in ["batting", "bowling", "all-rounder", "teams"]: return {"error": "Invalid category. Choose from 'batting', 'bowling', 'all-rounder', 'teams'."} # The 'all-rounder' category is spelled as 'all-rounder' in the URL url_category = category if category != "all-rounder" else "all-rounder" link = f"https://www.cricbuzz.com/cricket-stats/icc-rankings/men/{url_category}" try: response = requests.get(link, headers=HEADERS, timeout=10) response.raise_for_status() source = response.text page = BeautifulSoup(source, "lxml") rankings = {} # Define formats to scrape formats = ["test", "odi", "t20"] # Map category to the format used in ng-show directive category_map = { "batting": "batsmen", "bowling": "bowlers", "all-rounder": "allrounders", "teams": "teams" } angular_category = category_map.get(category) for f in formats: format_key = f"{angular_category}-{f}s" # e.g., batsmen-tests if f == 't20': format_key = f"{angular_category}-t20s" # Find the container for the specific format format_container = page.find("div", {"ng-show": f"'{format_key}' == act_rank_format"}) if not format_container: continue ranking_list = [] if category == "teams": # Find all team rows rows = format_container.find_all("div", class_="cb-col cb-col-100 cb-font-14 cb-brdr-thin-btm text-center") for row in rows: position = row.find("div", class_="cb-col cb-col-20 cb-lst-itm-sm").text.strip() team_name = row.find("div", class_="cb-col cb-col-50 cb-lst-itm-sm text-left").text.strip() rating = row.find_all("div", class_="cb-col cb-col-14 cb-lst-itm-sm")[0].text.strip() points = row.find_all("div", class_="cb-col cb-col-14 cb-lst-itm-sm")[1].text.strip() ranking_list.append({ "position": position, "team": team_name, "rating": rating, "points": points }) else: # Find all player rows rows = format_container.find_all("div", class_="cb-col cb-col-100 cb-font-14 cb-lst-itm text-center") for row in rows: position = row.find("div", class_="cb-col cb-col-16 cb-rank-tbl cb-font-16").text.strip() rating = row.find("div", class_="cb-col cb-col-17 cb-rank-tbl pull-right").text.strip() player_info = row.find("div", class_="cb-col cb-col-67 cb-rank-plyr") player_name = player_info.find("a").text.strip() country = player_info.find("div", class_="cb-font-12 text-gray").text.strip() ranking_list.append({ "position": position, "player": player_name, "country": country, "rating": rating }) rankings[f] = ranking_list return rankings except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"} except Exception as e: return {"error": f"An error occurred: {str(e)}"}