Provides ChatGPT app integration using the OpenAI Apps SDK (MCP), enabling tools, resources, and interactive widgets to be used within ChatGPT conversations through OAuth2 authentication.
ChatGPT App with OAuth2 + MCP + Privy
A complete ChatGPT App implementation using the OpenAI Apps SDK (MCP), with OAuth2 authentication via Privy.io.
๐๏ธ Architecture
Backend: Express + MCP Server (TypeScript/Bun)
OAuth UI: React + Privy + React Router
Widgets: React components (rendered in ChatGPT)
Auth: OAuth2 with PKCE + Privy.io
Package Manager: Bun
๐ Project Structure
๐ Quick Start
Prerequisites
1. Install Bun
2. Install Dependencies
3. Generate JWT Keys
4. Configure Environment
5. Build & Run
IMPORTANT: Widgets must be built before starting the server!
The server will start at http://localhost:3002
๐ง Development
Understanding the Widget Build Process
โ ๏ธ Key Point: bun run dev does NOT automatically build widgets. You must build them separately!
There are three development workflows:
Option 1: Manual Build (Recommended for first-time setup)
Option 2: Watch Mode (Recommended for active widget development)
Option 3: Run Everything (Most convenient)
Other Development Commands
Project Configuration
Server: src/server/index.ts
OAuth endpoints:
/authorize,/token,/.well-known/*MCP endpoint:
/mcpHealth check:
/health
OAuth UI: src/client/src/App.tsx
Authorization page with Privy login
Consent screen
Built with Vite + React + React Router
Widgets: src/widgets/src/
ListView: Interactive list with actions
Built as standalone bundles
Communicate via
window.openaiAPI
๐งช Testing
Test with MCP Inspector
Test with ngrok
Connect to ChatGPT
Enable Developer Mode:
ChatGPT Settings โ Apps & Connectors โ Advanced settings
Enable "Developer mode"
Create Connector:
Settings โ Connectors โ Create
Name: "Your App Name"
Description: "What your app does"
Connector URL:
https://your-server.com/mcp(or ngrok URL)
Test OAuth Flow:
Start a new ChatGPT conversation
Click + โ More โ Select your connector
You'll be redirected to
/authorizeLog in with Privy
Grant consent
ChatGPT receives OAuth token
Test Tools:
Ask ChatGPT: "Show me my items"
The
get-itemstool will be calledWidget will render in ChatGPT
๐ฆ Production Build
Docker Deployment
Deploy to Fly.io
๐ OAuth2 Flow
ChatGPT redirects user to
/authorize?client_id=...&code_challenge=...Server serves React UI (Privy login)
User authenticates with Privy
Frontend shows consent screen
User approves, server generates authorization code
Frontend redirects back to ChatGPT with code
ChatGPT exchanges code for access token at
/tokenServer validates PKCE, issues JWT
ChatGPT uses JWT for
/mcprequests
๐จ Adding New Tools
1. Define Tool in src/server/mcp/tools.ts
2. Implement Handler
3. Link to Widget (Optional)
๐จ Adding New Widgets
1. Create Widget Component
2. Build Widget
3. Configure Vite
4. Register Resource
๐ Environment Variables
Variable | Description | Required |
| Your Privy app ID | โ |
| Your Privy app secret | โ |
| Privy app ID (for frontend) | โ |
| Base64-encoded RSA private key | โ |
| Base64-encoded RSA public key | โ |
| Your server URL | โ |
| Your existing backend URL | โ |
| Server port (default: 3000) | โ |
| Environment (development/production) | โ |
๐ Troubleshooting
Widgets not loading
OAuth flow fails
Check
SERVER_BASE_URLmatches your actual URLVerify Privy app ID is correct
Check JWT keys are properly base64-encoded
Ensure redirect URI is registered in ChatGPT
Token validation fails
Verify JWT keys are correct (public/private pair)
Check token hasn't expired (1 hour default)
Ensure
audclaim matches your server URL
MCP Inspector can't connect
๐ Resources
๐ License
MIT
๐ค Contributing
Contributions welcome! Please open an issue or PR.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A complete ChatGPT App implementation using MCP with OAuth2 authentication via Privy.io, enabling secure user authentication and interactive widgets rendered in ChatGPT.