Provides an MCP server with interactive React components for ChatGPT Apps, enabling calculator widgets and custom UI components that render inline in ChatGPT with state persistence and bidirectional communication.
MCP Server for ChatGPT Apps
A Model Context Protocol (MCP) server with interactive React components for ChatGPT Apps.
What is This?
This project implements an MCP server that works with ChatGPT Apps SDK, featuring:
SSE-based MCP server - HTTP server using Server-Sent Events
Interactive React widgets - Components that render inline in ChatGPT
Calculator example - A fully functional calculator with history
Modern build system - Vite + React + TypeScript + Tailwind CSS
Project Structure
Installation
1. Install Dependencies
2. Build Components
This generates bundled React components in the assets/ directory.
Running the Server
Start the MCP Server
The server will start on http://localhost:8000 with these endpoints:
GET /mcp- SSE streamPOST /mcp/messages?sessionId=...- Message handler
Testing with ChatGPT
Option 1: Local Testing with ngrok
Start the server:
npm run serverExpose with ngrok:
ngrok http 8000Add to ChatGPT:
Go to ChatGPT Settings > Connectors
Add connector with URL:
https://YOUR-ID.ngrok-free.app/mcp
Use in ChatGPT:
Add the connector to your conversation
Ask: "Show me a calculator" or "Open calculator"
The interactive calculator widget will appear!
Option 2: Production Deployment
Set base URL for assets:
export BASE_URL=https://your-cdn.com npm run buildDeploy:
Upload
assets/to a CDN or static hosting (with CORS enabled)Deploy the MCP server with HTTPS
Register in ChatGPT with your server URL
Available Tools
1. Calculator (with React UI)
Tool:
calculatorDescription: Interactive calculator widget with history
Features:
Basic arithmetic operations
Calculation history (last 5 calculations)
Dark/light theme support
State persistence across turns
2. Get Current Time
Tool:
get_current_timeReturns: Current time in ISO format
3. Echo
Tool:
echoReturns: Echoes back your message
Development
Run Dev Server (with hot reload)
Visit http://localhost:4444 to preview components.
Adding New Components
Create component in
web/src/your-component/index.tsx:
Update Vite config (
vite.config.ts):
Update post-build script (
scripts/post-build.js):
Add widget to server (
server/src/server.ts):
Build and test:
Key Features
window.openai API
Components have access to:
Custom Hooks
Troubleshooting
"Widget assets not found"
Run npm run build to generate component bundles.
CORS errors
Ensure your server has CORS enabled (already configured in server.ts).
Components not rendering
Check browser console for errors
Verify assets are accessible at BASE_URL
Ensure HTML files reference correct JS/CSS paths
Resources
License
ISC
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables interactive React components to render inline in ChatGPT conversations, featuring a calculator widget with history and demonstrating how to build custom UI components for ChatGPT Apps.