Description
## Prerequisites
- Node.js (version 18 or higher)
- An OpenAI account with an API key (get one at [platform.openai.com/api-keys](https://platform.openai.com/api-keys))
- ChatGPT Desktop app (latest version)
- ngrok account (free tier sufficient) or Cloudflare Tunnel for exposing local server via HTTPS
- Basic familiarity with terminal commands
## Setup for ChatGPT Desktop
### Option 1: Using Developer Mode (Recommended)
1. Open ChatGPT Desktop and navigate to **Settings → Apps & Connectors → Advanced settings → Enable Developer Mode**.
2. Go to **Settings → Apps & Connectors → Create** to add a new connector.
3. Enter the MCP server URL (e.g., `https://your-ngrok-subdomain.ngrok-free.app/mcp` from ngrok).
4. Leave authentication blank unless custom auth is configured (default is none).
5. Save and test the connection—ChatGPT will now have access to OpenAI MCP tools.
### Option 2: Local Server Setup
1. Follow the start command to clone, install, and run the server locally (defaults to `http://localhost:3000`).
2. Install and authenticate ngrok: `ngrok authtoken YOUR_NGROK_TOKEN`.
3. Expose the server: `ngrok http 3000`.
4. Copy the HTTPS forwarding URL (e.g., `https://abc123.ngrok-free.app`) and append `/mcp` for the full endpoint.
5. Use this URL in ChatGPT Desktop's Developer Mode connector as described in Option 1.
**Alternative with Cloudflare Tunnel:**
```bash
# Install cloudflared
brew install cloudflared # macOS, or equivalent for your OS
# Run tunnel
cloudflared tunnel --url http://localhost:3000
```
Use the provided HTTPS URL.
## Configuration Examples
### Basic Setup
Minimal config for quick start:
```bash
export OPENAI_API_KEY=sk-your-key
npm run dev
```
Server runs on `http://localhost:3000/mcp`. Tunnel with ngrok and connect to ChatGPT.
### Advanced Setup
Customize models and options:
```bash
export OPENAI_API_KEY=sk-your-key
export OPENAI_BASE_URL=https://api.openai.com/v1 # Custom endpoint if needed
export ALLOWED_MODELS=gpt-4o,gpt-4o-mini,gpt-4-turbo # Restrict models
export PORT=8080 # Change port
npm run dev
```
Update ngrok/tunnel to match the new port.
### Production Setup
For reliable, secure use:
1. Use PM2 for process management: `npm i -g pm2`, then `pm2 start npm --name "openai-mcp" -- run start`.
2. Set up a reverse proxy (e.g., Nginx) with SSL certs from Let's Encrypt.
3. Use a paid ngrok/Cloudflare plan for static domains.
4. Add auth: `export MCP_AUTH_TOKEN=your-secret-token` and configure ChatGPT connector with Bearer token.
## Using with ChatGPT
- **Available Capabilities**: Tools like `list_openai_models`, `openai_chat_completion`, `openai_embeddings` become available, allowing ChatGPT Desktop to invoke OpenAI models (e.g., GPT-4o, GPT-4o-mini) for tasks like generation, analysis, or embeddings.
- **Example Prompts**:
- "List all available OpenAI models using the MCP tool."
- "Use GPT-4o-mini via OpenAI MCP to summarize this article: [paste text]."
- "Generate code with GPT-4o: Write a Python function for [task]."
- **Limitations/Considerations**: Incurs OpenAI API costs based on usage; subject to rate limits and quotas. Local server adds slight latency. Ensure HTTPS for ChatGPT compatibility—no HTTP.
## Troubleshooting
- **Server fails to start**: Verify Node.js version (`node -v`), reinstall deps (`rm -rf node_modules && npm install`), check port conflicts.
- **ChatGPT connection error**: Confirm HTTPS URL (HTTP not supported); restart ngrok/tunnel; check firewall blocks port 3000.
- **API 401/Invalid Key**: Double-check `OPENAI_API_KEY` export (use `echo $OPENAI_API_KEY`); regenerate key if needed.
- **Tool not appearing in ChatGPT**: Refresh Developer Mode connector; restart ChatGPT Desktop; verify `/mcp` endpoint responds (curl `https://your-url/mcp`).
- **Rate limit errors**: Monitor OpenAI dashboard; add `export MAX_TOKENS=4000` or upgrade plan.
- Logs: Check server console for details; enable debug with `export DEBUG=mcp*`.