get_player_current_games
Retrieve a chess player's current ongoing games on Chess.com by providing their username.
Instructions
Get a player's ongoing games on 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:128-140 (handler)The main handler/tool function for 'get_player_current_games'. It is decorated with @mcp.tool, takes a username parameter, logs the request, and calls make_api_request with the endpoint 'player/{username}/games' to fetch a player's current/ongoing games from Chess.com API.
@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:128-128 (registration)Registration of 'get_player_current_games' as an MCP tool via the @mcp.tool decorator with description 'Get a player's ongoing games on Chess.com'.
@mcp.tool(description="Get a player's ongoing games on Chess.com") - src/chess_mcp/server.py:312-330 (helper)Resource handler that wraps get_player_current_games as a resource at 'chess://player/{username}/games/current', formatting the result as JSON string.
@mcp.resource("chess://player/{username}/games/current") async def player_current_games_resource(username: str) -> str: """ Resource that returns a player's current games. Args: username: The Chess.com username Returns: JSON-formatted current games """ try: import json logger.debug("Fetching player current games resource", username=username) games = await get_player_current_games(username=username) return json.dumps(games, indent=2) except Exception as e: logger.error("Error retrieving current games", username=username, error=str(e)) return f"Error retrieving current games: {str(e)}" - tests/test_server.py:73-79 (helper)Unit test for get_player_current_games, testing that the function correctly calls make_api_request and returns the expected game data.
@pytest.mark.asyncio async def test_get_player_current_games(): mock_data = {"games": [{"url": "game_url"}]} with patch("chess_mcp.server.make_api_request", new=AsyncMock(return_value=mock_data)): result = await get_player_current_games("testuser") assert result == mock_data