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
Installation
Prerequisites
Python 3.8+
Node.js 18+
Stockfish chess engine (optional, for analysis)
Setup Steps
Install Python dependencies:
Install Stockfish (optional, for engine analysis):
Install Node.js dependencies:
Build the frontend component:
This generates assets/chess-board.html which the server loads.
The MCP server is configured in your
~/.cursor/mcp.json:
Development Workflow
Build Once (Production)
Development Mode (with hot reload)
Serve Built Assets (for testing)
Testing Locally (No ChatGPT Required!)
Option 1: Direct Local Tester (Recommended)
Play chess directly without server/OAuth:
Commands:
š See: LOCAL_TESTING.md
Option 2: HTTP Client
Test via HTTP (requires server running):
š 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:
Usage
Starting a Game
In ChatGPT, start a chess game by making your first move:
or
The interactive chess board will appear showing your move.
Making Moves
Simply type your move in algebraic notation:
Supported notation:
Basic moves:
e4,Nf3,d5Captures:
exd5,Nxf7Castling:
O-O(kingside),O-O-O(queenside)Pawn promotion:
e8=Q,a1=NCheck:
Qh5+Checkmate:
Qf7#
Additional Commands
Check game status:
Load a puzzle:
Get engine analysis:
Reset game:
MCP Tools
The server exposes five tools:
chess_move
Input:
move(string) - Algebraic notationOutput: Updated board state with FEN, move history, game status
Widget: Renders interactive chess board
chess_stockfish
Input:
depth(int, default: 15) - Analysis depthOutput: 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:
useToolOutput<T>()
Get the current tool output:
useToolResponseMetadata<T>()
Get tool response metadata:
useWidgetState<T>(defaultState)
Persist component state across sessions:
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.tsxIncludes all dependencies
Wraps in HTML with proper structure
Outputs to
assets/chess-board.html
Server Architecture
Resource Handling
The server follows Apps SDK patterns:
Tool Metadata
All tools include proper metadata:
Troubleshooting
Widget Not Rendering
Ensure component is built:
npm run buildVerify
assets/chess-board.htmlexistsCheck server logs for errors
Stockfish Not Found
Update the path in server/main.py:
Build Errors
If TypeScript errors occur:
Server Won't Start
Make sure all Python dependencies are installed:
What's New in This Version
⨠Restructured Project
Moved from
web/tosrc/directoryRoot-level
package.jsonandvite.config.mtsProper 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!