Skip to main content
Glama
pab1it0

Chess.com MCP Server

get_player_game_archives

Retrieve monthly game archives for a Chess.com player to access historical match data for analysis.

Instructions

Get a list of available monthly game archives for a player on Chess.com

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYes

Implementation Reference

  • The main handler function for the 'get_player_game_archives' tool, decorated with @mcp.tool for automatic registration. It fetches the list of available monthly game archives for a Chess.com player by making an API request to /player/{username}/games/archives.
    @mcp.tool(description="Get a list of available monthly game archives for a player on Chess.com")
    async def get_player_game_archives(username: str) -> Dict[str, Any]:
        """
        Get a list of available monthly game archives for a player on Chess.com.
    
        Args:
            username: The Chess.com username
    
        Returns:
            List of available game archives
        """
        logger.info("Fetching player game archives", username=username)
        return await make_api_request(f"player/{username}/games/archives")
  • Shared helper function 'make_api_request' that performs HTTP GET requests to the Chess.com API, handling JSON or PGN responses, logging, and error raising. Directly used by the get_player_game_archives handler.
    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
  • The @mcp.tool decorator line that registers the 'get_player_game_archives' function as an MCP tool with its description.
    @mcp.tool(description="Get a list of available monthly game archives for a player on Chess.com")

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/pab1it0/chess-mcp'

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