Chess MCP
Play interactive chess games through conversation with move validation, Stockfish engine analysis, tactical puzzles, and a visual chess board widget in ChatGPT.
README
Chess MCP App
A ChatGPT Chess application built with OpenAI Apps SDK, allowing you to play chess through conversation with an interactive board widget.
Now following OpenAI Apps SDK best practices!
Features
- 🎮 Play chess using algebraic notation (e4, Nf3, O-O, etc.)
- 📊 Interactive chess board widget in ChatGPT
- 🤖 AI opponent suggestions (ChatGPT can play moves)
- 🔍 Stockfish engine analysis integration
- 📝 Move history tracking
- ✅ Full move validation and game state management
- 📋 Game status and player information display
- 🧩 Mate in 1 tactical puzzles (Easy, Medium, Hard)
Architecture
- Backend: Python MCP Server using FastMCP with python-chess
- Frontend: React component with chess.js + react-chessboard
- Build System: Vite for optimal development experience
- Integration: OpenAI Apps SDK patterns with proper hooks
Project Structure
ChessMCP/
├── server/
│ ├── main.py # Python MCP server (renamed from server.py)
│ └── requirements.txt # Python dependencies
├── src/
│ ├── chess-board/ # Chess board component
│ │ └── index.tsx
│ ├── types.ts # Shared TypeScript types
│ ├── use-openai-global.ts # Hook for window.openai access
│ ├── use-widget-state.ts # Hook for widget state
│ └── use-widget-props.ts # Hook for tool props
├── assets/ # Build output (generated by Vite)
│ └── chess-board.html
├── vite.config.mts # Vite configuration
├── package.json # Root dependencies
├── tsconfig.json # TypeScript config
└── README.md
Installation
Prerequisites
- Python 3.8+
- Node.js 18+
- Stockfish chess engine (optional, for analysis)
Setup Steps
- Install Python dependencies:
cd server
pip3 install -r requirements.txt
- Install Stockfish (optional, for engine analysis):
# macOS
brew install stockfish
# Ubuntu/Debian
sudo apt-get install stockfish
- Install Node.js dependencies:
npm install
- Build the frontend component:
npm run build
This generates assets/chess-board.html which the server loads.
- The MCP server is configured in your
~/.cursor/mcp.json:
{
"mcpServers": {
"chess": {
"command": "python3",
"args": ["/path/to/ChessMCP/server/main.py"],
"env": {
"PYTHONPATH": "/path/to/ChessMCP/server"
}
}
}
}
Development Workflow
Build Once (Production)
npm run build
Development Mode (with hot reload)
# Terminal 1: Start Vite dev server
npm run dev
# Terminal 2: Start Python server
cd server
python3 main.py
Serve Built Assets (for testing)
npm run serve
Testing Locally (No ChatGPT Required!)
Option 1: Direct Local Tester (Recommended)
Play chess directly without server/OAuth:
python3 chess_local_test.py
Commands:
♟️ > move e4
♟️ > move e5
♟️ > status
♟️ > stockfish
♟️ > puzzle medium
📖 See: LOCAL_TESTING.md
Option 2: HTTP Client
Test via HTTP (requires server running):
# Terminal 1: Start server
cd server && python3 main.py
# Terminal 2: Start client
python3 chess_client.py
📖 See: CLIENT_USAGE.md
Testing with ChatGPT
The Chess MCP server now includes Google OAuth 2.1 authentication for secure ChatGPT integration!
📖 Quick Start: OAUTH_QUICK_START.md (5 minutes)
📖 Detailed Setup: GOOGLE_OAUTH_SETUP.md (Step-by-step)
📖 Next Steps: NEXT_STEPS.md (What to do now)
📖 Troubleshooting: CHATGPT_CONNECTOR_TROUBLESHOOTING.md
Quick start:
# 1. Set up Google OAuth credentials (see GOOGLE_OAUTH_SETUP.md)
# 2. Create server/.env with credentials
# Terminal 1: Start server
cd server
pip3 install -r requirements.txt
python3 main.py
# Terminal 2: Expose with ngrok
ngrok http 8000
# Update server/.env with ngrok URL, restart server
# Then add connector in ChatGPT Settings > Connectors
# URL format: https://YOUR-SUBDOMAIN.ngrok-free.app (no /mcp suffix)
Usage
Starting a Game
In ChatGPT, start a chess game by making your first move:
ChessMCP e4
or
Let's play chess! I'll start with e4
The interactive chess board will appear showing your move.
Making Moves
Simply type your move in algebraic notation:
Nf3
e5
Bc4
Nc6
Supported notation:
- Basic moves:
e4,Nf3,d5 - Captures:
exd5,Nxf7 - Castling:
O-O(kingside),O-O-O(queenside) - Pawn promotion:
e8=Q,a1=N - Check:
Qh5+ - Checkmate:
Qf7#
Additional Commands
Check game status:
chess_status
What's the current status?
Load a puzzle:
Show me a chess puzzle
Give me a hard puzzle
Get engine analysis:
Ask Stockfish for the best move
Reset game:
chess_reset
Let's start a new game
MCP Tools
The server exposes five tools:
chess_move
- Input:
move(string) - Algebraic notation - Output: Updated board state with FEN, move history, game status
- Widget: Renders interactive chess board
chess_stockfish
- Input:
depth(int, default: 15) - Analysis depth - Output: Best move, evaluation, principal variation
- Widget Accessible: Can be called from the widget UI
chess_reset
- Input: None
- Output: Confirmation of reset
- Widget: Shows fresh starting position
chess_status ⭐
- Input: None
- Output: Game status, current turn, player names, move count, recent moves
- Use: Check game progress and who's moving
chess_puzzle ⭐
- Input:
difficulty(string: "easy", "medium", "hard") - Output: Mate-in-1 puzzle position with hint
- Widget: Shows puzzle position on the board
- Use: Practice tactical patterns and checkmate recognition
React Hooks (Apps SDK Patterns)
The component uses OpenAI Apps SDK hooks for clean, reactive code:
useOpenAiGlobal(key)
Access window.openai properties reactively:
const theme = useOpenAiGlobal("theme");
const displayMode = useOpenAiGlobal("displayMode");
useToolOutput<T>()
Get the current tool output:
const toolOutput = useToolOutput<ChessToolOutput>();
// Returns: { fen, move, status, turn }
useToolResponseMetadata<T>()
Get tool response metadata:
const metadata = useToolResponseMetadata<ChessMetadata>();
// Returns: { move_history_list, legal_moves, etc. }
useWidgetState<T>(defaultState)
Persist component state across sessions:
const [widgetState, setWidgetState] = useWidgetState<ChessWidgetState>({
lastDepth: 15,
analysisVisible: false
});
Build System (Vite)
Why Vite?
- ⚡️ Fast hot module replacement during development
- 📦 Optimized production builds
- 🎯 TypeScript support out of the box
- 🔧 Better error messages
- 🎨 Source maps for debugging
Build Output
The build creates a single HTML file containing:
- Bundled React component
- All JavaScript dependencies
- Inline CSS
- Proper structure for Skybridge runtime
Configuration
See vite.config.mts for the build configuration. The setup:
- Bundles
src/chess-board/index.tsx - Includes all dependencies
- Wraps in HTML with proper structure
- Outputs to
assets/chess-board.html
Server Architecture
Resource Handling
The server follows Apps SDK patterns:
# Load HTML from assets
@lru_cache(maxsize=None)
def load_widget_html(component_name: str) -> str:
html_path = ASSETS_DIR / f"{component_name}.html"
return html_path.read_text(encoding="utf8")
# Proper MIME type
MIME_TYPE = "text/html+skybridge"
# Resource registration
@mcp._mcp_server.list_resources()
async def list_resources() -> List[types.Resource]:
return [types.Resource(...)]
# Resource handler
async def handle_read_resource(req) -> types.ServerResult:
html = load_widget_html("chess-board")
return types.ServerResult(types.ReadResourceResult(...))
Tool Metadata
All tools include proper metadata:
{
"openai/outputTemplate": "ui://widget/chess-board.html",
"openai/widgetAccessible": True,
"openai/resultCanProduceWidget": True,
"openai/toolInvocation/invoking": "Making move...",
"openai/toolInvocation/invoked": "Move played"
}
Troubleshooting
Widget Not Rendering
- Ensure component is built:
npm run build - Verify
assets/chess-board.htmlexists - Check server logs for errors
Stockfish Not Found
Update the path in server/main.py:
STOCKFISH_PATH = "/path/to/stockfish"
Build Errors
If TypeScript errors occur:
npm run typecheck
Server Won't Start
Make sure all Python dependencies are installed:
cd server
pip3 install -r requirements.txt
What's New in This Version
✨ Restructured Project
- Moved from
web/tosrc/directory - Root-level
package.jsonandvite.config.mts - Proper Apps SDK project structure
🎣 React Hooks
useOpenAiGlobalfor reactive window.openai accessuseWidgetStatefor persistent state managementuseToolOutputanduseToolResponseMetadatafor props
⚡ Vite Build System
- Replaced esbuild with Vite
- Hot module replacement in development
- Better TypeScript support
- Faster builds
🏗️ Server Improvements
- Proper resource loading from
assets/ - Correct MIME type (
text/html+skybridge) - Better error handling
- CORS middleware for development
📝 Better Types
- Comprehensive TypeScript types
- Apps SDK-compatible interfaces
- Chess-specific type definitions
Contributing
Feel free to enhance the app with:
- Opening analysis and endgame tablebases
- Multiple game sessions
- PGN import/export
- Time controls
- Online multiplayer
- More puzzle types
License
MIT License - feel free to use and modify!
Resources
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。