stockfish-mcp
Analyzes chess positions via Stockfish, returning best moves and evaluations from FEN or PGN input.
README
stockfish-mcp
A tiny, opinionated Model Context Protocol server that gives an LLM the best move for any chess position — powered by Stockfish.
Hand it a position as FEN or PGN (or nothing, for the starting position) and it returns the best move, the engine's evaluation, and — optionally — the predicted best line, as clean structured JSON. One tool. One call. No UCI knowledge required.
{
"turn": "black",
"bestmove": { "uci": "f6e4", "san": "Nxe4" },
"ponder": { "uci": "d2d4", "san": "d4" },
"score": { "type": "cp", "value": -371, "perspective": "side to move" },
"evaluation": "White is better (+3.71)",
"fen": "r1bqk2r/ppp2ppp/2np1n2/P3p3/1PB1P3/5N2/2PP1PPP/RNBQ1RK1 b kq - 0 7"
}
Why another Stockfish MCP?
Most chess-engine MCP servers are thin UCI passthroughs: they hand the language model the raw UCI protocol (position, go, setoption, session IDs) and expect it to orchestrate a stateful, multi-call conversation with the engine. That's the wrong abstraction for an LLM, and it's a source of constant confusion — empty "silent command" responses, position state lost between calls, malformed FENs, and raw dumps of 30 search-trace lines.
stockfish-mcp takes the opposite approach. The model gets one high-level operation and the server handles everything else:
- One tool, one call. Set the position and search it in a single
analyzecall. Noposition-then-godance, no sessions to manage. - FEN or PGN in. Paste a FEN, a full PGN, a bare move list, or
startpos. Short FENs missing the halfmove/fullmove fields are accepted and normalized. - Unambiguous evaluation. UCI reports scores from the side-to-move's perspective (a classic footgun). We normalize to a White-perspective summary —
"White is better (+3.71)","Mate in 1 for Black"— that a model can relay verbatim without misreading who's winning. - Human-readable moves. Best move and ponder move in SAN (
Nxe4,O-O,e8=Q+), alongside the raw UCI. - Optional best line.
includeLine: trueadds the engine's principal variation as a numbered SAN line (1. e4 c5 2. Nf3 …), truncated for readability. Off by default to keep responses tight. - Stateless & robust. A fresh engine process per call (startup is ~tens of ms vs. a multi-second search) means no shared state, no race conditions, no leaked startup banners.
- Clear errors. Terminal positions (checkmate/stalemate/draw) and invalid input return descriptive messages instead of hanging or crashing.
Requirements
- Node.js ≥ 18
- Stockfish installed and on your
PATH(or pointSTOCKFISH_PATHat the binary). This project does not bundle Stockfish.
Install Stockfish:
# Debian / Ubuntu
sudo apt install stockfish
# macOS (Homebrew)
brew install stockfish
# or download a binary from https://stockfishchess.org/download/
Usage
With any MCP client (Claude Desktop, etc.)
Add to your client's MCP config. If published to npm:
{
"mcpServers": {
"stockfish": {
"command": "npx",
"args": ["-y", "stockfish-mcp"]
}
}
}
Or run it from a local checkout:
{
"mcpServers": {
"stockfish": {
"command": "node",
"args": ["/path/to/stockfish-mcp/index.mjs"]
}
}
}
From the command line (manual testing)
npm install
npm start # speaks MCP over stdio
npm test # end-to-end smoke test (needs stockfish installed)
The analyze tool
| Parameter | Type | Default | Description |
|---|---|---|---|
position |
string | start position | A FEN string or PGN/move list. Omit for the starting position. |
depth |
integer | 18 |
Search depth in plies. Higher = stronger but slower. |
movetime |
integer | — | If given, search this many milliseconds instead of a fixed depth. |
includeLine |
boolean | false |
Include the engine's predicted best line (PV) in SAN. |
Response
| Field | Description |
|---|---|
turn |
"white" or "black" — side to move in the given position. |
bestmove |
{ uci, san } — the best move (null if the position is already terminal). |
ponder |
{ uci, san } or null — the reply the engine expects. |
score |
{ type: "cp" | "mate", value, perspective: "side to move" } — raw engine score. |
evaluation |
Human-readable, White-perspective summary, e.g. "White is better (+3.71)", "Mate in 1 for Black", "roughly equal". |
fen |
The FEN actually analyzed (after PGN conversion / normalization). |
line |
(only with includeLine) Numbered SAN principal variation, truncated with …. |
Examples
FEN (black to move):
// analyze({ "position": "r1bqk2r/ppp2ppp/2np1n2/P3p3/2B1P3/5N2/2PP1PPP/RNBQ1RK1 b kq - 0 7", "depth": 14 })
{
"turn": "black",
"bestmove": { "uci": "f6e4", "san": "Nxe4" },
"ponder": { "uci": "d2d4", "san": "d4" },
"evaluation": "White is better (+3.71)"
}
PGN:
// analyze({ "position": "1. e4 e5 2. Nf3 Nc6 3. Bb5 a6", "depth": 12 })
{
"turn": "white",
"bestmove": { "uci": "b5c6", "san": "Bxc6" },
"ponder": { "uci": "d7c6", "san": "dxc6" },
"evaluation": "White is better (+0.36)"
}
Best line + mate detection:
// analyze({ "position": "6k1/5ppp/8/8/8/8/8/R6K w - - 0 1", "includeLine": true })
{
"turn": "white",
"bestmove": { "uci": "a1a8", "san": "Ra8#" },
"evaluation": "Mate in 1 for White",
"line": "1. Ra8#"
}
Configuration
Environment variables:
| Variable | Default | Description |
|---|---|---|
STOCKFISH_PATH |
stockfish |
Path to the Stockfish binary. |
STOCKFISH_TIMEOUT_MS |
60000 |
Per-search safety timeout, in milliseconds. |
STOCKFISH_DEFAULT_DEPTH |
18 |
Search depth used when the caller omits depth. |
Example:
{
"mcpServers": {
"stockfish": {
"command": "npx",
"args": ["-y", "stockfish-mcp"],
"env": { "STOCKFISH_PATH": "/usr/games/stockfish", "STOCKFISH_DEFAULT_DEPTH": "20" }
}
}
}
How it works
The server spawns a fresh stockfish process for each analyze call, sends position fen … followed by go depth N (or go movetime N), reads the engine's info lines to capture the latest score and principal variation, and resolves on bestmove. Moves are converted to SAN with chess.js, which also handles PGN→FEN conversion and FEN validation.
Two UCI subtleties worth noting (both handled here): go is asynchronous, so stdin is left open and no quit is sent before the search finishes — closing the pipe would abort it. And score cp/score mate are reported from the side-to-move's perspective, so we flip them when Black is to move to produce a consistent White-perspective evaluation.
License
MIT.
A note on Stockfish: Stockfish itself is licensed GPL-3.0. This project does not include, link against, modify, or distribute Stockfish — it only spawns a Stockfish binary that you install separately and communicates with it over the public UCI protocol via a pipe. The two are separate programs, so this wrapper is independently licensed under MIT. You are responsible for obtaining Stockfish and complying with its license.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。