# Host a public leadgen MCP server (leadgen.auradevs.co/mcp)

Goal: a **public URL anyone on Earth can add as a connector**, where the server
**runs in the cloud** — not a tunnel to your laptop. Each user gets their own
isolated run (default CSV inline; opt-in their own Notion).

## Tunnel vs. real hosting — the key distinction
- `cloudflared tunnel --url http://localhost:8000` = a tunnel **to your PC**. Dies
  when your PC sleeps. **You don't want this.**
- **A VPS** = the server runs on an always-on machine in the cloud with its own
  public IP/domain. **This is what you want.** (You can still put Cloudflare's
  *proxy* in front for TLS/DDoS — that's different from a localhost tunnel.)

## Free, always-on VPS options
| Provider | Free tier | Good for scraping? |
|---|---|---|
| **Oracle Cloud — Always Free** ⭐ | **Ampere A1 ARM: up to 4 vCPU / 24 GB RAM**, truly always free | **Yes — best.** Plenty for many concurrent browsers. |
| Google Cloud — Always Free | 1× e2-micro (2 vCPU burst / 1 GB) | OK at low concurrency (1 GB is tight for Chrome) |
| Fly.io | small free allowance, container-native | Good; needs a card |
| Koyeb / Render free | free web service | ❌ sleeps on idle — bad for an always-on connector |

**Recommended: Oracle Cloud Always Free (Ampere A1).** Pick Ubuntu 22.04, give it
2–4 OCPU / 12–24 GB.

## Deploy (≈15 min)
On the VPS (Ubuntu):
```bash
# 1. Docker
curl -fsSL https://get.docker.com | sh

# 2. get the code + build the MCP image
git clone https://github.com/subhadeeproy3902/lead-gen.git && cd lead-gen
docker build -f deploy/Dockerfile.mcp -t leadgen-mcp .

# 3. run it (set your public domain; tune concurrency to your RAM)
docker run -d --restart unless-stopped --name leadgen-mcp -p 8000:8000 \
  -e LEADGEN_PUBLIC_URL=https://leadgen.auradevs.co \
  -e LEADGEN_MAX_CONCURRENCY=8 \
  leadgen-mcp
```

### TLS + your domain (Caddy = automatic HTTPS)
```bash
sudo apt install -y caddy
# /etc/caddy/Caddyfile:
#   leadgen.auradevs.co {
#       reverse_proxy localhost:8000
#   }
sudo systemctl restart caddy
```
Point DNS: in Cloudflare, add an **A record** `leadgen` → your VPS public IP
(proxied "orange cloud" is fine — that's a proxy, not a localhost tunnel). Open
ports **80** and **443** in the VPS firewall **and** the Oracle security list.

**Done →** your public connector URL is **`https://leadgen.auradevs.co/mcp`**.
Anyone adds it once; every prompt runs their own isolated scrape.

## Per-user isolation & queue
- Each `leadgen_run` spins up **its own browser in its own worker thread** — users
  never wait behind one another (it's not a single global lock).
- `LEADGEN_MAX_CONCURRENCY` caps how many run at once so the box can't OOM
  (≈1 browser per ~1.5 GB RAM → 8–12 on a 24 GB A1). Beyond the cap, extra runs
  queue briefly. For true scale, run **several replicas** and load-balance them
  behind the same domain (Cloudflare LB, or `docker run` N containers + Caddy
  `reverse_proxy` to all of them).

## Notes
- The server holds **no Notion token of yours** — users connect their own; default
  output is CSV returned to them. So one public server is safe to share.
- Keep the image updated: `git pull && docker build … && docker rm -f leadgen-mcp && docker run …`.
- For production auth on who may *connect*, put Cloudflare Access in front of the domain.
