Skip to main content
Glama
pab1it0

Chess.com MCP Server

download_player_games_pgn

Retrieve and download Portable Game Notation (PGN) files for any Chess.com player's games from a specified month and year, enabling offline analysis or archival.

Instructions

Download PGN files for all games in a specific month from Chess.com

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYes
yearYes
monthYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main tool handler function that downloads PGN files for all games in a specific month from Chess.com's API. Decorated with @mcp.tool, it constructs the API endpoint, calls make_api_request with accept_json=False to get PGN text, and returns the result.
    @mcp.tool(description="Download PGN files for all games in a specific month from Chess.com")
    async def download_player_games_pgn(
        username: str,
        year: int,
        month: int
    ) -> str:
        """
        Download PGN files for all games in a specific month from Chess.com.
    
        Args:
            username: The Chess.com username
            year: Year (YYYY format)
            month: Month (MM format, 01-12)
    
        Returns:
            Multi-game PGN format text containing all games for the month
        """
        month_str = str(month).zfill(2)
        logger.info(
            "Downloading player games PGN",
            username=username,
            year=year,
            month=month_str
        )
        result = await make_api_request(
            f"player/{username}/games/{year}/{month_str}/pgn",
            accept_json=False
        )
        return result
  • The @mcp.tool decorator registers the function as an MCP tool with the given description.
    @mcp.tool(description="Download PGN files for all games in a specific month from Chess.com")
  • The helper function used by download_player_games_pgn to make the actual HTTP GET request to the Chess.com API. When accept_json is False (as called by the PGN tool), it sends 'application/x-chess-pgn' as the Accept header and returns the raw text response.
    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 function signature defines the schema/inputs: username (str), year (int), month (int), and returns a string (multi-game PGN text).
    async def download_player_games_pgn(
        username: str,
        year: int,
        month: int
    ) -> str:
  • An MCP resource that wraps the download_player_games_pgn tool, providing a resource-based access pattern to the same underlying PGN download functionality.
    @mcp.resource("chess://player/{username}/games/{year}/{month}/pgn")
    async def player_games_pgn_resource(username: str, year: str, month: str) -> str:
        """
        Resource that returns a player's games for a specific month in PGN format.
    
        Args:
            username: The Chess.com username
            year: Year (YYYY format)
            month: Month (MM format, 01-12)
    
        Returns:
            PGN-formatted games
        """
        try:
            logger.debug(
                "Fetching player games PGN resource",
                username=username,
                year=year,
                month=month
            )
            pgn_data = await download_player_games_pgn(
                username=username,
                year=int(year),
                month=int(month)
            )
            return pgn_data
        except Exception as e:
            logger.error(
                "Error downloading PGN data",
                username=username,
                year=year,
                month=month,
                error=str(e)
            )
            return f"Error downloading PGN data: {str(e)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits. It only states 'Download PGN files' but does not mention file size, rate limits, whether multiple files are bundled, or if the download is synchronous. The read-only nature is implied but not explicitly stated.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, which is concise, but it omits essential information. While brevity is valued, it sacrifices completeness, making it under-specified rather than well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the low complexity and existence of an output schema, the description still falls short. It does not explain the output format (PGN bundle or single file), nor does it provide context about the tool's place among siblings. The description is minimally adequate but not fully informative.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning no parameter descriptions in the schema. The tool description does not add any meaning beyond the parameter names (username, year, month). It fails to explain expected formats, ranges, or constraints (e.g., month 1-12, year range).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action 'Download PGN files' and the resource 'all games in a specific month from Chess.com'. It distinguishes from siblings like get_player_games_by_month by specifying the PGN format, but could be more explicit about how it differs from other game retrieval tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like get_player_games_by_month or get_player_game_archives. The description does not indicate prerequisites, limitations, or context for use, leaving the agent without decision-making support.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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