Stockfish MCP服务器
一个模型上下文协议(MCP)服务器,将Stockfish国际象棋引擎与Claude Desktop集成在一起,允许您在人工智能的帮助下下棋。
🗓️ 自然语言象棋
  
特性
- 🎮 使用可定制的ELO评级启动和管理国际象棋游戏
- 🤖 从Stockfish引擎获取最佳移动建议
- 📊 使用Redis的持久游戏状态存储
- ♟️ 完全支持UCI国际象棋符号
- 🔄 实时游戏状态更新
- 🖼️ 带有自动生成图像的可视化电路板表示
先决条件
- Python 3.13+
- Stockfish象棋引擎
- Redis服务器
- 紫外线 (推荐)或pip
安装
1.克隆存储库
git clone https://github.com/sankalp0412/stockfish-mcp.git
cd stockfish-mcp2.安装Stockfish
macOS(Homebrew):
brew install stockfish
which stockfish # Note the path for laterLinux:
sudo apt-get install stockfish # Debian/Ubuntu
# or
sudo yum install stockfish # RHEL/CentOS窗户: 下载自 stockfishches.org/下载
3.安装Redis
macOS(Homebrew):
brew install redis
brew services start redisLinux:
sudo apt-get install redis-server
sudo systemctl start redis窗户: 使用 Windows版Redis
4.设置环境变量
cp .env.example .env编辑 .env 并设置您的Stockfish路径:
STOCKFISH_PATH=/usr/local/bin/stockfish # Update with your actual path
REDIS_HOST=localhost
REDIS_PORT=63795.安装Python依赖项
使用紫外线(推荐):
uv sync使用pip:
pip install -e .配置Claude桌面
将以下内容添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json\ 窗户: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"stockfish-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/stockfish-mcp",
"run",
"stockfish-mcp"
]
}
}
}重要提示: 替换 /absolute/path/to/stockfish-mcp 使用克隆存储库的实际绝对路径。
重新启动克劳德桌面 完全(退出并重新打开)以使更改生效。
用法
配置后,您可以通过Claude与国际象棋引擎进行交互。以下是游戏方法:
开始新游戏
Start a chess game with ELO rating 2000下棋
只需用自然语言告诉克劳德你的动作:
I want to play e4
Play knight to f3
Move my bishop to c4克劳德将:
- 使用
play_move应用您的移动 - 使用
get_best_moves内部分析立场 - 选择并播放其响应动作
- 在数据库中保持游戏状态的更新
查看董事会
Show me the current board position克劳德将在游戏的任何时候显示棋盘的视觉表示。
关闭游戏
Close the game注: 这 get_best_moves 克劳德自己使用该工具来分析位置并决定其动作。你不需要直接称呼它——只要自然地玩就行了!
MCP工具参考
| 工具 | 说明 | 参数 |
|---|---|---|
start_game | 初始化一个新的国际象棋游戏 | user_elo (可选,默认值:3000) |
get_best_moves | 获取当前位置的前3个动作 | game_id |
play_move | 验证并应用移动 | game_id, user_move (UCI符号) |
get_board_visual | 生成可视化电路板表示 | game_id |
close_game | 结束游戏并从数据库中删除 | game_id |
MCP服务器未在Claude中显示
- 检查Claude Desktop日志是否有错误
- 验证中的绝对路径
claude_desktop_config.json - 确保Redis正在运行:
redis-cli ping(应该回来PONG) - 验证Stockfish路径:
$STOCKFISH_PATH --version - 完全重新启动克劳德桌面
导入错误
cd /path/to/stockfish-mcp
uv sync # Reinstall dependenciesRedis连接错误
# Check if Redis is running
redis-cli ping
# Start Redis
brew services start redis # macOS
sudo systemctl start redis # Linux贡献
欢迎投稿!请随时提交拉取请求。
作者
桑卡尔普·杜帕尔(@桑卡尔p0412)
