Skip to main content
Glama

get_match_heroes

Retrieve hero selections for any Dota 2 match by entering the match ID to analyze team compositions and player choices.

Instructions

Get heroes played in a specific match.

Args:
    match_id: ID of the match to retrieve

Returns:
    List of heroes played by each player in the match

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
match_idYes

Implementation Reference

  • The primary handler function for the 'get_match_heroes' tool. It is registered via the @mcp.tool() decorator. Fetches match data from the OpenDota API, maps hero IDs to names, processes player data to list heroes for Radiant and Dire teams with player names and K/D/A stats, and formats the output string.
    @mcp.tool()
    async def get_match_heroes(match_id: int) -> str:
        """Get heroes played in a specific match.
    
        Args:
            match_id: ID of the match to retrieve
    
        Returns:
            List of heroes played by each player in the match
        """
        match_data = await make_opendota_request(f"matches/{match_id}")
    
        if "error" in match_data:
            return f"Error retrieving match data: {match_data['error']}"
    
        if not match_data or "players" not in match_data:
            return f"No data found for match ID {match_id}."
    
        # Get hero names
        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
    
        # Process players
        radiant_players = []
        dire_players = []
    
        for player in match_data["players"]:
            hero_id = player.get("hero_id", 0)
            hero_name = hero_id_to_name.get(hero_id, f"Hero {hero_id}")
            account_id = player.get("account_id", "Anonymous")
            name = player.get("personaname", "Unknown")
            kills = player.get("kills", 0)
            deaths = player.get("deaths", 0)
            assists = player.get("assists", 0)
    
            player_info = (
                f"{name} (ID: {account_id}) - {hero_name}: {kills}/{deaths}/{assists}"
            )
    
            if player.get("player_slot", 0) < 128:
                radiant_players.append(player_info)
            else:
                dire_players.append(player_info)
    
        # Match result
        radiant_win = match_data.get("radiant_win", False)
        result = "Radiant Victory" if radiant_win else "Dire Victory"
    
        return (
            f"Heroes in Match {match_id} ({result}):\n\n"
            f"Radiant:\n" + "\n".join(f"- {p}" for p in radiant_players) + "\n\n"
            "Dire:\n" + "\n".join(f"- {p}" for p in dire_players)
        )

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/asusevski/opendota-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server