get_player_stats
Retrieve a Chess.com player's statistics by username. Use this tool to access performance data including ratings, win/loss records, and game history for analysis.
Instructions
Get a player's stats from Chess.com
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/chess_mcp/server.py:98-110 (handler)The actual tool handler for 'get_player_stats'. Uses @mcp.tool decorator to register as an MCP tool, takes a username parameter, and calls the Chess.com API via make_api_request at endpoint 'player/{username}/stats'.
@mcp.tool(description="Get a player's stats from Chess.com") async def get_player_stats(username: str) -> Dict[str, Any]: """ Get a player's chess statistics from Chess.com. Args: username: The Chess.com username Returns: Player statistics data """ logger.info("Fetching player stats", username=username) return await make_api_request(f"player/{username}/stats") - src/chess_mcp/server.py:98-98 (registration)Registered via the @mcp.tool descriptor on line 98, which exposes it as a tool named 'get_player_stats' in the MCP server.
@mcp.tool(description="Get a player's stats from Chess.com") - src/chess_mcp/server.py:26-73 (helper)The make_api_request helper function that get_player_stats calls internally to make HTTP requests to the Chess.com API.
async def make_api_request( endpoint: str, params: Optional[Dict[str, Any]] = None, accept_json: bool = True ) -> Union[Dict[str, Any], str]: """ Make a request to the Chess.com API. Args: endpoint: The API endpoint to request params: Optional query parameters accept_json: Whether to accept JSON response (True) or PGN (False) Returns: JSON response as dict or text response as string Raises: httpx.HTTPError: If the request fails """ url = f"{config.base_url}/{endpoint}" headers = { "accept": "application/json" if accept_json else "application/x-chess-pgn" } logger.debug( "Making API request", endpoint=endpoint, url=url, accept_json=accept_json, has_params=params is not None ) async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, params=params or {}) response.raise_for_status() if accept_json: result = response.json() logger.debug("API request successful", endpoint=endpoint, response_type="json") return result else: result = response.text logger.debug("API request successful", endpoint=endpoint, response_type="text") return result except httpx.HTTPError as e: logger.error( - src/chess_mcp/server.py:98-110 (schema)Input schema: 'username' (str). The return type is Dict[str, Any]. This is implicitly defined by the function signature and the @mcp.tool decorator handles validation.
@mcp.tool(description="Get a player's stats from Chess.com") async def get_player_stats(username: str) -> Dict[str, Any]: """ Get a player's chess statistics from Chess.com. Args: username: The Chess.com username Returns: Player statistics data """ logger.info("Fetching player stats", username=username) return await make_api_request(f"player/{username}/stats")