Description
## Prerequisites
- Node.js (v18 or higher)
- npm (v9 or higher)
- OpenAI API key (get one from [platform.openai.com/api-keys](https://platform.openai.com/api-keys))
- ChatGPT Desktop app (latest version with Developer Mode support)
- ngrok or Cloudflare Tunnel (for exposing local server to HTTPS)
- Git (for cloning the repo)
## Setup for ChatGPT Desktop
### Option 1: Using Developer Mode (Recommended)
1. Open ChatGPT Desktop and go to **Settings → Apps & Connectors → Advanced settings → Enable Developer Mode**.
2. Navigate to **Settings → Apps & Connectors → Create** to add a new connector.
3. Enter the MCP server URL (e.g., `https://your-ngrok-url.ngrok.io/mcp`—see Option 2 for local exposure).
4. For authentication, add header: `Authorization: Bearer $OPENAI_API_KEY` or use query param if supported.
5. Save and test the connector—ChatGPT will now have access to OpenAI Assistant tools.
### Option 2: Local Server Setup
1. Follow the start command to clone, install, and run the server locally (`http://localhost:8787/mcp`).
2. Expose the endpoint via HTTPS (MCP requires secure connection):
- **ngrok**: Install ngrok, then run `ngrok http 8787`. Copy the HTTPS URL (e.g., `https://abc123.ngrok.io`).
- **Cloudflare Tunnel**: Install cloudflared, run `cloudflared tunnel --url http://localhost:8787`. Use the generated URL.
3. Use the full MCP URL in ChatGPT Desktop connector: `https://your-tunnel-url/mcp`.
4. Restart the server if needed and verify connectivity.
## Configuration Examples
### Basic Setup
Minimal env vars for quick start:
```bash
export OPENAI_API_KEY=sk-...
npm start
```
Server runs on `http://localhost:8787/mcp`. Expose with ngrok and add to ChatGPT.
### Advanced Setup
Add persistence and custom ports:
```bash
export OPENAI_API_KEY=sk-...
export PORT=3000
export DB_PATH=./my_threads.db # Custom SQLite path
npm start
```
Access via `http://localhost:3000/mcp`.
### Production Setup
Secure with env vars and HTTPS reverse proxy:
```bash
export OPENAI_API_KEY=sk-...
export NODE_ENV=production
export DB_PATH=/secure/path/threads.db
npm start
```
Use PM2 for process management: `npm install -g pm2; pm2 start npm --name "mcp-server" -- start`.
Expose via domain with SSL (e.g., Caddy/Nginx).
## Using with ChatGPT
- **Available Tools**: `create_assistant`, `run_assistant`, `list_threads`, `manage_conversations`—enabling ChatGPT to build and interact with custom OpenAI Assistants.
- **Example Prompts**:
- "Create a coding assistant with tools for Python debugging and run it on this code: [paste code]."
- "List my saved threads and continue the last conversation about project planning."
- "Build a math tutor assistant and solve: integrate x^2 from 0 to 1."
- **Limitations/Considerations**: OpenAI API costs apply; local SQLite is single-user; streaming works best with stable connections. Threads persist locally—backup DB_PATH regularly.
## Troubleshooting
- **Connection Refused**: Ensure server is running (`curl http://localhost:8787/mcp`) and tunnel is active.
- **Auth Errors**: Verify `OPENAI_API_KEY` is valid and passed correctly in connector headers.
- **SQLite Issues**: Check file permissions on `DB_PATH`; delete `.db` file to reset.
- **No Tools Visible**: Restart ChatGPT Desktop after adding connector; check Developer Mode logs.
- **Ngrok Disconnects**: Use paid ngrok for static domains or switch to Cloudflare Tunnel.
- **Rate Limits**: Monitor OpenAI usage; add `export MAX_TOKENS=4096` for limits.