Description
## Prerequisites
- Python 3.10 or higher
- An OpenAI API key (get one from [platform.openai.com/api-keys](https://platform.openai.com/api-keys))
- Git for cloning the repository
- ngrok or Cloudflare Tunnel for exposing local servers (HTTPS required for ChatGPT Desktop)
- ChatGPT Desktop app (latest version) with Developer Mode enabled
## Setup for ChatGPT Desktop
### Option 1: Using Developer Mode (Recommended)
1. Open ChatGPT Desktop and go to **Settings → Apps & Connectors → Advanced settings**.
2. Enable **Developer Mode**.
3. Navigate to **Settings → Apps & Connectors → Create** and select **MCP Server**.
4. Enter the MCP server URL (e.g., `https://your-ngrok-url.ngrok.io/mcp`).
5. Add authentication if required (e.g., Bearer token via headers).
6. Save the connector. ChatGPT will now discover and use the server's tools.
### Option 2: Local Server Setup
1. Start the server locally (see Start Command above). It runs on `http://localhost:8787/mcp` by default.
2. Expose it via HTTPS:
- **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 provided HTTPS URL.
3. Use the full MCP endpoint URL (e.g., `https://abc123.ngrok.io/mcp`) in ChatGPT's Developer Mode connector setup.
## Configuration Examples
### Basic Setup
Use minimal environment variables for quick start:
```bash
export OPENAI_API_KEY=sk-your-openai-key
python main.py
```
Connect ChatGPT to `http://localhost:8787/mcp` (local) or ngrok URL.
### Advanced Setup
Enable multi-LLM and custom options:
```bash
export OPENAI_API_KEY=sk-your-openai-key
export ANTHROPIC_API_KEY=your-anthropic-key # For additional LLM support
export MAX_COST_PER_SESSION=10.00 # USD limit
export TOOLS_ENABLED=file,search,shell # Customize tools
python main.py --port 8787 --debug
```
Supports other LLMs like Anthropic via env vars.
### Production Setup
For secure, persistent use:
```bash
# Use .env file
echo "OPENAI_API_KEY=sk-prod-key" > .env
echo "MCP_HOST=0.0.0.0" >> .env
echo "LOG_LEVEL=info" >> .env
# Run with PM2 or systemd for daemon
pm2 start main.py --name mcp-coding-assistant
```
Deploy on VPS with Cloudflare Tunnel or reverse proxy (e.g., Nginx) for HTTPS.
## Using with ChatGPT
Once connected, ChatGPT gains access to:
- **File operations**: Read/write/edit files, list directories.
- **Search**: Code search, web search integration.
- **Shell execution**: Run commands, manage processes.
- **Real-time visualization**: Tool calls shown inline with costs.
- **Cost management**: Tracks and limits API usage.
**Example Prompts**:
- "Create a new Python file called `hello.py` in my project folder and write a simple web server."
- "Search my codebase for 'def process_data' and explain the function."
- "Run `ls -la` in the current directory and summarize the output."
- "Optimize this SQL query: [paste query] and save the improved version."
**Limitations/Considerations**:
- Local servers need HTTPS tunneling.
- Shell execution is powerful—use sandboxed environments.
- Costs accrue from LLM calls; monitor via built-in tracking.
- Tools are read-eval only by default; enable writes cautiously.
## Troubleshooting
- **Connection failed**: Ensure HTTPS URL ends with `/mcp` and server is running (`curl http://localhost:8787/mcp`).
- **API key errors**: Verify `OPENAI_API_KEY` is valid and has credits.
- **ngrok issues**: Free ngrok changes URLs on restart—use paid for static domains.
- **Tools not appearing**: Restart ChatGPT Desktop after connector setup; check server logs for errors.
- **Port conflicts**: Change `MCP_PORT` env var.
- **High latency**: Use production setup; avoid local for heavy use.
- Logs: Run with `--debug` for verbose output.