get_match_data
Retrieve detailed Dota 2 match information including player stats, scores, and game data using the match ID to analyze gameplay performance and outcomes.
Instructions
Get detailed data for a specific match.
Args:
match_id: ID of the match to retrieve
Returns:
Detailed match information including players, scores, and stats
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| match_id | Yes |
Implementation Reference
- src/opendota_server/server.py:496-511 (handler)The primary handler function implementing the logic for the 'get_match_data' MCP tool. It is registered as a tool using the @mcp.tool() decorator, takes a match_id parameter, fetches data from the OpenDota API, handles errors, and formats the output using a helper function.@mcp.tool() async def get_match_data(match_id: int) -> str: """Get detailed data for a specific match. Args: match_id: ID of the match to retrieve Returns: Detailed match information including players, scores, and stats """ match_data = await make_opendota_request(f"matches/{match_id}") if "error" in match_data: return f"Error retrieving match data: {match_data['error']}" return format_match_data(match_data)
- Helper utility function that takes raw match data dictionary and formats it into a detailed, human-readable string representation, including match info, teams, scores, winner, and per-player stats.def format_match_data(match: Dict[str, Any]) -> str: """Format match data into a readable string.""" if not match or "match_id" not in match: return "Match data not found." # Basic match info match_id = match.get("match_id", "Unknown") duration = match.get("duration", 0) duration_formatted = format_duration(duration) start_time = format_timestamp(match.get("start_time", 0)) game_mode = match.get("game_mode", "Unknown") radiant_win = match.get("radiant_win", False) winner = "Radiant" if radiant_win else "Dire" # Scores radiant_score = match.get("radiant_score", 0) dire_score = match.get("dire_score", 0) # Teams radiant_team_data = match.get("radiant_team", {}) dire_team_data = match.get("dire_team", {}) # Handle the case where these might be strings instead of dicts if isinstance(radiant_team_data, dict): radiant_team = radiant_team_data.get("name", "Radiant") else: radiant_team = "Radiant" if isinstance(dire_team_data, dict): dire_team = dire_team_data.get("name", "Dire") else: dire_team = "Dire" # Format players data player_data = [] players = match.get("players", []) for player in players: account_id = player.get("account_id", "Anonymous") hero_id = player.get("hero_id", "Unknown") hero_name = player.get("hero_name", "Unknown Hero") kills = player.get("kills", 0) deaths = player.get("deaths", 0) assists = player.get("assists", 0) gpm = player.get("gold_per_min", 0) xpm = player.get("xp_per_min", 0) team = "Radiant" if player.get("player_slot", 0) < 128 else "Dire" player_data.append( f"Player ID: {account_id}\n" f"- Team: {team}\n" f"- Hero: {hero_name} (ID: {hero_id})\n" f"- K/D/A: {kills}/{deaths}/{assists}\n" f"- GPM/XPM: {gpm}/{xpm}" ) joined_player_data = "\n\n".join(player_data) formatted_output = ( f"Match ID: {match_id}\n" f"Date: {start_time}\n" f"Duration: {duration_formatted}\n" f"Game Mode: {game_mode}\n" f"Teams: {radiant_team} vs {dire_team}\n" f"Score: {radiant_score} - {dire_score}\n" f"Winner: {winner}\n\n" f"Player Details:\n" f"{'-' * 40}\n" f"{joined_player_data}" ) return formatted_output