lichess-stockfish-mcp
by amankrsingh
README.md
# lichess-stockfish-mcp
An [MCP](https://modelcontextprotocol.io) server that gives Claude (or any MCP client) a local **Stockfish** engine and the **Lichess API**. Use it for game reviews, coaching, opening research and endgame checks, and to give something back to the Lichess community.
## Tools
| Group | Tool | Purpose |
|---|---|---|
| Engine | `analyze_position` | Top N Stockfish lines for a FEN |
| | `legal_moves` | Legal moves in SAN, so the model never suggests an illegal move |
| | `review_pgn` | Full game review: Lichess-style accuracy, ACPL, inaccuracies/mistakes/blunders with the best move, annotated PGN |
| Lichess | `lichess_user`, `lichess_recent_games`, `lichess_game_pgn` | Profiles and games |
| | `review_lichess_game` | Review any Lichess game by id or URL |
| | `review_player_recent_games` | Coach report over the last N games: where errors happen (opening/middlegame/endgame), results per opening, worst moments |
| | `lichess_cloud_eval` | Lichess's cached deep evaluations |
| | `opening_explorer` | What Lichess players or masters play from a position |
| | `endgame_tablebase` | Perfect play for 7 or fewer pieces |
| | `lichess_puzzle` | Daily puzzle or a puzzle by id |
| | `lichess_account` | Check which account a token belongs to |
| Contribute | `import_game_to_lichess` | Publish over-the-board or club games publicly on Lichess |
| | `publish_review_to_study` | Push an engine-annotated review into a Lichess Study chapter |
The two "Contribute" tools write to Lichess. Their descriptions tell the model to confirm with the user first.
### How the review judges moves
It follows Lichess's own method:
- Each eval is converted to a win percentage: `50 + 50 * (2 / (1 + exp(-0.00368208 * cp)) - 1)`.
- A move is an inaccuracy, mistake or blunder when it loses ≥5, ≥10 or ≥15 win-percentage points and wasn't the engine's choice.
- Allowing a forced mate, or letting one slip, is judged by Lichess's mate rules.
- Per-move accuracy uses `103.1668 * exp(-0.04354 * loss) - 3.1669`, averaged across the game. That's close to Lichess's number but not identical.
## Setup
Requires Python 3.10+ and a [Stockfish](https://stockfishchess.org/download/) binary.
```bash
python -m venv .venv
.venv/bin/pip install -r requirements.txt # Windows: .venv\Scripts\pip
```
| Environment variable | Default | Purpose |
|---|---|---|
| `STOCKFISH_PATH` | `./bin/**/stockfish*.exe`, then `stockfish` on PATH | Engine binary |
| `LICHESS_TOKEN` | unset | Only for `publish_review_to_study` (scope `study:write`): [create one](https://lichess.org/account/oauth/token/create?scopes[]=study:write&description=lichess-mcp) |
| `ENGINE_THREADS` | half the CPUs | Stockfish threads |
| `ENGINE_HASH_MB` | 256 | Stockfish hash |
| `SSL_CERT_FILE` | system store | Custom CA bundle, for example behind a TLS-inspecting proxy |
### Register with Claude Code
```bash
claude mcp add lichess -e STOCKFISH_PATH=/usr/games/stockfish -- /path/to/.venv/bin/python /path/to/server.py
```
Or use a project `.mcp.json`:
```json
{
"mcpServers": {
"lichess": {
"command": "/path/to/.venv/bin/python",
"args": ["/path/to/server.py"],
"env": { "STOCKFISH_PATH": "/usr/games/stockfish", "LICHESS_TOKEN": "${LICHESS_TOKEN:-}" }
}
}
}
```
**Windows with WSL:** run the server inside WSL by setting `"command": "wsl.exe"` and `"args": ["-e", "env", "STOCKFISH_PATH=...", "/home/you/.venv/bin/python", "/mnt/c/.../server.py"]`. Add `"WSLENV": "LICHESS_TOKEN"` to `env` to pass the token through.
### Example prompts
- "Review my last 10 blitz games on Lichess (user `<name>`) and tell me my recurring mistakes."
- "Review lichess.org/abcd1234 and add the annotated version to my study `<id>`."
- "What do 1800-rated players play after 1.e4 c5 2.Nf3 d6, and what does Stockfish think?"
## Tests
```bash
python tests/test_server.py # engine + live Lichess
python tests/test_server.py offline # engine only
```
## More ways to support the community
- **[fishnet](https://github.com/lichess-org/fishnet)**: donate CPU to Lichess's free server-side analysis.
- **[Fishtest](https://tests.stockfishchess.org)**: donate CPU to test Stockfish patches.
- **[lichess-bot](https://github.com/lichess-bot-devs/lichess-bot)**: run an engine as a public bot. Upgrading to a bot account is permanent, so use a new account.
## Fair play
Use this only after games, for study, or for your own imported games. Getting engine help during a live game breaks the Lichess (and Chess.com) Terms of Service.
## License
MIT for this code. Stockfish itself is GPLv3 and isn't included. This server runs it as a separate program.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues