get_match_details
Retrieve comprehensive cricket match details, including title, result, and scorecard data for each innings, by providing a Cricbuzz URL via the cricket-mcp-server.
Instructions
Get detailed scorecard for a specific cricket match from a Cricbuzz URL.
Args: match_url (str): The URL of the match on Cricbuzz (can be obtained from get_live_matches).
Returns: dict: A dictionary containing match details including: - Match title and result. - A scorecard for each innings with batting and bowling stats.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| match_url | Yes |
Implementation Reference
- cricket_server.py:225-327 (handler)The handler function for the 'get_match_details' tool. It scrapes the Cricbuzz match page for title, result, and detailed scorecard including batting and bowling stats for each innings. Registered via @mcp.tool() decorator.@mcp.tool() def get_match_details(match_url: str) -> dict: """ Get detailed scorecard for a specific cricket match from a Cricbuzz URL. Args: match_url (str): The URL of the match on Cricbuzz (can be obtained from get_live_matches). Returns: dict: A dictionary containing match details including: - Match title and result. - A scorecard for each innings with batting and bowling stats. """ if not match_url or "cricbuzz.com" not in match_url: return {"error": "A valid Cricbuzz match URL is required."} try: response = requests.get(match_url, headers=HEADERS, timeout=10) response.raise_for_status() source = response.text page = BeautifulSoup(source, "lxml") 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 or parse match page: {str(e)}"} match_data = {} # Extract title and result title_tag = page.find("h1", class_="cb-nav-hdr") if title_tag: match_data["title"] = title_tag.text.strip() result_tag = page.find("div", class_="cb-nav-text") if result_tag: match_data["result"] = result_tag.text.strip() # Scorecard scorecard = {} innings_divs = page.find_all("div", id=re.compile(r"^inning_\d+$")) for i, inning_div in enumerate(innings_divs): inning_key = f"inning_{i+1}" inning_data = {"batting": [], "bowling": []} inning_title_tag = inning_div.find("div", class_="cb-scrd-hdr-rw") if inning_title_tag: inning_data["title"] = inning_title_tag.text.strip() # Batting stats batsmen = inning_div.find_all("div", class_=lambda x: x and x.startswith('cb-col cb-col-w-')) for batsman in batsmen: cols = batsman.find_all("div", class_=lambda x: x and x.startswith('cb-col cb-col-w-')) if len(cols) > 1 and "batsman" in cols[0].text.lower(): # Header row continue if len(cols) >= 7: player_name = cols[0].text.strip() if "Extras" in player_name or not player_name: continue inning_data["batting"].append({ "player": player_name, "dismissal": cols[1].text.strip(), "R": cols[2].text.strip(), "B": cols[3].text.strip(), "4s": cols[4].text.strip(), "6s": cols[5].text.strip(), "SR": cols[6].text.strip(), }) # Bowling stats bowlers_section = inning_div.find("div", class_="cb-col-bowlers") if bowlers_section: bowlers = bowlers_section.find_all("div", class_="cb-scrd-itms") for bowler in bowlers: cols = bowler.find_all("div", class_=lambda x: x and x.startswith('cb-col cb-col-w-')) if len(cols) > 1 and "bowler" in cols[0].text.lower(): # Header row continue if len(cols) >= 6: player_name = cols[0].text.strip() if not player_name: continue inning_data["bowling"].append({ "player": player_name, "O": cols[1].text.strip(), "M": cols[2].text.strip(), "R": cols[3].text.strip(), "W": cols[4].text.strip(), "Econ": cols[5].text.strip(), }) scorecard[inning_key] = inning_data match_data["scorecard"] = scorecard return match_data
- cricket_server.py:225-225 (registration)The @mcp.tool() decorator registers the get_match_details function as an MCP tool in FastMCP.@mcp.tool()
- cricket_server.py:226-237 (schema)Type hints and docstring define the input schema (match_url: str) and output format (dict with title, result, scorecard).def get_match_details(match_url: str) -> dict: """ Get detailed scorecard for a specific cricket match from a Cricbuzz URL. Args: match_url (str): The URL of the match on Cricbuzz (can be obtained from get_live_matches). Returns: dict: A dictionary containing match details including: - Match title and result. - A scorecard for each innings with batting and bowling stats. """