get_player_current_games
Retrieve all ongoing chess games for a specific player on Chess.com using their username. Ideal for tracking active matches and analyzing player activity.
Instructions
Get a player's ongoing games on Chess.com
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Input Schema (JSON Schema)
{
"properties": {
"username": {
"title": "Username",
"type": "string"
}
},
"required": [
"username"
],
"title": "get_player_current_gamesArguments",
"type": "object"
}
Implementation Reference
- src/chess_mcp/server.py:128-140 (handler)The core handler function for the 'get_player_current_games' tool. It is decorated with @mcp.tool for automatic registration and schema generation, and fetches the player's current games from the Chess.com API endpoint 'player/{username}/games'.@mcp.tool(description="Get a player's ongoing games on Chess.com") async def get_player_current_games(username: str) -> Dict[str, Any]: """ Get a list of a player's current games on Chess.com. Args: username: The Chess.com username Returns: Current games data """ logger.info("Fetching player current games", username=username) return await make_api_request(f"player/{username}/games")
- src/chess_mcp/server.py:26-81 (helper)Shared helper function that performs HTTP requests to the Chess.com API, handling JSON/PGN responses and logging. This is called by the tool handler to fetch the games data.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( "API request failed", endpoint=endpoint, url=url, error=str(e), error_type=type(e).__name__ ) raise
- src/chess_mcp/server.py:128-140 (registration)The @mcp.tool decorator registers this function as an MCP tool, auto-generating input schema from type hints and docstring.@mcp.tool(description="Get a player's ongoing games on Chess.com") async def get_player_current_games(username: str) -> Dict[str, Any]: """ Get a list of a player's current games on Chess.com. Args: username: The Chess.com username Returns: Current games data """ logger.info("Fetching player current games", username=username) return await make_api_request(f"player/{username}/games")