get_active_player_name
Retrieve the current player's name from the League of Legends client using the Live Client Data API.
Instructions
Returns the player name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- main.py:90-97 (handler)The main handler function for the 'get_active_player_name' tool. It asynchronously fetches the active player's name from the League of Legends client API endpoint '/liveclientdata/activeplayername' and returns it as a string.async def get_active_player_name() -> str: """ Returns the player name. """ async with get_lol_client() as client: response = await client.get("/liveclientdata/activeplayername") return response.text
- main.py:88-89 (registration)The @mcp.tool() decorator registers the get_active_player_name function as an MCP tool. The @with_timeout decorator adds timeout and error handling.@mcp.tool() @with_timeout
- main.py:18-47 (helper)The 'with_timeout' decorator used by the tool to handle various HTTP errors and timeouts when communicating with the LoL client.def with_timeout(func: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]: """ Decorator to handle timeout exceptions for async functions. """ @functools.wraps(func) async def wrapper(*args: Any, **kwargs: Any) -> T: try: return await func(*args, **kwargs) except httpx.TimeoutException: return { "error": "Game has not started or connection failed.", "code": "TIMEOUT" } except httpx.ConnectError: return { "error": "Cannot connect to the game client. Please check if the game is running.", "code": "CONNECTION_ERROR" } except httpx.HTTPStatusError as e: return { "error": f"Server error: HTTP {e.response.status_code}", "code": "HTTP_ERROR", "status": e.response.status_code } except Exception as e: return { "error": f"An error occurred: {str(e)}", "code": "UNKNOWN_ERROR" } return wrapper
- main.py:50-58 (helper)Helper function to create an httpx.AsyncClient configured for the LoL client API, used inside the tool handler.def get_lol_client(): """ Create an HTTP client for the League of Legends client. """ return httpx.AsyncClient( base_url=LOL_CLIENT_HOST, verify="./certs/riotgames.pem", timeout=DEFAULT_TIMEOUT )