get_player_rankings
Retrieve a player's hero rankings using their Steam32 account ID to analyze performance across different heroes in Dota 2 matches.
Instructions
Get player hero rankings.
Args:
account_id: Steam32 account ID of the player
Returns:
Player's hero rankings
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes |
Implementation Reference
- src/opendota_server/server.py:978-1028 (handler)The primary handler function for the 'get_player_rankings' tool. It fetches hero rankings data for a given player account ID from the OpenDota API, maps hero IDs to names, and formats the results into a readable string response. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() async def get_player_rankings(account_id: int) -> str: """Get player hero rankings. Args: account_id: Steam32 account ID of the player Returns: Player's hero rankings """ rankings_data = await make_opendota_request(f"players/{account_id}/rankings") if "error" in rankings_data: return f"Error retrieving rankings data: {rankings_data['error']}" if ( not rankings_data or not isinstance(rankings_data, list) or len(rankings_data) == 0 ): return "No ranking data found for this player." # Get hero names (just for context) heroes_data = await make_opendota_request("heroes") hero_id_to_name = {} if not isinstance(heroes_data, dict) and isinstance(heroes_data, list): for hero in heroes_data: if isinstance(hero, dict) and "id" in hero and "localized_name" in hero: hero_id = hero.get("id") hero_name = hero.get("localized_name") if hero_id is not None and hero_name is not None: hero_id_to_name[hero_id] = hero_name formatted_rankings = [] for ranking in rankings_data: hero_id = ranking.get("hero_id", 0) hero_name = hero_id_to_name.get(hero_id, f"Hero {hero_id}") score = ranking.get("score", 0) percent_rank = ranking.get("percent_rank", 0) * 100 # Convert to percentage formatted_rankings.append( f"{hero_name} (ID: {hero_id})\n" f"Score: {score:.2f}\n" f"Percentile: {percent_rank:.2f}%" ) return f"Hero Rankings for Player ID {account_id}:\n\n" + "\n\n".join( formatted_rankings )
- src/opendota_server/server.py:978-978 (registration)The @mcp.tool() decorator registers the get_player_rankings function as an MCP tool.@mcp.tool()