Skip to content

Cloud Deployment

Deploy gmail-mcp-server to EC2, DigitalOcean, or any cloud VPS so ChatGPT can access it.

  • ChatGPT Integration: Use Gmail tools in ChatGPT custom connectors
  • Remote Access: Reach your server from anywhere
  • Shared Setup: Single server, multiple clients
  • Linux server (Ubuntu 20.04+)
  • Domain pointing to your server
  • Docker & Docker Compose
  • A reverse proxy (Caddy or Nginx)

Install Caddy:

Terminal window
sudo apt-get update && sudo apt-get install -y caddy

Create /etc/caddy/Caddyfile:

gmail-mcp.example.com {
reverse_proxy localhost:8811
}

Replace gmail-mcp.example.com with your domain.

Terminal window
sudo systemctl start caddy
sudo systemctl enable caddy

Caddy auto-handles HTTPS with Let’s Encrypt. Done!

Install Nginx:

Terminal window
sudo apt-get install -y nginx

Create /etc/nginx/sites-available/gmail-mcp:

server {
listen 80;
server_name gmail-mcp.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name gmail-mcp.example.com;
ssl_certificate /etc/letsencrypt/live/gmail-mcp.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gmail-mcp.example.com/privkey.pem;
location / {
proxy_pass http://localhost:8811;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

Get SSL cert with Certbot:

Terminal window
sudo certbot certonly --standalone -d gmail-mcp.example.com
sudo systemctl start nginx && sudo systemctl enable nginx

Upload secrets/credentials.json from your local machine:

Terminal window
scp secrets/credentials.json user@your-server:~/gmail-mcp-server/secrets/

On your server:

Terminal window
cd ~/gmail-mcp-server
python -m venv .venv
source .venv/bin/activate
pip install -e .
python authorize.py

If you can’t open a browser, use SSH port forwarding:

Terminal window
# On your local machine:
ssh -L 8080:localhost:8080 user@your-server
# Visit http://localhost:8080 in your browser

Copy template:

Terminal window
cp .env.example .env

Edit .env with your values:

GMAIL_MCP_CREDENTIALS=secrets/credentials.json
GMAIL_MCP_TOKEN=secrets/token.json
GMAIL_MCP_ALLOWED_HOSTS=gmail-mcp.example.com
GMAIL_MCP_ENABLE_OAUTH=1
GMAIL_MCP_ISSUER_URL=https://gmail-mcp.example.com
GMAIL_MCP_OAUTH_CLIENT_ID=gmail-mcp-abc123
GMAIL_MCP_OAUTH_REDIRECT_URIS=https://chatgpt.com/connector/oauth/your_id
GMAIL_MCP_OAUTH_PASSPHRASE=$(python -c "import secrets; print(secrets.token_urlsafe(24))")
GMAIL_MCP_OAUTH_STATE=secrets/oauth_state.json
Terminal window
docker compose up -d --build
docker compose logs gmail-mcp

Should show: INFO: Uvicorn running on http://0.0.0.0:8811

  1. In ChatGPT, Settings → Tools → Create action
  2. Fill in:
    • Name: gmail-mcp
    • Server URL: https://gmail-mcp.example.com/mcp
    • Authentication: OAuth
    • Client ID: gmail-mcp-abc123 (from .env)
    • Token endpoint auth: None
  3. Save → auto-discovers endpoints
  4. First use → consent page → enter passphrase → done!
  • ✅ Only gmail.readonly and gmail.compose requested
  • ✅ Your token is local, never sent to us
  • ✅ Passphrase protects the consent screen
  • ✅ DNS rebinding protection (GMAIL_MCP_ALLOWED_HOSTS)
  • ✅ Only drafts are writable—never send, modify, delete

Stuck? See Troubleshooting.