# MCP Give Claude Code, Claude Desktop, Cursor or any MCP client the ChessDrive APIs as tools with `chessdrive mcp`, a local MCP server in the CLI, or with the hosted Connector at `https://api.chessdrive.io/mcp`. Set it up in one command or one config entry. `chessdrive mcp` is an [MCP](https://modelcontextprotocol.io) server built into the [CLI](/docs/cli). Your AI tool starts it and talks to it over stdin and stdout, so nothing listens on a port. Each tool calls the API with your key and returns the API's JSON, as in the [API reference](/docs/api). ## 1. Install the CLI and log in Install `chessdrive` and run `chessdrive login` as the [CLI page](/docs/cli) shows. The server uses the key `login` saved, or `CHESSDRIVE_API_KEY` when your AI tool passes it, and reads it on each call, so logging in again takes effect without a restart. ```text Terminal chessdrive login ``` ## 2. Add it to Claude Code `--scope user` makes the tools available in every project; leave it out for the current project only. Run `/mcp` in Claude Code to check that `chessdrive` is connected. ```text Claude Code claude mcp add --scope user chessdrive -- chessdrive mcp ``` ## 3. Or add it to Claude Desktop Open Settings, then Developer, then Edit Config, and add the server to `claude_desktop_config.json`. Claude Desktop doesn't read your shell's `PATH`, so give the CLI's full path, which `command -v chessdrive` prints. Restart Claude Desktop to load it. ```json claude_desktop_config.json { "mcpServers": { "chessdrive": { "command": "/Users/you/.local/bin/chessdrive", "args": ["mcp"] } } } ``` ## 4. Or add it to Cursor Add the same entry to `~/.cursor/mcp.json` for every project, or to `.cursor/mcp.json` in one project. Cursor lists the tools in its MCP settings. ```json mcp.json { "mcpServers": { "chessdrive": { "command": "/Users/you/.local/bin/chessdrive", "args": ["mcp"] } } } ``` Any other MCP client that starts a local server takes the same command and argument: `chessdrive mcp`. ## Tools Each tool takes the fields of its API's request, with the same names, and returns the response body, but for `embed`, below, and `get_game` and `show_board`, which are no API. Generate and Engine return the whole result at once: a tool doesn't stream. | Tool | Does | Cost | |---|---|---| | `generate` | Asks Knight or Queen, optionally about a position, as [Generate](/docs/generate) | Billed | | `embed` | Turns positions and texts into vectors, as [Embed](/docs/embed), written to a file on your machine | Billed | | `search` | Gets the moves played from a position, or a player's games, as [Search](/docs/search) | Billed | | `engine` | Analyses a position with Stockfish, up to 100 positions in one call, or a whole game, as [Engine](/docs/engine) | Billed | | `get_game` | Gets a finished game from a Lichess or chess.com link, as a PGN. A chess.com link also takes `username`, either player's. On the Connector only | Free | | `show_board` | Shows a position or a game on a board in your chat, to step through or play, in an app that can show one. A board told to play you bills its replies as `engine` calls. On the Connector only | Free | | `list_models` | Lists the [Models](/docs/models), with no key needed | Free | | `usage` | Your requests and cost per day, by API, Model or key, between `from` and `to` | Free | | `balance` | Your Plan, Balance, Monthly credit, Trial credits, this month's spend and Spend limit | Free | | `study_key` | Makes a Study key for one Study page, so the page can call Engine and Generate itself: only those two, up to $1 a day, for 7 days. See [Authentication](/docs/authentication) | Free | Try asking your AI tool: "Here's the PGN of my last game. Have Stockfish check every move, then explain my worst one." ### Vectors go to a file An agent never sees a vector: it writes code that uses them. So `embed` takes `out`, the path of a `.npy` file, and writes the same two files as [`chessdrive embed --out`](/docs/cli): the vectors, and a `.jsonl` saying what each row is. It returns their paths and a summary, never the vectors. It takes `dimensions` for shorter vectors, but no `precision` or `encoding_format`: the file is always float32. Besides `model` and `out` it takes `input`, the API's items, as many as you like, and `pgn_file`, the path of a PGN file on your machine, for every position of every game in it. It makes the calls, up to 256 items each, and waits when rate limited. ```text embed result { "items": 2000, "embedded": 2000, "dimensions": 512, "model": "chessdrive-embed-1", "vectors": "/Users/you/vectors.npy", "rows": "/Users/you/vectors.jsonl", "cost_usd": "0.080000" } ``` A long run can pass the time your AI tool gives a tool call. Nothing is lost: the same call carries on from the rows written, and `embedded` says how many that call added. Larger runs suit `chessdrive embed --out` in a terminal. A failed call's tool error adds `resume`, saying how many rows are in the file. ## Errors A failed call comes back to the agent as a tool error with the API's `error` object, the HTTP `status` and the `request_id`, so it can tell a refusal for money from a rate limit. A 429 adds `retry_after_seconds`. The codes are those in [Errors](/docs/errors). ```json Tool error { "status": 402, "error": { "type": "billing_error", "code": "insufficient_balance", "message": "Your Balance is used up. Top up in the Dashboard to keep calling." }, "request_id": "req_01J9Z6Q8F3" } ``` A `billing_error` (402) is settled in the [Dashboard](/dashboard/billing): top up, or raise a Spend or Key limit. A `rate_limit_error` (429) passes after the wait; [Rate limits](/docs/rate-limits) has the limits. ## The hosted Connector The Connector is the same tools, hosted at `https://api.chessdrive.io/mcp`, with nothing to install and no key to copy: a Streamable HTTP MCP server you sign in to through your browser. It serves every tool above but `embed`, which writes to your machine. Sign in once. In a coding agent, the Connector uses the key `chessdrive login` saved: the agent runs `chessdrive key` each time it connects, so the key is never copied into its settings and logging in again takes effect at the next connect. In Claude's chat app, or without the CLI, add the address and sign in when the app asks. Either way you pick the Account it bills and a daily limit, $25 by default. The CLI's key shows in [API keys](/dashboard/keys) under your machine's name, a browser sign-in as a Connection, where you can change the limit or revoke it, and its calls show in your Request log as any API call does. ## Claude Code The [Plugin](/cookbook/add-to-your-ai) brings the Connector set up this way. To add the Connector alone, for every project: ```text Claude Code claude mcp add-json --scope user chessdrive '{"type":"http","url":"https://api.chessdrive.io/mcp","headersHelper":"chessdrive key --headers"}' ``` Without the CLI, `claude mcp add --scope user --transport http chessdrive https://api.chessdrive.io/mcp`, then run `/mcp`, choose `chessdrive` and sign in. ## Cursor In `~/.cursor/mcp.json`. Cursor runs no command for a header, so it reads the key from a variable your shell sets: add `export CHESSDRIVE_CONNECTOR_KEY="$(chessdrive key 2>/dev/null)"` to your shell's startup file, such as `~/.zshrc`, and restart Cursor. Without the headers, sign in when Cursor asks. ```json mcp.json { "mcpServers": { "chessdrive": { "url": "https://api.chessdrive.io/mcp", "headers": { "Authorization": "Bearer ${env:CHESSDRIVE_CONNECTOR_KEY}" } } } } ``` ## Codex In `~/.codex/config.toml`, with the full path `command -v chessdrive` prints, as the Codex app may not have your shell's `PATH`. Without the helper, sign in when Codex asks. ```toml config.toml [mcp_servers.chessdrive] url = "https://api.chessdrive.io/mcp" http_headers_helper = "/full/path/to/chessdrive key --headers" ``` Claude's desktop app keeps the tools and the board it read when you connected, while claude.ai in a browser reads them again for each new chat. If the app shows an older board, or misses a tool, disconnect the Connector and connect it again, then open a new chat. ### With an API key Where no one can sign in through a browser, such as on a server, the Connector also takes an API key as a bearer token. Calls bill the key's Account. ## Claude Code with a key The key is stored in Claude Code's config. Run `/mcp` to check the tools are listed. ```text Claude Code claude mcp add --scope user --transport http chessdrive https://api.chessdrive.io/mcp --header "Authorization: Bearer $CHESSDRIVE_API_KEY" ``` ## Cursor with a key In `~/.cursor/mcp.json`, Cursor reads the key from your environment when it starts. ```json mcp.json { "mcpServers": { "chessdrive": { "url": "https://api.chessdrive.io/mcp", "headers": { "Authorization": "Bearer ${env:CHESSDRIVE_API_KEY}" } } } } ``` ## Codex with a key In `~/.codex/config.toml`, Codex reads the key from the variable it names. ```toml config.toml [mcp_servers.chessdrive] url = "https://api.chessdrive.io/mcp" bearer_token_env_var = "CHESSDRIVE_API_KEY" ``` Signed out, or with a revoked or disabled key, the Connector answers `401` before any tool runs. An empty Balance comes back as a tool error that links to [Pricing](/pricing). The Connector's `engine` answer holds what an agent reads and no more, so it takes a fraction of the context the API's does: moves in SAN alone, scores as `cp` or `mate`, and no `uci`, `wdl`, `nodes`, `seldepth`, `time_ms`, `usage`, `id`, `network` or `version`. `stop_reason` shows only when the time cap stopped the search. The API and `chessdrive mcp` return the whole answer. The Connector also adds one field to an `engine` answer, so an agent can show you a board in any app: `board_url`, a link to [the Board](/board) with the position, its evaluation and the engine's Lines as arrows (on a list, on each position analysed; on a whole game, on each inaccuracy, mistake and blunder, with Engine's best move). The position or game is in the link's fragment, after `#`, so opening it sends nothing to ChessDrive. ## Staging and other APIs The server calls the API the CLI does: the one `chessdrive login` checked the key against, or `CHESSDRIVE_BASE_URL`. To pass a key and an API to the server alone, set them in your AI tool's config, as `claude mcp add` does with `-e`: ```text Claude Code claude mcp add chessdrive -e CHESSDRIVE_API_KEY=ck_… -e CHESSDRIVE_BASE_URL=https://api.chessdrive.io -- chessdrive mcp ``` The key is then stored in that config file, so prefer `chessdrive login` on a shared machine.